Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

消息加密参数 #84

Closed
fuqiangdong01 opened this issue Nov 29, 2016 · 5 comments
Closed

消息加密参数 #84

fuqiangdong01 opened this issue Nov 29, 2016 · 5 comments

Comments

@fuqiangdong01
Copy link
Member

首先,在处理微信通知消息时,报了这个错误:WARN RootController:186 - 加密消息签名校验失败
发现微信的 signature是用token,timestamp和noncestr三个参数计算的,与其文档里的说明并不一致。而我们的WxCryptUtl.decrypt方法内,是按照文档里实现的。

@binarywang
Copy link
Member

不太明白你的意思,“发现微信的 signature是用token,timestamp和noncestr三个参数计算的,与其文档里的说明并不一致” 这句话怎么理解?

@binarywang
Copy link
Member

我感觉你应该是概念上有所混淆导致这个问题,WxCryptUtil是消息加密用的,而signature是校验消息来源的,不是一个东西

@fuqiangdong01
Copy link
Member Author

fuqiangdong01 commented Nov 29, 2016

`
try {

  WxMpXmlMessage xmlMessage = WxMpXmlMessage.fromEncryptedXml(message, wxMpService.getWxMpConfigStorage(),timestamp, nonce, signature);

  if (WxConsts.XML_MSG_DEVICE_EVENT.equals(xmlMessage.getMsgType())) {

    if (LOG.isDebugEnabled()) {
      LOG.debug("device event");
    }

    String openId = xmlMessage.getFromUser();
    String deviceId = xmlMessage.getDeviceId();
    rentalService.bindDevice(deviceId, openId);

  }
} catch (Exception e) {

  LOG.warn(e.getMessage());

}

我是这样调用的。报错:WARN RootController:186 - 加密消息签名校验失败`
debug时,发现SHA1.gen(new String[]{this.token, timeStamp, nonce,cipherText})计算的结果与signature不一致,若只用前三个参数计算token,timeStamp,nonce计算,则与微信的signature一致。

@binarywang
Copy link
Member

你确实是搞错了,signature那个是验证消息是否是微信服务器发送过来用的。建议你参考下demo中的实现方法,具体看首页中提供的几个demo即可,或者看wiki中的相关内容

@fuqiangdong01
Copy link
Member Author

是的,是我搞错了。这个位置,我应该使用msg_signature。在向微信测试号的请求里,并没有msg_signature这个参数。哭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants