USVT-132 因空对象异常,无法返回正常数据,修改空对象异常问题

This commit is contained in:
YuCheng Hu 2023-01-05 13:47:03 -05:00
parent 050cedfc1d
commit 4844e96155
2 changed files with 20 additions and 13 deletions

View File

@ -49,15 +49,15 @@ public class HomeController {
log.debug("Receive message from WeChat - [{}]", weChatMessage);
String weChatMessageStr = weChatService.getWeChatMessage(weChatMessage);
log.debug("Response message to WeChat - [{}]",weChatMessageStr);
weChatMessageStr = "<xml><ToUserName><![CDATA[\n" +
" o9phd5jz_We8mPs1ovmyjud97Ock\n" +
" ]]></ToUserName><FromUserName><![CDATA[\n" +
" gh_f8d764e538eb\n" +
" ]]></FromUserName><CreateTime>1672943527158</CreateTime><MsgType><![CDATA[\n" +
" text\n" +
" ]]></MsgType><Content><![CDATA[VisaFn Response your message - \n" +
" this is a test - 你好\n" +
" ]]></Content></xml>";
// weChatMessageStr = "<xml><ToUserName><![CDATA[\n" +
// " o9phd5jz_We8mPs1ovmyjud97Ock\n" +
// " ]]></ToUserName><FromUserName><![CDATA[\n" +
// " gh_f8d764e538eb\n" +
// " ]]></FromUserName><CreateTime>1672943527158</CreateTime><MsgType><![CDATA[\n" +
// " text\n" +
// " ]]></MsgType><Content><![CDATA[VisaFn Response your message - \n" +
// " this is a test - 你好\n" +
// " ]]></Content></xml>";
return weChatMessageStr;
}

View File

@ -11,6 +11,7 @@ import com.northtecom.visatrack.api.model.entity.wechat.WeChatUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.dom4j.Document;
@ -107,12 +108,18 @@ public class WeChatUtils {
weChatMessage.setMsgType(document.getRootElement().element("MsgType").getText());
weChatMessage.setContent(document.getRootElement().element("Content").getText());
weChatMessage.setMsgId(document.getRootElement().element("MsgId").getText());
weChatMessage.setMsgDataId(document.getRootElement().element("MsgDataId").getText());
weChatMessage.setIdx(document.getRootElement().element("Idx").getText());
if (ObjectUtils.isNotEmpty(document.getRootElement().element("MsgDataId"))) {
weChatMessage.setMsgDataId(document.getRootElement().element("MsgDataId").getText());
}
if (ObjectUtils.isNotEmpty(document.getRootElement().element("Idx"))) {
weChatMessage.setIdx(document.getRootElement().element("Idx").getText());
}
log.debug("WeChat Message Content - [{}]", weChatMessage.getContent());
} catch (DocumentException e) {
} catch (Exception e) {
log.warn("Cannot Process weChat Message", e);
return null;
}
@ -122,7 +129,7 @@ public class WeChatUtils {
public static String covertToWeChatMessageXmlStr(WeChatMessage weChatMessage) {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "xml" );
Element root = document.addElement("xml");
root.addElement("ToUserName").addCDATA(weChatMessage.getToUserName());
root.addElement("FromUserName").addCDATA(weChatMessage.getFromUserName());