支付宝登录

This commit is contained in:
Guoqs
2024-06-11 16:30:42 +08:00
parent 0aef83548c
commit d30be0215e
13 changed files with 202 additions and 127 deletions

View File

@@ -1,16 +1,21 @@
package com.jsowell.alipay.service;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipayEncrypt;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse;
import com.alipay.easysdk.factory.Factory;
import com.jsowell.alipay.config.AliPayConfig;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -22,36 +27,34 @@ import java.util.Map;
/**
* 支付宝小程序service
*/
@Slf4j
@Service
public class AliAppletRemoteService {
private Logger log = LoggerFactory.getLogger(AliAppletRemoteService.class);
/**
* 通过authCode获取手机号
* @param code
* @return
* @throws Exception
*/
public String getMobileNumberByCode(String code) throws Exception {
AlipaySystemOauthTokenResponse token = Factory.Base.OAuth().getToken(code);
log.info("AlipaySystemOauthTokenResponse:{}", JSON.toJSONString(token));
String accessToken = token.getAccessToken();
// Factory.Util.AES().decrypt();
return "";
}
/**
* (支付宝) 换取授权访问令牌
* alipay.system.oauth.token(换取授权访问令牌)
* 通过openIdCode获取openId
* @param openIdCode
* @return
*/
@RequestMapping("getInfo")
public RestApiResponse<?> getInfo(String auth_code) throws AlipayApiException {
RestApiResponse<?> restApiResponse;
try {
if(auth_code==null||auth_code.length()==0) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
Map<String,Object> map=new HashMap<>();
map.put("userid", "");
restApiResponse = new RestApiResponse<>(map);
} catch (BusinessException e) {
restApiResponse = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
restApiResponse = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);
}
return restApiResponse;
public String getOpenId(String openIdCode) {
return "";
}
}