|
@@ -3,6 +3,7 @@ package com.jpsoft.smart.modules.common.utils;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import com.jpsoft.smart.modules.wechat.entity.AccessToken;
|
|
|
import com.jpsoft.smart.modules.wechat.vo.UserInfo;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONException;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
@@ -237,4 +238,89 @@ public class WeixinUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void replyArticlesMessage(HttpServletResponse response, String fromUserName, String toUserName, String title,String description,String picurl,String url){
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("<xml>");
|
|
|
+ sb.append("<ToUserName><![CDATA[" + toUserName + "]]></ToUserName>");
|
|
|
+ sb.append("<FromUserName><![CDATA["+ fromUserName + "]]></FromUserName>");
|
|
|
+ sb.append("<CreateTime>" + DateTime.now().getTime() + "</CreateTime>");
|
|
|
+ sb.append("<MsgType><![CDATA[news]]></MsgType>");
|
|
|
+ sb.append("<ArticleCount>" + 1 + "</ArticleCount>");
|
|
|
+ sb.append("<Articles>");
|
|
|
+ sb.append("<item>");
|
|
|
+ sb.append("<Title><![CDATA["+title+"]]></Title> ");
|
|
|
+ sb.append("<Description><![CDATA["+description+"]]></Description>");
|
|
|
+ sb.append("<PicUrl><![CDATA["+picurl+"]]></PicUrl>");
|
|
|
+ sb.append("<Url><![CDATA["+url+"]]></Url>");
|
|
|
+ sb.append("</item>");
|
|
|
+ sb.append("</Articles>");
|
|
|
+ sb.append("</xml>");
|
|
|
+
|
|
|
+ try {
|
|
|
+ response.getWriter().print(sb.toString());
|
|
|
+ response.getWriter().close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static String createMenu(String appid,String appSecret){
|
|
|
+ AccessToken token = WeixinUtil.getAccessToken(appid, appSecret);
|
|
|
+
|
|
|
+ System.out.println(token.getToken());
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ JSONArray buttonArray = new JSONArray();
|
|
|
+
|
|
|
+ JSONObject button1 = new JSONObject();
|
|
|
+ button1.put("type", "view");
|
|
|
+ button1.put("name", "疫情监管");
|
|
|
+ button1.put("url", "http://wisdomhousewechat.sudaonline.net/prevention/");
|
|
|
+ buttonArray.add(button1);
|
|
|
+
|
|
|
+ JSONObject button2 = new JSONObject();
|
|
|
+ button2.put("type","view");
|
|
|
+ button2.put("name","智慧物业");
|
|
|
+ button2.put("url","http://wisdomhousewechat.sudaonline.net/#/home/?id=1");
|
|
|
+ buttonArray.add(button2);
|
|
|
+
|
|
|
+ JSONObject button3 = new JSONObject();
|
|
|
+ button3.put("type","click");
|
|
|
+ button3.put("name","关于系统");
|
|
|
+ button3.put("key","文章");
|
|
|
+ buttonArray.add(button3);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ data.put("button", buttonArray);
|
|
|
+ data.put("action_name", "QR_LIMIT_STR_SCENE");
|
|
|
+
|
|
|
+ JSONObject actionInfo = new JSONObject();
|
|
|
+ JSONObject scene = new JSONObject();
|
|
|
+
|
|
|
+ scene.put("scene_str", "6");
|
|
|
+
|
|
|
+ actionInfo.put("scene", scene);
|
|
|
+
|
|
|
+ data.put("action_info", actionInfo);
|
|
|
+ System.out.println(data.toString());
|
|
|
+ //创建菜单
|
|
|
+ String result = HttpConnectionUtil.getHttpContentByPost(" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + token.getToken(), "utf-8", data.toString());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args){
|
|
|
+
|
|
|
+ String result = createMenu("wxb935babc7dd147b8","9cb08ae433a8ad88d77ff921f9175577");
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|