代码如下,可以正常接收微信用户在服务号内发送的信息,也正常返回了,但是服务号内就是没返回的信息。
@PostMapping(value = "/wechat_fwh_callback", produces = "application/xml; charset=utf-8")
public String wechat(@RequestBody String xml) {
Map<String, Object> data = XmlUtils.toMap(xml);
if (data.get("MsgType") != null && data.get("MsgType").equals("text")) {
String resXml = XmlUtils.toTextXml(data.get("FromUserName"), data.get("ToUserName"), "测试:" + data.get("Content"));
System.out.println(xml);
System.out.println(resXml);
return resXml;
}
return "";
}
打印信息:
<xml><ToUserName><![CDATA[gh_f204bd70f3e9]]></ToUserName>
<FromUserName><![CDATA[o3xHj1xPDwmdGqHFlDTI8adCL5Go]]></FromUserName>
<CreateTime>1762174234</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[hello]]></Content>
<MsgId>25228271564300828</MsgId>
</xml>
<xml>
<ToUserName><![CDATA[o3xHj1xPDwmdGqHFlDTI8adCL5Go]]></ToUserName>
<FromUserName><![CDATA[gh_f204bd70f3e9]]></FromUserName>
<CreateTime>1762174235</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[测试:hello]]></Content>
</xml>
