This commit is contained in:
hongqiwei
2026-01-15 11:49:51 +08:00
parent c86372e447
commit a56afdd4f1
11 changed files with 192 additions and 354 deletions
@@ -36,16 +36,16 @@ public class DataCenterProperties {
@Inject
private RedisService redisService;
private String appId;
private String key;
private String secret;
private String tokenUrl;
private Map<String, String> codes = new HashMap<>();
private Map<String, String> urls = new HashMap<>();
public void init() {
Map<String, String> all = conf.toMap();
appId = all.get("data-center.app-id");
key = all.get("data-center.key");
secret = all.get("data-center.secret");
tokenUrl = all.get("data-center.token-url");
extract(all, "data-center.codes.", codes);
extract(all, "data-center.urls.", urls);
}
@@ -68,12 +68,8 @@ public class DataCenterProperties {
* @return 相关配置
*/
public Credential credential(String key) {
String code = codes.get(key);
String url = urls.get(key);
if (code == null || url == null) {
throw new BaseException("未知业务: " + key);
}
String token = getToken(Integer.parseInt(code), key);
String token = getToken(key);
return new Credential(url, token);
}
@@ -87,11 +83,10 @@ public class DataCenterProperties {
/**
* 获取token
* @param code
* @param keyPrefix
* @return token
*/
private String getToken(Integer code, String keyPrefix) {
private String getToken(String keyPrefix) {
String dateCenterPrefix = RedisConstant.DATE_CENTER_PREFIX + keyPrefix;
String token = redisService.get(dateCenterPrefix);
if (StrUtil.isNotBlank(token)) {
@@ -99,18 +94,18 @@ public class DataCenterProperties {
} else {
HttpRequest httpRequest = HttpUtil.createPost(tokenUrl);
Map<String, Object> reqBody = Map.of(
"appId", appId,
"code", code
"key", key,
"secret", secret
);
httpRequest.body(JSONUtil.toJsonStr(reqBody));
JSONObject resp = JSONUtil.parseObj(httpRequest.execute().body());
if (resp.getInt("code") != 200) {
throw new BaseException("获取token失败: " + resp.getStr("msg"));
if (!"ok".equals(resp.getStr("message"))) {
throw new BaseException("获取token失败: " + resp.getStr("description"));
} else {
JSONObject data = resp.getJSONObject("data");
String tokenStr = data.getStr("token");
Integer expire = data.getInt("expire");
JSONObject data = resp.getJSONObject("result");
String tokenStr = data.getStr("access_token");
Integer expire = data.getInt("expires_in");
redisService.setex(dateCenterPrefix, expire, tokenStr);
return tokenStr;
}
@@ -1,4 +1,4 @@
package com.budwk.app.base.sms.impl.jshvc;
package com.budwk.app.base.sms.impl.ypi;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
@@ -17,7 +17,7 @@ import java.util.List;
import java.util.Map;
/**
* @ClassName SmsJshvcServiceImpl
* @ClassName SmsYpiServiceImpl
* @Author JyuHsin
* @Date 2025/11/26 19:32
* @Version 1.0
@@ -25,12 +25,12 @@ import java.util.Map;
*/
@Slf4j
@IocBean
public class SmsJshvcServiceImpl implements SmsService {
public class SmsYpiServiceImpl implements SmsService {
private static final String APPID = "1430576717768122368";
private static final String APP_SECRET = "19A0ACB03FBQHL4R4XQD";
private static final String TOKEN_URL = "https://gateway.jshvc.edu.cn/token/gateway/accessToken";
private static final String MSG_URL = "https://gateway.jshvc.edu.cn/mp/restful/v2/message/send";
private static final String TOKEN_URL = "https://gateway.ypi.edu.cn/token/gateway/accessToken";
private static final String MSG_URL = "https://gateway.ypi.edu.cn/mp/restful/v2/message/send";
private static final String REDIS_KEY_MSG_ACCESS_TOKEN = "msg:token:";
@Inject
@@ -38,7 +38,7 @@ public class SmsJshvcServiceImpl implements SmsService {
@Override
public void send(String loginName, String content) {
// send(loginName, "智慧工会", content);
send(loginName, "智慧工会", content);
}
@Override
@@ -48,16 +48,16 @@ public class SmsJshvcServiceImpl implements SmsService {
@Override
public void send(String loginName, String title, String content, String link) {
// Map<String, String> paramMap = Map.of("userId", loginName);
// doSend(title, content, List.of(paramMap), link);
Map<String, String> paramMap = Map.of("userId", loginName);
doSend(title, content, List.of(paramMap), link);
}
@Override
public void massSend(List<String> loginNames, String title, String content, String link) {
// List<Map<String, String>> receivers = loginNames.stream()
// .map(name -> Map.of("userId", name))
// .toList();
// doSend(title, content, receivers, link);
List<Map<String, String>> receivers = loginNames.stream()
.map(name -> Map.of("userId", name))
.toList();
doSend(title, content, receivers, link);
}
/**