|
@@ -1,5 +1,7 @@
|
|
|
package com.caimei365.user.components;
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
@@ -15,6 +17,8 @@ import org.springframework.stereotype.Component;
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLDecoder;
|
|
|
import java.security.AlgorithmParameters;
|
|
|
import java.security.Security;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -300,15 +304,16 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 购买会员消息推送
|
|
|
+ *
|
|
|
* @param accessToken 微信公众号
|
|
|
- * @param openid 公众号的openid
|
|
|
- * @param title 标题
|
|
|
- * @param name 商品名称
|
|
|
- * @param money 金额
|
|
|
- * @param remarkText 备注
|
|
|
- * @param pagePath 跳转链接
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param money 金额
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
*/
|
|
|
- public void sendTemplateMsgs(String accessToken, String openid, String title, String name, Double money, String date,String remarkText, String pagePath) {
|
|
|
+ public void sendTemplateMsgs(String accessToken, String openid, String title, String name, Double money, String date, String remarkText, String pagePath) {
|
|
|
JSONObject first = new JSONObject();
|
|
|
first.put("value", title);
|
|
|
JSONObject keyword1 = new JSONObject();
|
|
@@ -332,9 +337,9 @@ public class WeChatService {
|
|
|
miniProgram.put("pagepath", pagePath);
|
|
|
|
|
|
JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
- json.put("touser",openid);
|
|
|
- json.put("template_id","Sj5QEHxYrXMOvkY0t7ptj_6LJvBE6H4O-N0TRS3l3tc");
|
|
|
- json.put("url","https://www.caimei365.com/");
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "Sj5QEHxYrXMOvkY0t7ptj_6LJvBE6H4O-N0TRS3l3tc");
|
|
|
+ json.put("url", "https://www.caimei365.com/");
|
|
|
json.put("miniprogram", miniProgram);
|
|
|
json.put("data", data);
|
|
|
// json 字符串
|
|
@@ -343,7 +348,7 @@ public class WeChatService {
|
|
|
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 requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
// 发送请求
|
|
|
String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
log.info(">>>>>>>>推送结果:" + result);
|
|
@@ -354,16 +359,17 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 续费会员消息推送
|
|
|
+ *
|
|
|
* @param accessToken 微信公众号
|
|
|
- * @param openid 公众号的openid
|
|
|
- * @param title 标题
|
|
|
- * @param name 商品名称
|
|
|
- * @param remarkText 备注
|
|
|
- * @param pagePath 跳转链接
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param title 标题
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
*/
|
|
|
- public void sendTemplateMsg(String accessToken, String openid,String date,String remarkText, String pagePath) {
|
|
|
+ public void sendTemplateMsg(String accessToken, String openid, String date, String remarkText, String pagePath) {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- Date dat=new Date();
|
|
|
+ Date dat = new Date();
|
|
|
JSONObject first = new JSONObject();
|
|
|
first.put("value", "恭喜您成功续费采美超级会员");
|
|
|
JSONObject keyword1 = new JSONObject();
|
|
@@ -384,9 +390,9 @@ public class WeChatService {
|
|
|
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("touser", openid);
|
|
|
+ json.put("template_id", "QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
|
|
|
+ json.put("url", "https://www.caimei365.com/");
|
|
|
json.put("miniprogram", miniProgram);
|
|
|
json.put("data", data);
|
|
|
// json 字符串
|
|
@@ -395,7 +401,7 @@ public class WeChatService {
|
|
|
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 requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
// 发送请求
|
|
|
String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
log.info(">>>>>>>>推送结果:" + result);
|
|
@@ -406,12 +412,13 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 续费会员消息推送
|
|
|
+ *
|
|
|
* @param accessToken 微信公众号
|
|
|
- * @param openid 公众号的openid
|
|
|
- * @param remarkText 备注
|
|
|
- * @param pagePath 跳转链接
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
*/
|
|
|
- public void sendTemplateMessg(String accessToken, String openid, String nickName,String time,String remarkText, String pagePath) {
|
|
|
+ public void sendTemplateMessg(String accessToken, String openid, String nickName, String time, String remarkText, String pagePath) {
|
|
|
JSONObject first = new JSONObject();
|
|
|
first.put("value", "绑定成功提醒");
|
|
|
JSONObject keyword1 = new JSONObject();
|
|
@@ -435,9 +442,9 @@ public class WeChatService {
|
|
|
miniProgram.put("pagepath", pagePath);
|
|
|
|
|
|
JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
- json.put("touser",openid);
|
|
|
- json.put("template_id","ph3XjF5o2QPuANQW2XlO7PRYU7Y9t-3fAX5TSqwTftk");
|
|
|
- json.put("url","https://www.caimei365.com/");
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "ph3XjF5o2QPuANQW2XlO7PRYU7Y9t-3fAX5TSqwTftk");
|
|
|
+ json.put("url", "https://www.caimei365.com/");
|
|
|
json.put("miniprogram", miniProgram);
|
|
|
json.put("data", data);
|
|
|
// json 字符串
|
|
@@ -446,7 +453,7 @@ public class WeChatService {
|
|
|
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 requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
// 发送请求
|
|
|
String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
log.info(">>>>>>>>推送结果:" + result);
|
|
@@ -458,16 +465,17 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 上架费消息推送
|
|
|
+ *
|
|
|
* @param accessToken 微信公众号
|
|
|
- * @param openid 公众号的openid
|
|
|
- * @param remarkText 备注
|
|
|
- * @param pagePath 跳转链接
|
|
|
+ * @param openid 公众号的openid
|
|
|
+ * @param remarkText 备注
|
|
|
+ * @param pagePath 跳转链接
|
|
|
*/
|
|
|
- public void sendTemplate(String accessToken, String openid, String date, String newTime,String endTime,Double money,String remarkText, String pagePath) {
|
|
|
+ public void sendTemplate(String accessToken, String openid, String date, String newTime, String endTime, Double money, String remarkText, String pagePath) {
|
|
|
JSONObject first = new JSONObject();
|
|
|
first.put("value", "维护费到期提醒");
|
|
|
JSONObject keyword1 = new JSONObject();
|
|
|
- keyword1.put("value", "尊敬的采美供应商用户,您的账号维护费用"+date+"天后即将到期!");
|
|
|
+ keyword1.put("value", "尊敬的采美供应商用户,您的账号维护费用" + date + "天后即将到期!");
|
|
|
JSONObject keyword2 = new JSONObject();
|
|
|
keyword2.put("value", "维护费");
|
|
|
JSONObject keyword3 = new JSONObject();
|
|
@@ -496,9 +504,9 @@ public class WeChatService {
|
|
|
miniProgram.put("pagepath", pagePath);
|
|
|
|
|
|
JSONObject json = new JSONObject(new LinkedHashMap());
|
|
|
- json.put("touser",openid);
|
|
|
- json.put("template_id","jYUIq63wP6mGFvkgNHgTOXAgF7j6h_VZKgST_-2fqCo");
|
|
|
- json.put("url","https://www.caimei365.com/");
|
|
|
+ json.put("touser", openid);
|
|
|
+ json.put("template_id", "jYUIq63wP6mGFvkgNHgTOXAgF7j6h_VZKgST_-2fqCo");
|
|
|
+ json.put("url", "https://www.caimei365.com/");
|
|
|
json.put("miniprogram", miniProgram);
|
|
|
json.put("data", data);
|
|
|
// json 字符串
|
|
@@ -507,7 +515,7 @@ public class WeChatService {
|
|
|
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 requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
// 发送请求
|
|
|
String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
|
|
|
log.info(">>>>>>>>推送结果:" + result);
|
|
@@ -516,9 +524,49 @@ public class WeChatService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取微信urlscheme
|
|
|
+ *
|
|
|
+ * @param path
|
|
|
+ * @param query
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseJson getOpenLink(String path, String query, String env) {
|
|
|
+ String token = null;
|
|
|
+ try {
|
|
|
+ String link = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
|
|
+ link = link.replace("APPID", miniAppId);
|
|
|
+ link = link.replace("APPSECRET", miniAppSecret);
|
|
|
+ String result = RequestUtil.sendGet(link);
|
|
|
+ log.info("微信公众号获取access_token>>>" + result);
|
|
|
+ Map<String, Object> map = JSONObject.parseObject(result, Map.class);
|
|
|
+ token = (String) map.get("access_token");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" + token;
|
|
|
+ JSONObject jumpWxa = new JSONObject();
|
|
|
+ jumpWxa.put("path", path);
|
|
|
+ jumpWxa.put("query", query);
|
|
|
+ //正式版为"release",体验版为"trial",开发版为"develop"
|
|
|
+ jumpWxa.put("env_version", env);
|
|
|
+
|
|
|
+ JSONObject reqMap = new JSONObject();
|
|
|
+ reqMap.put("jump_wxa", jumpWxa);
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ HttpRequest request = HttpUtil.createPost(url);
|
|
|
+ request.contentType("application/json");
|
|
|
+ request.body(reqMap.toJSONString());
|
|
|
+ result = request.execute().body();
|
|
|
+ result = URLDecoder.decode(result, "UTF-8");
|
|
|
+ log.info("微信获取getOpenLink回调报文" + result);
|
|
|
+ result = JSONObject.parseObject(result).getString("openlink");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ResponseJson.success(result);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|