Преглед изворни кода

新增公众号后台关系

刘韬 пре 5 година
родитељ
комит
cd1d211e16

+ 141 - 0
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/controller/WeixinApiController.java

@@ -0,0 +1,141 @@
+package com.zskk.controller;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.List;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.kit.PropKit;
+import com.jfinal.weixin.sdk.api.AccessTokenApi;
+import com.jfinal.weixin.sdk.api.ApiConfigKit;
+import com.jfinal.weixin.sdk.api.ApiResult;
+import com.jfinal.weixin.sdk.api.CallbackIpApi;
+import com.jfinal.weixin.sdk.api.CustomServiceApi;
+import com.jfinal.weixin.sdk.api.MenuApi;
+import com.jfinal.weixin.sdk.api.QrcodeApi;
+import com.jfinal.weixin.sdk.api.ShorturlApi;
+import com.jfinal.weixin.sdk.api.UserApi;
+import com.jfinal.weixin.sdk.jfinal.ApiController;
+import com.zskk.model.Institution;
+import com.zskk.service.ServiceFactory;
+
+public class WeixinApiController extends ApiController {
+
+    /**
+	 * 为WeixinConfig onLineTokenUrl处提供AccessToken
+	 * 
+	 * 此处是为了开发测试和生产环境同时使用一套appId时为开发测试环境提供AccessToken
+	 * 
+	 * 设计初衷:https://www.oschina.net/question/2702126_2237352
+	 */
+	public void getToken() {
+		try {
+			String json = AccessTokenApi.getAccessToken().getAccessToken();
+			renderText(json);
+		} catch (Exception e) {
+			// TODO: handle exception
+			renderText(e.toString());
+		}
+	}
+
+    /**
+     * 获取公众号菜单
+     */
+    public void getMenu() {
+        ApiResult apiResult = MenuApi.getMenu();
+        if (apiResult.isSucceed())
+            renderText(apiResult.getJson());
+        else
+            renderText(apiResult.getErrorMsg());
+    }
+
+    /**
+     * 创建菜单
+     */
+    public void createMenu()
+    {
+        String str = "{\n" +
+                "    \"button\": [\n" +
+                "        {\n" +
+//                "\t    \"name\": \"健易保\",\n" +
+//                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/aboutUs\",\n" +
+"\t    \"name\": \"疫情通道\",\n" +
+"\t    \"url\": \"https://wj.qq.com/s2/5297050/807b/\",\n" +
+//                "\t    \"url\": \"http://leo.spread.newtank.cn/group0930\",\n" +
+                "\t    \"type\": \"view\"\n" +
+                "        }\n" +
+                "    ]\n" +
+                "}";
+        ApiResult apiResult = MenuApi.createMenu(str);
+        if (apiResult.isSucceed())
+            renderText(apiResult.getJson());
+        else
+            renderText(apiResult.getErrorMsg());
+    }
+
+    /**
+     * 获取公众号关注用户
+     */
+    public void getFollowers()
+    {
+        ApiResult apiResult = UserApi.getFollows();
+        JSONObject json = JSON.parseObject(apiResult.getJson());
+        JSONObject json2 = json.getObject("data", JSONObject.class);
+        JSONArray jsonArray = json2.getJSONArray("openid");
+//        List<UserWechat> users = UserWechat.dao.find("SELECT * FROM user_wechat where source='测试微信'");
+//        for (UserWechat user : users) {
+//			if (jsonArray.contains(user.getWxOpenid())) {
+//				user.setSource("辽宁省电子胶片平台");
+////				user.update();
+//			}
+//		}
+        renderText(jsonArray.toJSONString());
+    }
+
+    /**
+     * 获取用户信息
+     */
+    public void getUserInfo()
+    {
+        ApiResult apiResult = UserApi.getUserInfo("ohbweuNYB_heu_buiBWZtwgi4xzU");
+        renderText(apiResult.getJson());
+    }
+   
+    /**
+     * 长链接转成短链接
+     */
+    public void getShorturl()
+    {
+        String str = "{\"action\":\"long2short\"," +
+                "\"long_url\":\"http://wap.koudaitong.com/v2/showcase/goods?alias=128wi9shh&spm=h56083&redirect_count=1\"}";
+        ApiResult apiResult = ShorturlApi.getShorturl(str);
+        renderText(apiResult.getJson());
+    }
+
+    /**
+     * 获取客服聊天记录
+     */
+    public void getRecord()
+    {
+        String str = "{\n" +
+                "    \"endtime\" : 987654321,\n" +
+                "    \"pageindex\" : 1,\n" +
+                "    \"pagesize\" : 10,\n" +
+                "    \"starttime\" : 123456789\n" +
+                " }";
+        ApiResult apiResult = CustomServiceApi.getRecord(str);
+        renderText(apiResult.getJson());
+    }
+
+    /**
+     * 获取微信服务器IP地址
+     */
+    public void getCallbackIp()
+    {
+        ApiResult apiResult = CallbackIpApi.getCallbackIp();
+        renderText(apiResult.getJson());
+    }
+    
+}
+

+ 0 - 1
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/controller/WxaUserApiController.java

@@ -92,7 +92,6 @@ public class WxaUserApiController extends WxaController {
 			sb.replace(3, 7, "****");
 			doctorBean.setPhone(sb.toString());
 			String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
-			String doctorsStr =  JSON.toJSONString(doctors);
 			Redis.use("pc").setex("think" + tokenKey, 7200, doctors.toJson());
 			loginBean.setDoctorBean(doctorBean);
 			loginBean.setToken(tokenKey);