提交 2d4d1e4c authored 作者: 吕本才's avatar 吕本才

feat(wechat): 新增微信小程序和公众号用户缓存常量及优化工具类

上级 a322cc4c
......@@ -61,4 +61,6 @@ public class CacheConstants
*/
public static final String FRONT_VERSION_KEY = "frontVersion:info";
public static final String HUB_USER_MINI_PROGRAM = "fortune_hub:user:mini_program:" ;
public static final String HUB_USER_OFFICE_ACCOUNT = "fortune_hub:user:office_account:";
}
......@@ -19,10 +19,10 @@ import org.apache.http.util.EntityUtils;
@Slf4j
public class WeChatPlatFormUtils {
// 微信模板消息接口地址
private static final String TEMPLATE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send";
private static final String TEMPLATE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send";
private static final String MINI_PROGRAM_CODE2SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session";
private static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/";
private static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";
public static Object isSubscribe(String openId, String templateId, String accessToken) {
String url = TEMPLATE_SEND_URL + "?access_token=" + accessToken;
......@@ -40,8 +40,9 @@ public class WeChatPlatFormUtils {
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
JSONObject jsonObject = JSON.parseObject(result);
log.info("result: {}", jsonObject.toString());
Integer errCode = jsonObject.getInteger("errcode");
log.info("errCode: {}", errCode);
// 根据错误码判断
if (errCode != null) {
return errCode != 43004;
......@@ -49,6 +50,7 @@ public class WeChatPlatFormUtils {
}
} catch (Exception e) {
e.printStackTrace();
log.error("获取"+templateId+"是否订阅"+openId+"失败"+e.getMessage(), e);
}
return false;
}
......@@ -59,10 +61,14 @@ public class WeChatPlatFormUtils {
* @param appSecret
* @return
*/
public static JSONObject getMiniappToken(String appId, String appSecret) {
public static JSONObject getMiniappAccessToken(String appId, String appSecret) {
// 需要缓存
String cacheKey = "wx_access_token:" + appId;
String url = ACCESS_TOKEN_URL +"?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
String body = HttpUtil.createGet(url).execute().body();
JSONObject jsonObject = JSONObject.parseObject(body);
return jsonObject;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论