本文整理了Java中me.chanjar.weixin.mp.api.WxMpService.checkSignature()
方法的一些代码示例,展示了WxMpService.checkSignature()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMpService.checkSignature()
方法的具体详情如下:
包路径:me.chanjar.weixin.mp.api.WxMpService
类名称:WxMpService
方法名:checkSignature
[英]```
验证推送过来的消息的正确性
详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
[中]```
验证推送过来的消息的正确性
详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
代码示例来源:origin: liuweijw/fw-cloud-framework
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
this.logger
.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { throw new IllegalArgumentException(
"请求参数非法,请核实!"); }
if (this.wxService.checkSignature(timestamp, nonce, signature)) { return echostr; }
return "非法请求";
}
代码示例来源:origin: com.github.hippoom/wechat-mp-autoconfigure
/**
* Handle authentication request from WeChat.
*
* @param signature given by WeChat MP webhook
* @param echostr given by WeChat MP webhook
* @param timestamp given by WeChat MP webhook
* @param nonce given by WeChat MP webhook
* @param request {@link HttpServletRequest}
* @return echostr if authenticated, "invalid authentication request" if failure
* @see <a href="http://admin.wechat.com/wiki/index.php?title=Message_Authentication">Message
* Authentication</a>
*/
@RequestMapping(method = GET)
protected String handleAuthentication(@RequestParam String signature,
@RequestParam String echostr,
@RequestParam String timestamp,
@RequestParam String nonce, HttpServletRequest request) {
log.debug("receiving {}", request.getParameterMap());
// see http://admin.wechat.com/wiki/index.php?title=Message_Authentication
return wxMpService.checkSignature(timestamp, nonce, signature) ? echostr
: "invalid authentication request";
}
代码示例来源:origin: yjjdick/sdb-mall
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@PathVariable String appid,
@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
final WxMpService wxService = WxMpConfiguration.getMpServices().get(appid);
log.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature,
timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
throw new IllegalArgumentException("请求参数非法,请核实!");
}
if (wxService.checkSignature(timestamp, nonce, signature)) {
return echostr;
}
return "非法请求";
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@PathVariable String appid,
@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
this.logger.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature,
timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
throw new IllegalArgumentException("请求参数非法,请核实!");
}
final WxMpService wxService = WxMpConfiguration.getMpServices().get(appid);
if (wxService == null) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%d]的配置,请核实!", appid));
}
if (wxService.checkSignature(timestamp, nonce, signature)) {
return echostr;
}
return "非法请求";
}
代码示例来源:origin: binarywang/weixin-java-mp-demo-springboot
openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!wxService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
代码示例来源:origin: liuweijw/fw-cloud-framework
@PostMapping(produces = "application/xml; charset=UTF-8")
public String post(@RequestBody String requestBody,
@RequestParam("signature") String signature,
@RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce,
@RequestParam(name = "encrypt_type", required = false) String encType,
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
this.logger.info("\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", signature, encType,
msgSignature, timestamp, nonce, requestBody);
if (!this.wxService.checkSignature(timestamp, nonce, signature)) { throw new IllegalArgumentException(
"非法请求,可能属于伪造的请求!"); }
String out = null;
if (encType == null) {
// 明文传输的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) { return ""; }
out = outMessage.toXml();
} else if ("aes".equals(encType)) {
// aes加密的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, this.wxService
.getWxMpConfigStorage(), timestamp, nonce, msgSignature);
this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) { return ""; }
out = outMessage.toEncryptedXml(this.wxService.getWxMpConfigStorage());
}
this.logger.debug("\n组装回复信息:{}", out);
return out;
}
代码示例来源:origin: yjjdick/sdb-mall
signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!wxService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
代码示例来源:origin: aillamsun/genesis
String nonce = inRequest.getParameter("nonce");
String timestamp = inRequest.getParameter("timestamp");
if (!WxMpServiceFactory.getWxMpService().checkSignature(timestamp, nonce, signature)) {
内容来源于网络,如有侵权,请联系作者删除!