mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-12 03:09:48 +08:00
update 支付宝登录
This commit is contained in:
@@ -272,30 +272,39 @@ public class MemberService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝 通过密文解密 获取手机号码
|
* 支付宝 通过密文解密 获取手机号码
|
||||||
* @param mobileNumberCiphertext
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
private String decryptMobileNumberCiphertext(String mobileNumberCiphertext) throws Exception {
|
// private String decryptMobileNumberCiphertext(String mobileNumberCiphertext) throws Exception {
|
||||||
String decrypt = Factory.Util.AES().decrypt(mobileNumberCiphertext);
|
// String decrypt = Factory.Util.AES().decrypt(mobileNumberCiphertext);
|
||||||
|
// String mobileNumber = JSON.parseObject(decrypt).getString("mobile");
|
||||||
|
// return mobileNumber;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝 通过密文解密 获取手机号码
|
||||||
|
*/
|
||||||
|
private void decryptMobileNumberCiphertext(AlipayLoginDTO dto) throws Exception {
|
||||||
|
String decrypt = Factory.Util.AES().decrypt(dto.getMobileNumberCiphertext());
|
||||||
String mobileNumber = JSON.parseObject(decrypt).getString("mobile");
|
String mobileNumber = JSON.parseObject(decrypt).getString("mobile");
|
||||||
return mobileNumber;
|
dto.setMobileNumber(mobileNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String alipayLogin(AlipayLoginDTO dto) throws Exception {
|
public String alipayLogin(AlipayLoginDTO dto) throws Exception {
|
||||||
String accessToken = getAccessToken(dto.getAuthCode());
|
// 获取AccessToken
|
||||||
|
getAccessToken(dto);
|
||||||
|
|
||||||
|
// 解密手机号
|
||||||
|
decryptMobileNumberCiphertext(dto);
|
||||||
|
|
||||||
// 获取buyer_id
|
// 获取buyer_id
|
||||||
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
|
// AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
|
||||||
// AlipayUserUserinfoShareRequest request = new AlipayUserUserinfoShareRequest();
|
// AlipayUserInfoShareResponse response = alipayClient.execute(request, dto.getAccessToken());
|
||||||
AlipayUserInfoShareResponse response = alipayClient.execute(request, accessToken);
|
// if(response.isSuccess()){
|
||||||
if(response.isSuccess()){
|
// log.info("调用成功:" + JSON.toJSONString(response));
|
||||||
log.info("调用成功:" + JSON.toJSONString(response));
|
// } else {
|
||||||
} else {
|
// log.info("调用失败:" + JSON.toJSONString(response));
|
||||||
log.info("调用失败:" + JSON.toJSONString(response));
|
// }
|
||||||
}
|
// String userId = response.getOpenId();
|
||||||
String userId = response.getOpenId();
|
// String mobile = response.getMobile();
|
||||||
String mobile = response.getMobile();
|
|
||||||
|
|
||||||
// 根据appid查询merchantId
|
// 根据appid查询merchantId
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAliAppId(dto.getAppId());
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAliAppId(dto.getAppId());
|
||||||
@@ -304,21 +313,22 @@ public class MemberService {
|
|||||||
MemberRegisterAndLoginDTO loginDTO = MemberRegisterAndLoginDTO.builder()
|
MemberRegisterAndLoginDTO loginDTO = MemberRegisterAndLoginDTO.builder()
|
||||||
.requestSource(dto.getRequestSource())
|
.requestSource(dto.getRequestSource())
|
||||||
.firstLevelMerchantId(firstLevelMerchantId)
|
.firstLevelMerchantId(firstLevelMerchantId)
|
||||||
.mobileNumber(mobile)
|
.mobileNumber(dto.getMobileNumber())
|
||||||
.buyerId(userId)
|
.buyerId(dto.getOpenId())
|
||||||
.build();
|
.build();
|
||||||
return memberRegisterAndLogin(loginDTO); // 支付宝小程序一键登录
|
return memberRegisterAndLogin(loginDTO); // 支付宝小程序一键登录
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 auth_code(用户授权码)后应尽快调用 alipay.system.oauth.token(换取授权访问令牌接口)换取 access_token(访问令牌)
|
* 获取 auth_code(用户授权码)后应尽快调用 alipay.system.oauth.token(换取授权访问令牌接口)换取 access_token(访问令牌)
|
||||||
* @param authCode
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private String getAccessToken(String authCode) throws AlipayApiException {
|
private void getAccessToken(AlipayLoginDTO dto) throws AlipayApiException {
|
||||||
|
if (StringUtils.isBlank(dto.getAuthCode())) {
|
||||||
|
log.info("换取授权访问令牌接口, authCode为空");
|
||||||
|
}
|
||||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||||
// 设置授权码
|
// 设置授权码
|
||||||
request.setCode(authCode);
|
request.setCode(dto.getAuthCode());
|
||||||
// 设置授权方式
|
// 设置授权方式
|
||||||
request.setGrantType("authorization_code");
|
request.setGrantType("authorization_code");
|
||||||
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
|
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
|
||||||
@@ -326,7 +336,10 @@ public class MemberService {
|
|||||||
throw new BusinessException(ReturnCodeEnum.CODE_ALIPAY_ACCESS_TOKEN_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_ALIPAY_ACCESS_TOKEN_ERROR);
|
||||||
}
|
}
|
||||||
log.info("支付宝getAccessToken:{}", JSON.toJSONString(response));
|
log.info("支付宝getAccessToken:{}", JSON.toJSONString(response));
|
||||||
return response.getAccessToken();
|
String accessToken = response.getAccessToken();
|
||||||
|
dto.setAccessToken(accessToken);
|
||||||
|
String openId = response.getOpenId();
|
||||||
|
dto.setOpenId(openId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,4 +23,8 @@ public class AlipayLoginDTO extends BaseDTO{
|
|||||||
private String authCode;
|
private String authCode;
|
||||||
|
|
||||||
private String accessToken;
|
private String accessToken;
|
||||||
|
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
private String mobileNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user