/*
* 设置Token
* 该方法是OK的。
*/
@RequestMapping(value = "/signature", method = RequestMethod.GET)
public void signature(
@RequestParam(value = "signature", required = false) String signature,
@RequestParam(value = "timestamp", required = false) String timestamp,
@RequestParam(value = "nonce", required = false) String nonce,
@RequestParam(value = "echostr", required = false) String echostr,
HttpServletResponse response) throws IOException {
String[] values = { CommonConstans.WEIXIN_TOKEN, timestamp, nonce };//CommonConstans.WEIXIN_TOKEN :是设置的Token内容。
Arrays.sort(values); // 字典序排序
String value = values[0] + values[1] + values[2];
log.info("内容:"+value);
String sign = DigestUtils.shaHex(value);
PrintWriter writer = response.getWriter();
if (signature.equals(sign)) {// 验证成功返回ehcostr
writer.print(echostr);
} else {
writer.print("error");
}
writer.flush();
writer.close();
}
JAVA设置WEIXIN公众号TOKEN方法
最新推荐文章于 2024-07-07 03:11:49 发布