|
@@ -516,4 +516,103 @@ public class WeChatService {
|
|
|
log.error("推送微信模板消息失败:", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 续费会员消息推送
|
|
|
+ * @param accessToken 微信公众号
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
+ */
|
|
|
+ public void sendTempl(String accessToken, String openid, String title, String name,String type,String date,String remarkText, String pagePath) {
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", title);
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", name);
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", date);
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword2.put("value", "会员剩余天数:30天");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkText);
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first", first);
|
|
|
+ data.put("keyword1", keyword1);
|
|
|
+ data.put("keyword2", keyword2);
|
|
|
+ data.put("remark", remark);
|
|
|
+
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", miniAppId);
|
|
|
+ miniProgram.put("pagepath", pagePath);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
+ json.put("touser",openid);
|
|
|
+ json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
|
|
|
+ json.put("url","https://www.caimei365.com/");
|
|
|
+ json.put("miniprogram", miniProgram);
|
|
|
+ json.put("data", data);
|
|
|
+ // json 字符串
|
|
|
+ String jsonString = json.toJSONString();
|
|
|
+ log.info(">>>>>>>>推送微信模板消息:" + jsonString);
|
|
|
+ try {
|
|
|
+ // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
|
|
|
+// String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
|
|
|
+ // 发送请求
|
|
|
+ String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
+ log.info(">>>>>>>>推送结果:" + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送微信模板消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 续费会员消息推送
|
|
|
+ */
|
|
|
+ public void sendTemplss(String accessToken, String openid,String Time, String pagePath) {
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", "恭喜您成功续费采美超级会员");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", "超级会员");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", Time);
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", "如在使用中有任何疑问,请在小程序内联系在线客服");
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first", first);
|
|
|
+ data.put("keyword1", keyword1);
|
|
|
+ data.put("keyword2", keyword2);
|
|
|
+ data.put("remark", remark);
|
|
|
+
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", miniAppId);
|
|
|
+ miniProgram.put("pagepath", pagePath);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
+ json.put("touser",openid);
|
|
|
+ json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
|
|
|
+ json.put("url","https://www.caimei365.com/");
|
|
|
+ json.put("miniprogram", miniProgram);
|
|
|
+ json.put("data", data);
|
|
|
+ // json 字符串
|
|
|
+ String jsonString = json.toJSONString();
|
|
|
+ log.info(">>>>>>>>推送微信模板消息:" + jsonString);
|
|
|
+ try {
|
|
|
+ // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
|
|
|
+// String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
|
|
|
+ // 发送请求
|
|
|
+ String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
+ log.info(">>>>>>>>推送结果:" + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送微信模板消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|