2020-03-19 13:45:56 +00:00
|
|
|
package com.zeekling.solo.wechat.controller;
|
2020-03-16 17:13:34 +00:00
|
|
|
|
2020-03-19 13:45:56 +00:00
|
|
|
import com.zeekling.solo.wechat.conf.WeXinConfigure;
|
|
|
|
import com.zeekling.solo.wechat.entity.Validate;
|
|
|
|
import com.zeekling.solo.wechat.verify.SHA1;
|
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
2020-03-18 14:35:54 +00:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2020-03-17 16:46:51 +00:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
2020-03-16 17:13:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author zeekling [lingzhaohui@zeekling.cn]
|
|
|
|
* @version 1.0
|
|
|
|
* @apiNote
|
|
|
|
* @since 2020-03-17
|
|
|
|
*/
|
2020-03-17 16:46:51 +00:00
|
|
|
@RestController
|
2020-03-16 17:13:34 +00:00
|
|
|
public class WeXinController {
|
|
|
|
|
2020-03-18 14:35:54 +00:00
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
2020-03-16 17:13:34 +00:00
|
|
|
|
2020-03-17 16:46:51 +00:00
|
|
|
@Resource
|
|
|
|
private WeXinConfigure wechatConfig;
|
|
|
|
|
2020-03-19 13:45:56 +00:00
|
|
|
@Resource
|
|
|
|
private WxMpService wxMpService;
|
|
|
|
|
2020-03-17 16:46:51 +00:00
|
|
|
@RequestMapping(value = "/validate")
|
2020-03-19 13:45:56 +00:00
|
|
|
public String validate(Validate validate) {
|
2020-03-17 16:46:51 +00:00
|
|
|
String token = wechatConfig.getToken();
|
2020-03-18 14:35:54 +00:00
|
|
|
String signature = SHA1.getSHA1(token, validate.getTimestamp(), validate.getNonce());
|
|
|
|
// 3.字符串校验
|
|
|
|
if (validate.getSignature().equals(signature)) {
|
|
|
|
logger.info("微信-签名校验通过");
|
|
|
|
logger.info("回复给微信的 echostr 字符串:{}", validate.getEchostr());
|
2020-03-17 16:46:51 +00:00
|
|
|
return validate.getEchostr();
|
2020-03-18 14:35:54 +00:00
|
|
|
} else {
|
|
|
|
logger.error("微信-签名校验失败");
|
2020-03-19 13:45:56 +00:00
|
|
|
return "微信-签名校验失败";
|
2020-03-17 16:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-03-16 17:13:34 +00:00
|
|
|
|
2020-03-18 14:35:54 +00:00
|
|
|
|
2020-03-16 17:13:34 +00:00
|
|
|
}
|