支付宝和微信工具类参数从sysParam取出

This commit is contained in:
张松
2025-03-10 10:52:44 +08:00
parent f3193de09b
commit 547f2b046b

View File

@@ -10,7 +10,6 @@ import com.czg.system.service.SysParamsService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@@ -23,7 +22,7 @@ import java.util.Map;
@Slf4j
@Component
public class WechatAuthUtil {
@DubboReference
@DubboReference(check = false)
private SysParamsService sysParamsService;
// @Value("${wx.appId}")
@@ -86,7 +85,7 @@ public class WechatAuthUtil {
return JSONObject.parseObject(resp).getString("openid");
}
public String getSessionKey(String code, String key) {
public JSONObject getSession(String code) {
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
@@ -102,7 +101,12 @@ public class WechatAuthUtil {
String resp = HttpUtil.post(requestUrl, requestUrlParam);
JSONObject jsonObject = JSON.parseObject(resp);
log.info("微信获取openid响应报文{}", resp);
String info = jsonObject.getString(key);
return jsonObject;
}
public String getSessionKey(String code, String key) {
JSONObject session = getSession(code);
String info = session.getString(key);
if (StrUtil.isBlank(info)) {
throw new RuntimeException(key + "获取失败");
}