您现在的位置是:首页 > 文章详情

微信开发之token认证

日期:2019-08-29点击:480

服务器配置如下

package com.dongpeng; import java.security.MessageDigest; import java.util.Arrays; import javax.servlet.http.HttpServletResponse; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @SpringBootApplication public class Application { public static final String TOKEN = "lianghao_token"; @RequestMapping("/") @ResponseBody public void index(String signature, String timestamp, String nonce, String echostr,HttpServletResponse response)throws Exception { System.out.println("signature:" + signature); System.out.println("timestamp:" + timestamp); System.out.println("nonce:" + nonce); System.out.println("echostr:" + echostr); System.out.println("TOKEN:" + TOKEN); String[] params = new String[] { TOKEN, timestamp, nonce }; Arrays.sort(params); // 将三个参数字符串拼接成一个字符串进行sha1加密 String clearText = params[0] + params[1] + params[2]; String algorithm = "SHA-1"; String sign = new String(org.apache.commons.codec.binary.Hex .encodeHex(MessageDigest.getInstance(algorithm).digest((clearText).getBytes()), true)); // 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 if (signature.equals(sign)) { response.getWriter().print(echostr); } } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }

配置服务端后,提交下面信息

才能成功提交

原文链接:https://yq.aliyun.com/articles/716471
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章