银收客 公众号消息推送问题
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.czg.service.product.util;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -95,23 +94,17 @@ public class WxAccountUtil {
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
synchronized (this) {
|
||||
String accessToken = Convert.toStr(redisService.get("accessToken"));
|
||||
if (StrUtil.isNotEmpty(accessToken)) {
|
||||
return accessToken;
|
||||
}
|
||||
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||
if (!respInfo.containsKey("access_token")) {
|
||||
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
||||
throw new RuntimeException(resp);
|
||||
}
|
||||
accessToken = respInfo.getString("access_token");
|
||||
int expiresIn = respInfo.getInteger("expires_in");
|
||||
redisService.set("accessToken", accessToken, expiresIn - 10);
|
||||
String accessToken = respInfo.getString("access_token");
|
||||
// int expiresIn = respInfo.getInteger("expires_in");
|
||||
// redisService.set("accessToken", accessToken, expiresIn - 10);
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject sendTemplateMsg(String detail, String templateId, String toUserOpenId, Map<String, Object> data) {
|
||||
log.info("银收客公众号消息推送,消息类型:{} 接收用户openId: {}, 消息数据: {}", detail, toUserOpenId, data);
|
||||
@@ -129,4 +122,30 @@ public class WxAccountUtil {
|
||||
}
|
||||
throw new CzgException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||
}
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//// String appId = "wx212769170d2c6b2a";
|
||||
//// String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
|
||||
//// String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||
//// System.out.println(resp);
|
||||
//
|
||||
// String accessToken = "100_ZGAKcjfJBViY-W_4TPDRnZJvnveRsVFAQzUY0SeosUMfVId4LN-TLD1Ajp-7t7aZL4yiBIjbAaTiK-FQ4S1KnbaDDobfYjD2jqMvbgXHFxiActwaDmdJfYpt6QcWNKcAHAQHE";
|
||||
// JSONObject object1 = new JSONObject();
|
||||
// object1.put("template_id", "C08OUr80x6wGmUN1zpFhSZyFA2G6b9_jiZgEppzLB70");
|
||||
// object1.put("touser", "ojC-S6r36TauETXV8G4e6J-U8Qa0");
|
||||
// object1.put("data", Map.of(
|
||||
// //品名
|
||||
// "thing34", Map.of("value", "耗材"),
|
||||
// //商品名称
|
||||
// "thing4", Map.of("value", "名称"),
|
||||
// //商品数量
|
||||
// "number5", Map.of("value", 1),
|
||||
// //商家名称
|
||||
// "thing22", Map.of("value", "412341324")
|
||||
// ));
|
||||
//
|
||||
// String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
|
||||
// log.info("银收客公众号消息推送,响应内容:{}", response);
|
||||
// JSONObject resObj = JSONObject.parseObject(response);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user