From c96fbe6b0aeb413a17c429133ee6d81d138144b9 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 09 六月 2026 10:58:52 +0800
Subject: [PATCH] Merge branch '1.0' of http://120.76.84.145:10101/gitblit/r/java/Robotaxi into 1.0
---
xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/SubscribeMessageUtil.java | 32 +++++++++++++++++++++++++++++---
1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/SubscribeMessageUtil.java b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/SubscribeMessageUtil.java
index dfa05a7..4ba7783 100644
--- a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/SubscribeMessageUtil.java
+++ b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/SubscribeMessageUtil.java
@@ -6,7 +6,11 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.xiaopeng.api.dto.account.UserResourcesDto;
+import com.xiaopeng.api.feignClient.account.SSOClient;
+import com.xiaopeng.api.vo.account.WechatAccessTokenResVo;
import com.xiaopeng.common.core.domain.R;
+import com.xiaopeng.common.core.exception.ServiceException;
import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.redis.service.RedisService;
import com.xiaopeng.pushMessage.model.Category;
@@ -18,6 +22,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -34,8 +39,14 @@
@Value("${wx.appletsAppSecret:123456}")
private String wxAppletsAppSecret;
+ @Value("${sso.appid}")
+ private String appId;
+
@Autowired
private RedisService redisService;
+
+ @Resource
+ private SSOClient ssoClient;
@@ -262,6 +273,21 @@
}
+ String getToken(Boolean isRefresh){
+ WechatAccessTokenResVo wechatAccessToken = ssoClient.getWechatAccessToken(appId, wxAppletsAppid, isRefresh);
+ if(null == wechatAccessToken){
+ log.info("获取微信access_token失败");
+ throw new ServiceException("获取微信access_token失败");
+ }
+ if(0 != wechatAccessToken.getCode()){
+ log.info("获取微信access_token失败:{}", wechatAccessToken.getMsg());
+ throw new ServiceException("获取微信access_token失败");
+ }
+ String accessToken = wechatAccessToken.getData().getAccessToken();
+ return accessToken;
+ }
+
+
/**
* 发送消息
* @param template_id 所需下发的订阅模板id
@@ -273,7 +299,7 @@
* @return
*/
public R send(String template_id, String page, String touser, String data, String miniprogram_state, String lang){
- String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getWxAppletsAccessToken();
+ String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getToken(false);
Map<String, Object> params = new HashMap<>();
params.put("template_id", template_id);
params.put("page", page);
@@ -286,13 +312,13 @@
HttpResponse execute = post.execute();
if(execute.getStatus() != 200){
log.info("发送消息失败:{}", execute.body());
- throw new RuntimeException("发送消息失败");
+ return R.fail(execute.body());
}
JSONObject jsonObject = JSON.parseObject(execute.body());
Integer errcode = jsonObject.getInteger("errcode");
if(0 != errcode){
log.info("发送消息失败:{}", jsonObject.getString("errmsg"));
- throw new RuntimeException(jsonObject.getString("errmsg"));
+ return R.fail(jsonObject.getString("errmsg"));
}
return R.ok();
}
--
Gitblit v1.7.1