|
@@ -236,8 +236,8 @@ public class WeChatService {
|
|
|
// return access_token;
|
|
|
// }
|
|
|
String link = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
|
|
- link = link.replace("APPID", crmAppId);
|
|
|
- link = link.replace("APPSECRET", crmAppSecret);
|
|
|
+ link = link.replace("APPID", "wx0938e78f38bc203d");
|
|
|
+ link = link.replace("APPSECRET", "a563dd2c07c9c815a4e697c8b6cb73dc");
|
|
|
String result = RequestUtil.sendGet(link);
|
|
|
log.info("微信公众号获取access_token>>>" + result);
|
|
|
Map<String, Object> map = JSONObject.parseObject(result, Map.class);
|
|
@@ -330,4 +330,193 @@ public class WeChatService {
|
|
|
log.error("推送微信模板消息失败:", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下单消息推送
|
|
|
+ * @param accessToken 微信公众号
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param orderno 订单编号
|
|
|
+ * @param money 金额
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
+ */
|
|
|
+ public void sendTemplateMsgs(String accessToken, String openid, String title, String name,String orderno, Double money, String remarkText, String pagePath) {
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", title);
|
|
|
+ first.put("color", "#000000");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", name);
|
|
|
+ keyword1.put("color", "#FF0000");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", orderno);
|
|
|
+ keyword2.put("color", "#c4c400");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", money.toString());
|
|
|
+ keyword3.put("color", "#c4c400");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkText);
|
|
|
+ remark.put("color", "#c4c400");
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first", first);
|
|
|
+ data.put("keyword1", keyword1);
|
|
|
+ data.put("keyword2", keyword2);
|
|
|
+ data.put("keyword3", keyword3);
|
|
|
+ data.put("remark", remark);
|
|
|
+
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", "o6rro6UAe6BRU30flEGvelFShDBw");
|
|
|
+ miniProgram.put("pagepath", pagePath);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "lLPssEY0tx6k5jT-8tDQgEpInf5quA3_M9RsI9aw3IM");
|
|
|
+ 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/template/send?access_token="+accessToken;
|
|
|
+ // 发送请求
|
|
|
+ String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
+ log.info(">>>>>>>>推送结果:" + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送微信模板消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发货消息推送
|
|
|
+ * @param accessToken
|
|
|
+ * @param openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param orderno 订单编号
|
|
|
+ * @param time 发货时间
|
|
|
+ * @param company 快递名称
|
|
|
+ * @param companyno 快递编号
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
+ */
|
|
|
+ public void sendTemplateMsgy(String accessToken, String openid, String title, String orderno,String time, String company, String companyno,String remarkText, String pagePath) {
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", title);
|
|
|
+ first.put("color", "#000000");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", orderno);
|
|
|
+ keyword1.put("color", "#FF0000");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", time);
|
|
|
+ keyword2.put("color", "#c4c400");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", company);
|
|
|
+ keyword3.put("color", "#c4c400");
|
|
|
+ JSONObject keyword4 = new JSONObject();
|
|
|
+ keyword4.put("value", companyno);
|
|
|
+ keyword4.put("color", "#c4c400");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkText);
|
|
|
+ remark.put("color", "#c4c400");
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first", first);
|
|
|
+ data.put("keyword1", keyword1);
|
|
|
+ data.put("keyword2", keyword2);
|
|
|
+ data.put("keyword3", keyword3);
|
|
|
+ data.put("keyword4", keyword4);
|
|
|
+ data.put("remark", remark);
|
|
|
+
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", receiptAppId);
|
|
|
+ miniProgram.put("pagepath", pagePath);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "_Zc6WiUp3hM4yBgT30HkTyA-SmcCN-sjnGpIa6n3rKI");
|
|
|
+ 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/template/send?access_token="+accessToken;
|
|
|
+ // 发送请求
|
|
|
+ String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
+ log.info(">>>>>>>>推送结果:" + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送微信模板消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 购买成功消息推送
|
|
|
+ * @param accessToken
|
|
|
+ * @param openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param paytime 付款时间
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param orderno 商品编号
|
|
|
+ * @param money 订单金额
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
+ */
|
|
|
+ public void sendTemplateMsgz(String accessToken, String openid, String title,String paytime, String name,String orderno, Double money, String remarkText, String pagePath) {
|
|
|
+ JSONObject first = new JSONObject();
|
|
|
+ first.put("value", title);
|
|
|
+ first.put("color", "#000000");
|
|
|
+ JSONObject keyword1 = new JSONObject();
|
|
|
+ keyword1.put("value", name);
|
|
|
+ keyword1.put("color", "#FF0000");
|
|
|
+ JSONObject keyword2 = new JSONObject();
|
|
|
+ keyword2.put("value", orderno);
|
|
|
+ keyword2.put("color", "#c4c400");
|
|
|
+ JSONObject keyword3 = new JSONObject();
|
|
|
+ keyword3.put("value", money);
|
|
|
+ keyword3.put("color", "#c4c400");
|
|
|
+ JSONObject keyword4 = new JSONObject();
|
|
|
+ keyword4.put("value", paytime);
|
|
|
+ keyword4.put("color", "#c4c400");
|
|
|
+ JSONObject remark = new JSONObject();
|
|
|
+ remark.put("value", remarkText);
|
|
|
+ remark.put("color", "#c4c400");
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first", first);
|
|
|
+ data.put("keyword1", keyword1);
|
|
|
+ data.put("keyword2", keyword2);
|
|
|
+ data.put("keyword3", keyword3);
|
|
|
+ data.put("keyword4", keyword4);
|
|
|
+ data.put("remark", remark);
|
|
|
+
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", receiptAppId);
|
|
|
+ miniProgram.put("pagepath", pagePath);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "KV6huLTZInkwTRyPkvaUElD3xs4TgEBK4e0xuDiSAmU");
|
|
|
+ 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/template/send?access_token="+accessToken;
|
|
|
+ // 发送请求
|
|
|
+ String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
+ log.info(">>>>>>>>推送结果:" + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送微信模板消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|