添加支付宝以及微信公众号配置参数
This commit is contained in:
@@ -37,9 +37,9 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
public String getOpenId(String code, String source) {
|
||||
String openId;
|
||||
if (UserAuthSourceEnum.WECHAT.getValue().equals(source)) {
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(code);
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(code, true);
|
||||
}else {
|
||||
openId = alipayUtil.getOpenId(code);
|
||||
openId = alipayUtil.getOpenId(code, true);
|
||||
}
|
||||
return openId;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
UserInfo userInfo;
|
||||
String openId;
|
||||
if (UserAuthSourceEnum.WECHAT.getValue().equals(userAuthorizationLoginDTO.getSource())) {
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(userAuthorizationLoginDTO.getCode());
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(userAuthorizationLoginDTO.getCode(), false);
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getWechatOpenId, openId).one();
|
||||
userInfo = userInfo == null ? new UserInfo() : userInfo;
|
||||
if (StrUtil.isNotBlank(userAuthorizationLoginDTO.getRawData())) {
|
||||
@@ -62,7 +62,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
}
|
||||
userInfo.setWechatOpenId(openId);
|
||||
} else {
|
||||
openId = alipayUtil.getOpenId(userAuthorizationLoginDTO.getCode());
|
||||
openId = alipayUtil.getOpenId(userAuthorizationLoginDTO.getCode(), false);
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getAlipayOpenId, openId).one();
|
||||
userInfo = userInfo == null ? new UserInfo() : userInfo;
|
||||
userInfo.setNickName("支付宝用户");
|
||||
|
||||
@@ -32,6 +32,7 @@ public class AlipayUtil {
|
||||
*/
|
||||
@Value("${alipay.appId}")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 应用私钥
|
||||
*/
|
||||
@@ -48,30 +49,38 @@ public class AlipayUtil {
|
||||
@Value("${alipay.encryptKey}")
|
||||
private String encryptKey;
|
||||
|
||||
@Value("${alipay.account.appId}")
|
||||
private String accountAppId;
|
||||
@Value("${alipay.account.privateKey}")
|
||||
private String accountPrivateKey;
|
||||
@Value("${alipay.account.publicKey}")
|
||||
private String accountPublicKey;
|
||||
|
||||
/**
|
||||
* 创建支付宝客户端
|
||||
* @return AlipayClient
|
||||
*/
|
||||
@SneakyThrows
|
||||
public AlipayClient createClient() {
|
||||
public AlipayClient createClient(boolean isAccount) {
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
//设置网关地址
|
||||
alipayConfig.setServerUrl(serverUrl);
|
||||
//设置应用ID
|
||||
alipayConfig.setAppId(appId);
|
||||
alipayConfig.setAppId(isAccount ? accountAppId : appId);
|
||||
//设置应用私钥
|
||||
alipayConfig.setPrivateKey(privateKey);
|
||||
alipayConfig.setPrivateKey(isAccount ? accountPrivateKey : privateKey);
|
||||
//设置支付宝公钥
|
||||
alipayConfig.setAlipayPublicKey(alipayPublicKey);
|
||||
alipayConfig.setAlipayPublicKey(isAccount ? accountPublicKey : alipayPublicKey);
|
||||
return new DefaultAlipayClient(alipayConfig);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取支付宝用户的openId
|
||||
* @param code 用户信息授权码
|
||||
* @return openId
|
||||
*/
|
||||
public String getOpenId(String code){
|
||||
public String getOpenId(String code, boolean isAccount){
|
||||
AlipaySystemOauthTokenRequest req = new AlipaySystemOauthTokenRequest();
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数
|
||||
req.setCode(code);
|
||||
@@ -80,7 +89,7 @@ public class AlipayUtil {
|
||||
//req.setBizContent(" {" + " \"primary_industry_name\":\"IT科技/IT软件与服务\"," + " \"primary_industry_code\":\"10001/20102\"," + " \"secondary_industry_code\":\"10001/20102\"," + " \"secondary_industry_name\":\"IT科技/IT软件与服务\"" + " }");
|
||||
AlipaySystemOauthTokenResponse response;
|
||||
try {
|
||||
response = createClient().execute(req);
|
||||
response = createClient(isAccount).execute(req);
|
||||
}catch (Exception e){
|
||||
log.error("获取支付宝用户信息失败", e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -21,10 +21,16 @@ public class WechatAuthUtil {
|
||||
|
||||
@Value("${wx.appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${wx.secrete}")
|
||||
private String secrete;
|
||||
|
||||
@Value("${wx.account.appId}")
|
||||
private String accountAppId;
|
||||
@Value("${wx.account.secrete}")
|
||||
private String accountSecrete;
|
||||
|
||||
|
||||
|
||||
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
@@ -41,14 +47,14 @@ public class WechatAuthUtil {
|
||||
|
||||
}
|
||||
|
||||
public String getSessionKeyOrOpenId(String code) {
|
||||
public String getSessionKeyOrOpenId(String code, boolean isAccount) {
|
||||
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
|
||||
//小程序appId
|
||||
requestUrlParam.put("appid", appId);
|
||||
requestUrlParam.put("appid", isAccount ? accountAppId : appId);
|
||||
//小程序secret
|
||||
requestUrlParam.put("secret", secrete);
|
||||
requestUrlParam.put("secret", isAccount ? accountSecrete : secrete);
|
||||
//小程序端返回的code
|
||||
requestUrlParam.put("js_code", code);
|
||||
//默认参数
|
||||
|
||||
Reference in New Issue
Block a user