wwl %!s(int64=3) %!d(string=hai) anos
pai
achega
6cac34ee65

+ 52 - 13
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -170,7 +170,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
                 log.info("2.1...");
                 String content = jsonObjectData.getStr("Content");
                 if (content.startsWith("你好")){
-                    String message = MessageUtil.initText(fromUserName, toUserName, "你好");
+                    String message = initText(fromUserName, toUserName, "你好");
                     return message;
                 }else if (content.startsWith("傻逼")){
                     Map<String, String> returnMap = new HashMap<>();
@@ -182,7 +182,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
                     String encryptMsg = mapToXml(returnMap);
                     return encryptMsg;
                 }else {
-                    return MessageUtil.initText(fromUserName, toUserName, "文本消息-默认回复信息");
+                    return initText(fromUserName, toUserName, "文本消息-默认回复信息");
                 }
 
             } else if (MessageUtil.MESSAGE_IMAGE.equals(msgType)) { // 图片消息
@@ -214,14 +214,14 @@ public class WxGzhServiceImpl implements IWxGzhService {
                     }else {
                         content = "关注事件";
                     }
-                    return MessageUtil.initText(fromUserName, toUserName, content);
+                    return initText(fromUserName, toUserName, content);
 
                 }  else if (MessageUtil.MESSAGE_UNSUBSCRIBE.equals(event)) { // 取消订阅事件
                     // todo 处理取消订阅事件
 
                 } else if (MessageUtil.MESSAGE_SCAN.equals(event)) { // 已关注扫描二维码事件
                     log.info("3.2...");
-                    return MessageUtil.initText(fromUserName, toUserName, "已关注扫描二维码事件");
+                    return initText(fromUserName, toUserName, "已关注扫描二维码事件");
                     
                 } else if (MessageUtil.MESSAGE_LOCATION.equals(event)) { // 上报地理位置事件
                     // todo 处理上报地理位置事件
@@ -229,7 +229,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
                 } else if (MessageUtil.MESSAGE_CLICK.equals(event)) { // 点击菜单拉取消息时的事件推送事件
                     //判断事件KEY值,与自定义菜单接口中KEY值对应
                     if ("generateTicket".equals(jsonObjectData.get("EventKey"))){ //获取分销二维码
-                        return MessageUtil.initNews(fromUserName,
+                        return initNews(fromUserName,
                                 toUserName,
                                 "图文消息信息",
                                 "title",
@@ -250,6 +250,53 @@ public class WxGzhServiceImpl implements IWxGzhService {
     }
 
 
+    /**
+     * 回复文本消息
+     * @param toUserName
+     * @param fromUserName
+     * @param content
+     * @return
+     */
+    public static String initText(String toUserName, String fromUserName, String content) throws Exception{
+        // 返回消息时ToUserName的值与FromUserName的互换
+        Map<String, String> returnMap = new HashMap<>();
+        returnMap.put("ToUserName", fromUserName);
+        returnMap.put("FromUserName", toUserName);
+        returnMap.put("CreateTime", new Date().getTime()+"");
+        returnMap.put("MsgType", "text");
+        returnMap.put("Content", content);
+        return mapToXml(returnMap);
+    }
+
+
+    /**
+     * 回复图文消息
+     * @param toUserName 接收方帐号(收到的OpenID)
+     * @param fromUserName 开发者微信号
+     * @param articles 图文消息信息,注意,如果图文数超过限制,则将只发限制内的条数
+     * @param title 图文消息标题
+     * @param description 图文消息描述
+     * @param picUrl 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
+     * @param url 点击图文消息跳转链接
+     * @return
+     */
+    public static String initNews(String toUserName, String fromUserName, String articles, String title, String description, String picUrl, String url)  throws Exception{
+        // 返回消息时ToUserName的值与FromUserName的互换
+        Map<String, String> returnMap = new HashMap<>();
+        returnMap.put("ToUserName", fromUserName);
+        returnMap.put("FromUserName", toUserName);
+        returnMap.put("CreateTime", new Date().getTime()+"");
+        returnMap.put("MsgType", "news");
+        returnMap.put("ArticleCount", "1");
+        returnMap.put("Content", articles);
+        returnMap.put("Title", title);
+        returnMap.put("Description", description);
+        returnMap.put("PicUrl", picUrl);
+        returnMap.put("Url", url);
+        return mapToXml(returnMap);
+    }
+
+
     /**
      * 将Map转换为XML格式的字符串
      *
@@ -293,13 +340,5 @@ public class WxGzhServiceImpl implements IWxGzhService {
     }
 
 
-    /**
-     * "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<xml>\n<Content>已关注扫描二维码事件</Content>\n<CreateTime>1635234568773</CreateTime>\n<ToUserName>ovKTX528FTUWEc-0qNDen5_RgGCQ</ToUserName>\n<FromUserName>gh_628da25a95e5</FromUserName>\n<MsgType>text</MsgType>\n</xml>\n"
-     *
-     * "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<xml>\n<Content>你好</Content>\n<CreateTime>1635234558771</CreateTime>\n<ToUserName>gh_628da25a95e5</ToUserName>\n<FromUserName>ovKTX528FTUWEc-0qNDen5_RgGCQ</FromUserName>\n<MsgType>text</MsgType>\n</xml>\n"
-     *
-     *
-     */
-
 
 }