https://developers.weixin.qq.com/miniprogram/introduction/custom.html
以下那个协议不生效,三个问题
1.需要加密吗?
2.是不是只能发XML格式?json行不行?
3.java代码具体该怎么做?
将消息转发到客服
如果小程序处于开发模式,普通微信用户向小程序客服发消息时,微信服务器会先将消息POST到开发者填写的url上,如果希望将消息转发到客服系统,则需要开发者在响应包中返回MsgType为transfer_customer_service的消息,微信服务器收到响应后会把当次发送的消息转发至客服系统。
用户被客服接入以后,客服关闭会话以前,处于会话过程中时,用户发送的消息均会被直接转发至客服系统。当会话超过30分钟客服没有关闭时,微信服务器会自动停止转发至客服,而将消息恢复发送至开发者填写的url上。
用户在等待队列中时,用户发送的消息仍然会被推送至开发者填写的url上。
这里特别要注意,只针对微信用户发来的消息才进行转发,而对于其他任何事件都不应该转接,否则客服在客服系统上就会看到一些无意义的消息了。
调用说明
<xml>
<ToUserName><![CDATA[touser]]></ToUserName>
<FromUserName><![CDATA[fromuser]]></FromUserName>
<CreateTime>1399197672</CreateTime>
<MsgType><![CDATA[transfer_customer_service]]></MsgType>
</xml>

开启消息推送配置的时候不是可以选是xml还是json吗,按你选的格式响应,默认xml
下面是我的java代码,能收到消息,但是返回后没有预期的转到客服服务器的效果,你能发现什么问题吗?
@PostMapping(value = "receive", produces = "application/json;charset=UTF-8")@ApiOperation(value = "消息接收")public String wxReceive(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) {Map<String, String[]> requestParams = request.getParameterMap();LOG.info("微信消息接收requestParams:" + new Gson().toJson(requestParams));String decryptJsonData = null;WechatMsgReceiveBaseDTO baseDTO = null;try {LOG.info("jsonData:{}", jsonData);WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAESKey, appId);decryptJsonData = wxBizMsgCrypt.decryptMsg(requestParams.get("msg_signature")[0], requestParams.get("timestamp")[0], requestParams.get("nonce")[0], jsonData);LOG.info("微信消息接收:{}", decryptJsonData);baseDTO = new Gson().fromJson(decryptJsonData, WechatMsgReceiveBaseDTO.class);String msgType = baseDTO.getEvent() == null ? baseDTO.getMsgType() : baseDTO.getEvent();// 如果是text消息,先检查是否需要转人工if ("text".equals(msgType)) {if (textService.checkNeedTransferManual(decryptJsonData)) {// 需要转人工,返回转人工消息LOG.info("转发消息到客服:fromUser={}", baseDTO.getFromUserName());LOG.info("toUser={}", baseDTO.getToUserName());LOG.info("需要转人工,返回JSON转发格式");// 构建JSON格式的转发响应Map<String, Object> jsonResp = new HashMap<>();jsonResp.put("ToUserName", baseDTO.getFromUserName()); // 用户OpenIDjsonResp.put("FromUserName", baseDTO.getToUserName()); // 小程序IDjsonResp.put("CreateTime", System.currentTimeMillis() / 1000);jsonResp.put("MsgType", "transfer_customer_service");LOG.info("返回JSON转发响应:{}", jsonResp);return new Gson().toJson(jsonResp); // 返回JSON格式}}这是我按照官方文档和你们的回复写的代码,但还是没有生效,请问问题出在哪?
@PostMapping(value = "receive", produces = "application/json;charset=UTF-8") @ApiOperation(value = "消息接收") public String wxReceive(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) { Map<String, String[]> requestParams = request.getParameterMap(); LOG.info("微信消息接收requestParams:" + new Gson().toJson(requestParams)); String decryptJsonData = null; WechatMsgReceiveBaseDTO baseDTO = null; try { LOG.info("jsonData:{}", jsonData); WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAESKey, appId); decryptJsonData = wxBizMsgCrypt.decryptMsg(requestParams.get("msg_signature")[0], requestParams.get("timestamp")[0], requestParams.get("nonce")[0], jsonData); LOG.info("微信消息接收:{}", decryptJsonData); baseDTO = new Gson().fromJson(decryptJsonData, WechatMsgReceiveBaseDTO.class); String msgType = baseDTO.getEvent() == null ? baseDTO.getMsgType() : baseDTO.getEvent(); // 如果是text消息,先检查是否需要转人工 if ("text".equals(msgType)) { if (textService.checkNeedTransferManual(decryptJsonData)) { // 需要转人工,返回转人工消息 LOG.info("转发消息到客服:fromUser={}", baseDTO.getFromUserName()); LOG.info("toUser={}", baseDTO.getToUserName()); LOG.info("需要转人工,返回JSON转发格式"); // 构建JSON格式的转发响应 Map<String, Object> jsonResp = new HashMap<>(); jsonResp.put("ToUserName", baseDTO.getFromUserName()); // 用户OpenID jsonResp.put("FromUserName", baseDTO.getToUserName()); // 小程序ID jsonResp.put("CreateTime", System.currentTimeMillis() / 1000); jsonResp.put("MsgType", "transfer_customer_service"); LOG.info("返回JSON转发响应:{}", jsonResp); return new Gson().toJson(jsonResp); // 返回JSON格式 } }