NutzCN Logo
问答 微信公众号收不到回复,显示请稍后重试
发布于 13天前 作者 wx_dc1uhcoqb670vfspa24d 91 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

使用nutzwk 改造为 springboot集成方式,调试的没有报错,但是公众号收不到消息回复。

2020-09-11 21:08:37 [http-nio-8080-exec-3] INFO com.jd.hhf.healthy.wx.aes.WxBizMsgCrypt [encryptMsg]-[248] - 发送给平台的签名是: --> 4538bef8947e08c413a211bda18119009f824b96
2020-09-11 21:08:56 [http-nio-8080-exec-6] INFO com.jd.hhf.healthy.wx.aes.WxBizMsgCrypt [decryptMsg]-[281] - 第三方收到URL中的签名: --> 16018c77ba67c5bd357db3bf7740d18cf94e0c27
2020-09-11 21:08:56 [http-nio-8080-exec-6] INFO com.jd.hhf.healthy.wx.aes.WxBizMsgCrypt [decryptMsg]-[282] - 第三方校验签名: --> 16018c77ba67c5bd357db3bf7740d18cf94e0c27
2020-09-11 21:08:56 [http-nio-8080-exec-6] INFO com.jd.hhf.healthy.wx.aes.WxBizMsgCrypt [encrypt]-[153] - aesKey --> [-27, 31, 48, 25, 36, -51, 74, -121, 109, 2, -60, 100, 70, 24, 56, -43, 30, 81, -74, -67, -24, -78, 83, -96, 72, 82, -72, -41, 24, 57, -17, -93]
2020-09-11 21:08:56 [http-nio-8080-exec-6] INFO com.jd.hhf.healthy.wx.aes.WxBizMsgCrypt [encryptMsg]-[248] - 发送给平台的签名是: --> 36764c4fc87dc3bb6ad0f13357b8e8c7d9e5f146

以下是采用微信工具发送

Connection: keep-alive
Date: Fri, 11 Sep 2020 13:08:56 GMT
Server: openresty/1.11.2.1
Content-Length: 497

解密前xml:

    <xml>
        <Encrypt>
            <![CDATA[90NJTXdz743O/r2+ZxfpLziNEyt8Nu68ufE2Q3tYgzZd/cQ3LSigIEufr3l1EamzLHil/n+XvBg3+k/3LnM9DmEsvhv5f+X+g/2+oc/xL9+e+Bi5kKNJBsX5CQGkrqZV5ciJ4Dw1Tk7a5nacF5SyBy/987vaNTkRRtoBHEahj4BMl9Fj5m7Rge8x/7fcmv6oaSJo7He+DutotCq67UCpBLFdKJqpWF4PFw3+GiyHQ98xB2y4V6C5JeeSyro8LMb/iEGuCmjCCrs7pU2Ul2ZuqOqrWCAC5Z/srAEaDaRHaD0=]]>
        </Encrypt>
        <MsgSignature>
            <![CDATA[36764c4fc87dc3bb6ad0f13357b8e8c7d9e5f146]]>
        </MsgSignature>
        <TimeStamp>1599829736</TimeStamp>
        <Nonce>
            <![CDATA[201830152]]>
        </Nonce>
    </xml>

解密后xml:

    <xml> <ToUserName></ToUserName> <FromUserName></FromUserName> <CreateTime>0</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[吃了!]]></Content> </xml>
5 回复
@RestController
@RequestMapping("/wx")
public class WxOperationTestController {

    @RequestMapping("/check/signature")
    public void msgIn(HttpServletRequest req,HttpServletResponse resp) throws IOException {
        WxHandler wxHandler = new DefaultWxHandler();

        WxApi wxApi = new WxApiImpl();
        wxApi.handle(req,resp,wxHandler);
    }
public class DefaultWxHandler extends BasicWxHandler {

    @Override
    public WxOutMsg text(WxInMsg msg) {
        String content = msg.getContent();
        if (content.contains("你好")) {
            return Wxs.respText("你好,你真帅!");
        }
        String answerStr = content.replace("吗","")
                .replace("?","!");
        return Wxs.respText(answerStr);
    }
}
@Override
    public void handle(HttpServletRequest req, HttpServletResponse resp, WxHandler handler) {
        try {
            WxInMsg in = parse(req);
            WxOutMsg out = handler.handle(in);
            StringWriter sw = new StringWriter();
            Wxs.asXml(sw, out);
            String re = sw.getBuffer().toString();
            if (msgCrypt != null) {
                re = msgCrypt.encryptMsg(re, req.getParameter("timestamp"), req.getParameter("nonce"));
            }
            resp.getWriter().write(re);
        } catch (AesException | IOException e) {
            throw new WxException(e);
        }
    }

您好,大佬,别的还需要提供吗?

WxApi wxApi = new WxApiImpl();

一般是单例

别的, 我建议还是仔细debug一下, 解密的部分.

或者, 干脆不要加密,直接明文试试

添加回复
请先登陆
回到顶部