|
@@ -2,6 +2,7 @@ package com.caimei365.order.components;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.annotation.JSONType;
|
|
|
import com.caimei365.order.model.ResponseJson;
|
|
|
import com.caimei365.order.utils.JwtUtil;
|
|
|
import com.caimei365.order.utils.RequestUtil;
|
|
@@ -20,6 +21,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.security.AlgorithmParameters;
|
|
|
import java.security.Security;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -54,6 +56,9 @@ public class WeChatService {
|
|
|
private String heHeAppId;
|
|
|
@Value("${wx.hehe-app-secret}")
|
|
|
private String heHeAppSecret;
|
|
|
+
|
|
|
+ public static String unionid;
|
|
|
+
|
|
|
/**
|
|
|
* 收款通知模板Id
|
|
|
*/
|
|
@@ -193,6 +198,7 @@ public class WeChatService {
|
|
|
// 静默授权
|
|
|
link = link.replace("snsapi_userinfo", "snsapi_base");
|
|
|
}
|
|
|
+ log.info("》》》》授权消息"+link);
|
|
|
return link;
|
|
|
}
|
|
|
|
|
@@ -219,7 +225,7 @@ public class WeChatService {
|
|
|
link = link.replace("CODE", code);
|
|
|
// 发送授权链接,得到微信用户信息
|
|
|
String result = RequestUtil.sendGet(link);
|
|
|
- log.info(result);
|
|
|
+ log.info("用户信息获取成功"+result);
|
|
|
Map<String, Object> map = JSONObject.parseObject(result, Map.class);
|
|
|
return map;
|
|
|
}
|
|
@@ -236,8 +242,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", "wx0938e78f38bc203d");
|
|
|
- link = link.replace("APPSECRET", "a563dd2c07c9c815a4e697c8b6cb73dc");
|
|
|
+ link = link.replace("APPID", crmAppId);
|
|
|
+ link = link.replace("APPSECRET", crmAppSecret);
|
|
|
String result = RequestUtil.sendGet(link);
|
|
|
log.info("微信公众号获取access_token>>>" + result);
|
|
|
Map<String, Object> map = JSONObject.parseObject(result, Map.class);
|
|
@@ -258,6 +264,7 @@ public class WeChatService {
|
|
|
log.info("微信公众号授权用户数据>>>>>>>>>>>" + userInfo);
|
|
|
Map<String, Object> map = JSONObject.parseObject(userInfo, Map.class);
|
|
|
return map;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -266,10 +273,12 @@ public class WeChatService {
|
|
|
public Map<String, Object> getUserInfoByWeb(String access_token, String openId) throws Exception {
|
|
|
String requestUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openId;
|
|
|
String userInfo = RequestUtil.sendGet(requestUrl);
|
|
|
+ log.info("获取用户信息"+userInfo);
|
|
|
Map<String, Object> map = JSONObject.parseObject(userInfo, Map.class);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 推送收款微信模板消息(公众号)
|
|
|
*
|
|
@@ -313,8 +322,8 @@ public class WeChatService {
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("touser", openid);
|
|
|
- json.put("template_id", messageTemplateReceipt);
|
|
|
- json.put("url", "https://www.caimei365.com/");
|
|
|
+ json.put("template_id",messageTemplateReceipt);
|
|
|
+ json.put("url","https://www.caimei365.com/");
|
|
|
json.put("miniprogram", miniProgram);
|
|
|
json.put("data", data);
|
|
|
// json 字符串
|
|
@@ -345,19 +354,14 @@ public class WeChatService {
|
|
|
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);
|
|
@@ -366,14 +370,14 @@ public class WeChatService {
|
|
|
data.put("keyword3", keyword3);
|
|
|
data.put("remark", remark);
|
|
|
|
|
|
- JSONObject miniProgram = new JSONObject();
|
|
|
- miniProgram.put("appid", "o6rro6UAe6BRU30flEGvelFShDBw");
|
|
|
- miniProgram.put("pagepath", pagePath);
|
|
|
+ JSONObject miniProgram = new JSONObject();
|
|
|
+ miniProgram.put("appid", miniAppId);
|
|
|
+ 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/");
|
|
|
+ JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
+ 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 字符串
|
|
@@ -381,6 +385,7 @@ public class WeChatService {
|
|
|
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);
|
|
@@ -445,7 +450,8 @@ public class WeChatService {
|
|
|
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 requestUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/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);
|
|
@@ -469,22 +475,16 @@ public class WeChatService {
|
|
|
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);
|
|
@@ -495,7 +495,7 @@ public class WeChatService {
|
|
|
data.put("remark", remark);
|
|
|
|
|
|
JSONObject miniProgram = new JSONObject();
|
|
|
- miniProgram.put("appid", receiptAppId);
|
|
|
+ miniProgram.put("appid", miniAppId);
|
|
|
miniProgram.put("pagepath", pagePath);
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
@@ -507,6 +507,7 @@ public class WeChatService {
|
|
|
// json 字符串
|
|
|
String jsonString = json.toJSONString();
|
|
|
log.info(">>>>>>>>推送微信模板消息:" + jsonString);
|
|
|
+ log.info(">>>>>>>>推送微信模板json消息:" + json);
|
|
|
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;
|
|
@@ -517,6 +518,4 @@ public class WeChatService {
|
|
|
log.error("推送微信模板消息失败:", e);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|