sysParam 获取值问题

This commit is contained in:
2025-12-24 13:57:40 +08:00
parent 302504b891
commit 240d672211
12 changed files with 125 additions and 91 deletions

View File

@@ -15,6 +15,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 微信公众号
@@ -90,8 +91,10 @@ public class AcAccountUtil {
if (StrUtil.isNotEmpty(accessToken)) {
return accessToken;
}
String acAppId = paramsService.getSysParamValue(ParamCodeCst.Wechat.Ac.USER_WX_AC_APP_ID);
String acSecrete = paramsService.getSysParamValue(ParamCodeCst.Wechat.Ac.USER_WX_AC_SECRETE);
Map<String, String> userAc = paramsService.getParamsByMap("user_ac_key_set", ParamCodeCst.USER_AC_KEY_SET);
// 用户小程序参数
String acAppId = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_APP_ID);
String acSecrete = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_SECRETE);
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", acAppId, acSecrete));
JSONObject respInfo = JSONObject.parseObject(resp);
if (!respInfo.containsKey("access_token")) {
@@ -103,26 +106,4 @@ public class AcAccountUtil {
redisService.set("wx:ac:AccessToken", accessToken, expiresIn - 10);
return accessToken;
}
public static void main(String[] args) {
// String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", "wx1fb600d0f5ea6279", "b4c0534c9b5e6c84a7fe5c2078dff876"));
// System.out.println(resp);
// String accessToken = "97_HZVThQrtvOiCZGrr23ZHN0cVpHBJHc18RSFHU6dvkQDMAme4GsG0NU-Dax1HP5Wx-aGa1l35KaqiMVv61TCj0Qk8DK1LC6kQ8uKLDfgRYVJjX3QjcelmIjp4PCkERBeABAUHR";
// JSONObject bodyJson = new JSONObject();
// //二维码有效时间最大2592000仅临时二维码需要
// bodyJson.put("expire_seconds", "2592000");
// //二维码类型QR_SCENE(临时整型)/QR_STR_SCENE(临时字符串)/QR_LIMIT_SCENE(永久整型)/QR_LIMIT_STR_SCENE(永久字符串)
// bodyJson.put("action_name", "QR_STR_SCENE");
// JSONObject actionInfo = new JSONObject();
// JSONObject scene = new JSONObject();
// scene.put("scene_str", "43525423");
// actionInfo.put("scene", scene);
// bodyJson.put("action_info", actionInfo);
// System.out.println(bodyJson);
//创建临时二维码失败,发送参数: {"action_info":{"scene":{"scene_id":36449}},"action_name":"QR_SCENE","expire_seconds":"2592000"}, 响应内容: {"errcode":40052,"errmsg":"invalid action name rid: 68f5fa37-20fb3162-0f87b4f2"}
//创建临时二维码失败,发送参数: {"action_info":{"scene":{"scene_id":36449}},"action_name":"QR_SCENE","expire_seconds":"2592000"}, 响应内容: {"errcode":40052,"errmsg":"invalid action name rid: 68f5f970-2a84749c-78e4d78f"}
// String resps = HttpUtil.post(StrUtil.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={}", accessToken), JSONObject.toJSONString(bodyJson));
// JSONObject respInfos = JSONObject.parseObject(resps);
// System.out.println(respInfos);
}
}

View File

@@ -17,6 +17,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
/**
* 支付宝通用SDK工具类
*
@@ -37,13 +40,15 @@ public class AlipayUtil {
*/
@SneakyThrows
public AlipayClient createClient(boolean isAccount) {
String serverUrl = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Web.ALI_GATEWAY);
String appId = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Mini.ALI_MINI_APP_ID);
String privateKey = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Mini.ALI_MINI_PRIVATE_KEY);
String alipayPublicKey = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Mini.ALI_MINI_PUBLIC_KEY);
String accountAppId = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_APP_ID);
String accountPrivateKey = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_PRIVATE_KEY);
String accountPublicKey = sysParamsService.getSysParamValue(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_PUBLIC_KEY);
Map<String, String> aliPayKeySet = sysParamsService.getParamsByMap("ali_pay_key_set", ParamCodeCst.ALI_PAY_KEY_SET);
String serverUrl = aliPayKeySet.get(ParamCodeCst.Alipay.Web.ALI_GATEWAY);
String appId = aliPayKeySet.get(ParamCodeCst.Alipay.Mini.ALI_MINI_APP_ID);
String privateKey = aliPayKeySet.get(ParamCodeCst.Alipay.Mini.ALI_MINI_PRIVATE_KEY);
String alipayPublicKey = aliPayKeySet.get(ParamCodeCst.Alipay.Mini.ALI_MINI_PUBLIC_KEY);
String accountAppId = aliPayKeySet.get(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_APP_ID);
String accountPrivateKey = aliPayKeySet.get(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_PRIVATE_KEY);
String accountPublicKey = aliPayKeySet.get(ParamCodeCst.Alipay.Web.ALI_ACCOUNT_PUBLIC_KEY);
AlipayConfig alipayConfig = new AlipayConfig();
//设置网关地址
alipayConfig.setServerUrl(serverUrl);

View File

@@ -56,8 +56,9 @@ public class WechatAuthUtil {
}
public String getAccountOpenId(String code) {
String accountAppId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
String accountSecrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
Map<String, String> shopAc = sysParamsService.getParamsByMap("shop_ac_key_set", ParamCodeCst.SHOP_AC_KEY_SET);
String accountAppId = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
String accountSecrete = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
Map<String, Object> requestUrlParam = new HashMap<>();
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
@@ -78,8 +79,10 @@ public class WechatAuthUtil {
//获取小程序token
private String getAccessToken() {
String appId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
Map<String, String> userMini = sysParamsService.getParamsByMap("user_mini_key_set", ParamCodeCst.USER_MINI_KEY_SET);
// 用户小程序参数
String appId = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, appId, secrete);
String response = HttpUtil.get(url);
com.alibaba.fastjson.JSONObject jsonResponse = com.alibaba.fastjson.JSONObject.parseObject(response);
@@ -120,8 +123,11 @@ public class WechatAuthUtil {
public JSONObject getSession(String code) {
String appId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
Map<String, String> userMini = sysParamsService.getParamsByMap("user_mini_key_set", ParamCodeCst.USER_MINI_KEY_SET);
// 用户小程序参数
String appId = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
Map<String, Object> requestUrlParam = new HashMap<>();
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN

View File

@@ -139,8 +139,9 @@ public class WechatMiniMsgUtil {
}
public String getAccountOpenId(String code) {
String accountAppId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
String accountSecrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
Map<String, String> shopAc = sysParamsService.getParamsByMap("shop_ac_key_set", ParamCodeCst.SHOP_AC_KEY_SET);
String accountAppId = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
String accountSecrete = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
Map<String, Object> requestUrlParam = new HashMap<>();
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
@@ -165,8 +166,10 @@ public class WechatMiniMsgUtil {
if (StrUtil.isNotEmpty(accessToken)) {
return accessToken;
}
String appId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID);
String secrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
// 商户小程序参数
Map<String, String> shopMiniKeyMap = sysParamsService.getParamsByMap("shop_mini_key_set", ParamCodeCst.SHOP_MINI_KEY_SET);
String appId = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID);
String secrete = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, appId, secrete);
String response = HttpUtil.get(url);
@@ -211,8 +214,10 @@ public class WechatMiniMsgUtil {
public JSONObject getSession(String code) {
String appId = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = sysParamsService.getSysParamValue(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
Map<String, String> userMini = sysParamsService.getParamsByMap("user_mini_key_set", ParamCodeCst.USER_MINI_KEY_SET);
// 用户小程序参数
String appId = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
String secrete = userMini.get(ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
Map<String, Object> requestUrlParam = new HashMap<>();
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN

View File

@@ -28,8 +28,6 @@ public class AppWxServiceImpl extends BaseWx {
@DubboReference
private SysParamsService paramsService;
private static final Set<String> USER_MINI_KEYS = Set.of(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID, ParamCodeCst.Wechat.Mini.USER_WX_SECRETE);
public AppWxServiceImpl(@Autowired RedisService autoRedisService) {
this.redisService = autoRedisService;
config = new Config();
@@ -64,10 +62,10 @@ public class AppWxServiceImpl extends BaseWx {
@Override
public void init() throws CzgException {
// 用户小程序参数
Map<String, String> userMiniKeyMap = paramsService.getParamsByMap("userMiniKeys", USER_MINI_KEYS);
Map<String, String> userMiniKeyMap = paramsService.getParamsByMap("user_mini_key_set", ParamCodeCst.USER_MINI_KEY_SET);
// 微信支付参数
Map<String, String> payKeyMap = paramsService.getParamsByMap("payKeys", PAY_KEYS);
Map<String, String> payKeyMap = paramsService.getParamsByMap("pay_key_set", ParamCodeCst.PAY_KEY_SET);
// 小程序id
config.appId = userMiniKeyMap.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);

View File

@@ -59,18 +59,6 @@ public abstract class BaseWx {
*/
protected static final Long EXPIRES_OFFSET = 200L;
/**
* 支付参数KEY
*/
protected static final Set<String> PAY_KEYS = Set.of(
ParamCodeCst.Wechat.Pay.WX_PUB_KEY,
ParamCodeCst.Wechat.Pay.WX_API_CLIENT_KEY,
ParamCodeCst.Wechat.Pay.WX_API_CLIENT_CERT,
ParamCodeCst.Wechat.Pay.WX_MCH_ID,
ParamCodeCst.Wechat.Pay.WX_V3_KEY,
ParamCodeCst.System.NATIVE_NOTIFY_URL
);
/**
* 初始化配置信息
*/

View File

@@ -64,7 +64,7 @@ public class WxServiceImpl extends BaseWx {
@Override
public void init() {
// 商户小程序参数
Map<String, String> shopMiniKeyMap = paramsService.getParamsByMap("shopMiniKeys", shopMiniKeys);
Map<String, String> shopMiniKeyMap = paramsService.getParamsByMap("shop_mini_key_set", ParamCodeCst.SHOP_MINI_KEY_SET);
// 小程序id
config.appId = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID);
@@ -72,7 +72,7 @@ public class WxServiceImpl extends BaseWx {
config.appSecret = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
// 微信支付参数
Map<String, String> payKeyMap = paramsService.getParamsByMap("payKeys", PAY_KEYS);
Map<String, String> payKeyMap = paramsService.getParamsByMap("pay_key_set", ParamCodeCst.PAY_KEY_SET);
config.certPath = "";
// 微信支付公钥
config.pubKey = payKeyMap.get(ParamCodeCst.Wechat.Pay.WX_PUB_KEY);

View File

@@ -12,6 +12,9 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.Map;
import java.util.Set;
/**
* 验证码工具类
*
@@ -23,38 +26,24 @@ public class SmsServiceImpl implements SmsService {
@Resource
private SysParamsService sysParamsService;
/**
* 阿里云key
*/
private String key;
/**
* 阿里云secret
*/
private String secret;
/**
* 短信模板id
*/
private String templateCode;
@PostConstruct
public void init() {
key = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_KEY);
secret = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_SECRET);
templateCode = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_TEMPLATE_CODE);
log.info("短信工具类初始化完毕key: {}, secret: {}, templateCode: {}", key, secret, templateCode);
}
public Client createClient() throws Exception {
public Client init() throws Exception {
Config config = new Config();
config.accessKeyId = key;
config.accessKeySecret = secret;
Map<String, String> aliOssKeys = sysParamsService.getParamsByMap("ali_oss_key_set", ParamCodeCst.ALI_OSS_KEY_SET);
config.accessKeyId = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_KEY);
config.accessKeySecret = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_SECRET);
templateCode = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_TEMPLATE_CODE);
return new Client(config);
}
@Override
public void sendCode(String phone, String checkCode) {
try {
Client client = createClient();
Client client = init();
// 1.发送短信
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
.setSignName("陕西超掌柜科技")
@@ -67,7 +56,7 @@ public class SmsServiceImpl implements SmsService {
if (sendSmsResponse.getStatusCode() != 200) {
throw new CzgException("短信发送失败");
}
}catch (Exception e) {
} catch (Exception e) {
log.info("发送短信失败", e);
}
}

View File

@@ -140,12 +140,12 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
@Cacheable(cacheNames = "params:entity", key = "#type")
@Override
public Map<String, String> getParamsByMap(String type, Set<String> keyList) throws CzgException{
public Map<String, String> getParamsByMap(String type, Set<String> keyList) throws CzgException {
Map<String, String> map = new HashMap<>();
for (String key : keyList) {
SysParams sysParam = getSysParam(key);
if (sysParam == null || StrUtil.isBlank(sysParam.getParamValue())) {
throw new CzgException(key + "参数不存在");
throw new CzgException("sysParam的类型" + type + "" + key + "参数不存在");
}
map.put(key, sysParam.getParamValue());
}