Parcourir la source

微信公众号服务配置-异常处理

chao il y a 3 ans
Parent
commit
2f478c8d40

+ 1 - 0
src/main/java/com/caimei365/wechat/controller/WechatServerApi.java

@@ -100,6 +100,7 @@ public class WechatServerApi {
             if (!StringUtils.hasLength(respXml)) { respXml = "success"; }
         } catch (Exception e) {
             log.info(">>>>>>>>>>微信公众号消息处理时出现异常:" + e);
+            respXml = "success";
         }
         log.info(">>>>>>>>>>微信回复用户消息:" + respXml);
         long endProcessTime = System.currentTimeMillis();

+ 14 - 12
src/main/java/com/caimei365/wechat/service/impl/WechatServerServiceImpl.java

@@ -276,18 +276,20 @@ public class WechatServerServiceImpl implements WechatServerService {
      * 根据数据库回复配置设置
      */
     private String setXmlByDatabaseReply(String openid, String wxType, WechatReply reply) {
-        if ("news".equals(reply.getResponseType())) {
-            // 回复图文
-            List<WechatArticleDetail> articleList = weChatDao.getArticleDetailList(reply.getRelateId());
-            log.info(">>>>>>>>>>匹配到图文内容数量:" + articleList.size());
-            if (!CollectionUtils.isEmpty(articleList)) {
-                return MessageUtil.setArticleXml(openid, wxType, articleList);
-            }
-        } else {
-            // 回复文本
-            String textContent = weChatDao.getTextContent(reply.getRelateId());
-            if (StringUtils.hasLength(textContent)) {
-                return MessageUtil.setTextXml(openid, wxType, textContent);
+        if (null != reply) {
+            if ("news".equals(reply.getResponseType())) {
+                // 回复图文
+                List<WechatArticleDetail> articleList = weChatDao.getArticleDetailList(reply.getRelateId());
+                log.info(">>>>>>>>>>匹配到图文内容数量:" + articleList.size());
+                if (!CollectionUtils.isEmpty(articleList)) {
+                    return MessageUtil.setArticleXml(openid, wxType, articleList);
+                }
+            } else {
+                // 回复文本
+                String textContent = weChatDao.getTextContent(reply.getRelateId());
+                if (StringUtils.hasLength(textContent)) {
+                    return MessageUtil.setTextXml(openid, wxType, textContent);
+                }
             }
         }
         return null;