Merge branch 'USVT-132' into 'master'

USVT-132 消息对象处理的空对象异常问题

See merge request usvisatrack/usvisatrack.api.service!20
This commit is contained in:
YuCheng Hu 2023-01-05 18:48:53 +00:00
commit f09703151d
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());
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;
}