binarywang/WxJava

该公众号提供服务出现故障,请稍后重试

Closed this issue · 6 comments

提问前,请确保阅读过项目首页说明以及wiki开发文档相关内容,尤其是常见问题部分。完成内容后,请务必移除包括本句在内的无用内容,以免影响阅读,否则直接关闭,谢谢合作~

另外如果确认属于bug,而且已明确如何修复,请参考贡献指南直接提交PR,省的浪费时间在这里描述问题,非常感谢配合

简要描述

对接公众号品台能力,自动回复总是出现 提供服务故障

模块版本情况

  • WxJava 模块名: weixin-java-mp
  • WxJava 版本号:4.6.0

详细描述

回调代码
public ResponseEntity post(final String appid, final HttpServletRequest request, final String requestBody) {
String encType = request.getParameter("encrypt_type");
String nonce = request.getParameter("nonce");
String timestamp = request.getParameter("timestamp");
String msgSignature = request.getParameter("msg_signature");
String signature = request.getParameter("signature");
String openid = request.getParameter("openid");
log.info("接收微信请求:[openid=[{}], [openid=[{}],[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[{}] ",
appid, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);

if (!this.wxMpService.switchover(appid)) {
  throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}

if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
  throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}

// 这里异步发送客服消息
return ResponseEntity.ok("");
}

配置信息

public WxMpMessageRouter messageRouter(final WxMpService wxMpService) {
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);

// 记录所有事件的日志 (异步执行)
newRouter.rule().handler(logHandler).next();

// 自定义菜单事件
newRouter.rule().msgType(EVENT).event(WxConsts.EventType.CLICK).handler(menuHandler).end();

// 关注事件,扫码事件::没有关注
newRouter.rule().msgType(EVENT).event(SUBSCRIBE).handler(subscribeHandler).end();

// 关键词回复,无关键词回复
newRouter.rule().msgType(WxConsts.MassMsgType.TEXT).handler(msgTextHandler).end();

// 扫码事件::已经关注
newRouter.rule().msgType(EVENT).event(WxConsts.EventType.SCAN).handler(scanHandler).end();
return newRouter;

}

能否贴一下本地的日志呢?

回调处理地址就直接返回
public ResponseEntity post(final String appid, final HttpServletRequest request, final String requestBody) {
return ResponseEntity.ok("");
}

// 事件处理, 直接就WxMpXmlOutMessage返回null,我是异步发送的客服消息
public class MenuHandler extends AbstractHandler {
@OverRide
public WxMpXmlOutMessage handle(final WxMpXmlMessage wxMessage,
final Map<String, Object> context,
final WxMpService wxMpService,
final WxSessionManager sessionManager) {
String appId = getAppId(context);
String eventKey = wxMessage.getEventKey();
log.info("MenuHandler菜单事件, appId: {}, eventKey: {}", appId, eventKey);
if (StringUtils.isNotEmpty(wxMessage.getEventKey())) {
// 发送客服消息
wxMpService.getKefuService().sendKefuMessage()
}
return null;
}
}

https://github.com/Wechat-Group/WxJava/wiki/MP_%E5%BE%AE%E4%BF%A1%E6%B6%88%E6%81%AF%E8%B7%AF%E7%94%B1%E5%99%A8

按照此文档,需要返回return ResponseEntity.ok("");,麻烦尝试修改后进行测试

其次建议异步调用客服消息,否则可能因为调用客服消息响应时间过长导致公众号无法及时收到相应

WxMpMessageHandler 我返回的都是 null,都是异步处理
只是WxMpMessageInterceptor这个没有实现, (这个有影响吗)
WxMpMessageHandler不同事件类型也发送消息了,就是接收到消息后,还有一个
该公众号提供服务出现故障,请稍后重试 信息

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.