Parcourir la source

增加模版消息推送

刘韬 il y a 5 ans
Parent
commit
1a674fcbe8

+ 6 - 26
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinApiController.java

@@ -118,32 +118,12 @@ public class WeixinApiController extends ApiController {
      */
     public void sendMsg()
     {
-        String str = " {\n" +
-                "           \"touser\":\"ohbweuNYB_heu_buiBWZtwgi4xzU\",\n" +
-                "           \"template_id\":\"9SIa8ph1403NEM3qk3z9-go-p4kBMeh-HGepQZVdA7w\",\n" +
-                "           \"url\":\"http://www.sina.com\",\n" +
-                "           \"topcolor\":\"#FF0000\",\n" +
-                "           \"data\":{\n" +
-                "                   \"first\": {\n" +
-                "                       \"value\":\"恭喜你购买成功!\",\n" +
-                "                       \"color\":\"#173177\"\n" +
-                "                   },\n" +
-                "                   \"keyword1\":{\n" +
-                "                       \"value\":\"去哪儿网发的酒店红包(1个)\",\n" +
-                "                       \"color\":\"#173177\"\n" +
-                "                   },\n" +
-                "                   \"keyword2\":{\n" +
-                "                       \"value\":\"1元\",\n" +
-                "                       \"color\":\"#173177\"\n" +
-                "                   },\n" +
-                "                   \"remark\":{\n" +
-                "                       \"value\":\"欢迎再次购买!\",\n" +
-                "                       \"color\":\"#173177\"\n" +
-                "                   }\n" +
-                "           }\n" +
-                "       }";
-        ApiResult apiResult = TemplateMsgApi.send(str);
-        renderText(apiResult.getJson());
+        Integer pushType = getParaToInt("pushType");
+        String openid = getPara("openid");
+		WeixinService wService = ServiceFactory.getService(WeixinService.class);
+		String urlString = "http://wechat.client.pacsonline.cn/#/pay?openid="+openid;
+		wService.sendTemplateMsg(openid, urlString, null, "a", pushType);
+
     }
     
     /**

+ 59 - 32
PacsOnline_Wechat_Patient/src/main/java/com/zskk/service/WeixinService.java

@@ -4,6 +4,8 @@ import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -16,6 +18,8 @@ import com.jfinal.weixin.sdk.api.JsTicketApi;
 import com.jfinal.weixin.sdk.api.SnsAccessToken;
 import com.jfinal.weixin.sdk.api.SnsAccessTokenApi;
 import com.jfinal.weixin.sdk.api.SnsApi;
+import com.jfinal.weixin.sdk.api.TemplateData;
+import com.jfinal.weixin.sdk.api.TemplateMsgApi;
 import com.jfinal.weixin.sdk.api.JsTicketApi.JsApiType;
 import com.zskk.model.User;
 import com.zskk.service.bean.WxJSConfigBean;
@@ -123,38 +127,61 @@ public class WeixinService {
 	/*
 	 * 发送模板消息
 	 */
-	public void sendTemplateMsg(String openid, String url, String event, String userName) {
-//		if (PropKit.getBoolean("devMode") == true) {
-//			ApiConfigKit.setThreadLocalApiConfig(getApiConfig());
-//			SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
-//			String time = sdf.format(new Date());
-//			String json = TemplateData.New().setTouser(openid)
-//					.setTemplate_id("eNs4B9rKo_0N-sF1NRmW6PESmTLm8zi_5Vl6ujeFngA").setTopcolor("#743A3A")
-//					.setUrl(url)
-//					.add("keyword1", time  , "#743A3A")
-//					.add("keyword2", event , "#743A3A")
-//					.add("keyword3", "用药了吗?用药后感觉怎么样?快来说说吧,我们不会将您的资料泄露,完成赢积分!", "#743A3A")
-//					.build();
-//			System.out.println(json);
-//			ApiResult result = TemplateMsgApi.send(json);
-//			System.out.println(result.getJson());
-//		}else{
-//			ApiConfigKit.setThreadLocalApiConfig(getApiConfig());
-//			SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
-//			String time = sdf.format(new Date());
-//			String json = TemplateData.New().setTouser(openid)
-//					.setTemplate_id("U4cjem6T4heIpO6gS92XE2au9ZTr0mJcgutgEoDIpRI").setTopcolor("#743A3A")
-//					.setUrl(url)
-//					.add("first"   , event      , "#0DB0EB")
-//					.add("keyword1", userName         , "")
-//					.add("keyword2", ""         , "")
-//					.add("keyword3", time       , "")
-//					.add("remark"  , "请按时记录哦", "#BBBBBB")
-//					.build();
-//			System.out.println(json);
-//			ApiResult result = TemplateMsgApi.send(json);
-//			System.out.println(result.getJson());
-//		}
+	public void sendTemplateMsg(String openid, String url, String event, String userName,Integer pushtype) {
+		PUSH_TYPE dType2 = null;
+		for (PUSH_TYPE xxxEnum : PUSH_TYPE.values()) {
+			if (xxxEnum.getPushType() == pushtype) {
+				dType2 = xxxEnum;
+			}
+		}
+		switch (dType2) {
+		case REMOTE_DIAGNOSIS_PATIENT_PAY:
+			sendRemoteDiagnosisPatientPayMsg(openid,url,userName);
+			break;
+
+		default:
+			break;
+		}
+	}
+	
+	public void sendRemoteDiagnosisPatientPayMsg(String openid, String url, String userName) {
+		String str = " {\n" +
+                "           \"touser\":\""+openid+"\",\n" +
+                "           \"template_id\":\"VZ0Y3yj6N6187EggHdtdUZYcdQ-UycrjKCZKjqLn60Y\",\n" +
+                "           \"url\":\"http://www.sina.com\",\n" +
+                "           \"topcolor\":\"#FF0000\",\n" +
+                "           \"data\":{\n" +
+                "                   \"first\": {\n" +
+                "                       \"value\":\"您好,你的费用信息情况如下:\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"keyword1\":{\n" +
+                "                       \"value\":\"订单num\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"keyword2\":{\n" +
+                "                       \"value\":\"张三\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"keyword3\":{\n" +
+                "                       \"value\":\"日期\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"keyword4\":{\n" +
+                "                       \"value\":\"1元\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"keyword5\":{\n" +
+                "                       \"value\":\"付费\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   },\n" +
+                "                   \"remark\":{\n" +
+                "                       \"value\":\"祝您早日康复。\",\n" +
+                "                       \"color\":\"#173177\"\n" +
+                "                   }\n" +
+                "           }\n" +
+                "       }";
+        ApiResult apiResult = TemplateMsgApi.send(str);
 	}
 	public static String getParamByUrl(String url, String name) {
 	    url += "&";