mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
update 支付宝登录
This commit is contained in:
@@ -157,6 +157,9 @@ public class MemberController extends BaseController {
|
||||
|
||||
String memberToken = memberService.alipayLogin(dto);
|
||||
response = new RestApiResponse<>(ImmutableMap.of("memberToken", memberToken));
|
||||
} catch (BusinessException e) {
|
||||
logger.error("支付宝登录异常 param:{}", JSON.toJSONString(dto), e);
|
||||
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("支付宝登录异常 param:{}", JSON.toJSONString(dto), e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ALIPAY_LOGIN_ERROR);
|
||||
|
||||
@@ -8,8 +8,10 @@ import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.request.AlipayUserUserinfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import com.alipay.api.response.AlipayUserUserinfoShareResponse;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@@ -285,13 +287,14 @@ public class MemberService {
|
||||
|
||||
// 获取buyer_id
|
||||
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
|
||||
// AlipayUserUserinfoShareRequest request = new AlipayUserUserinfoShareRequest();
|
||||
AlipayUserInfoShareResponse response = alipayClient.execute(request, accessToken);
|
||||
if(response.isSuccess()){
|
||||
log.info("调用成功:" + JSON.toJSONString(response));
|
||||
} else {
|
||||
log.info("调用失败:" + JSON.toJSONString(response));
|
||||
}
|
||||
String userId = response.getUserId();
|
||||
String userId = response.getOpenId();
|
||||
String mobile = response.getMobile();
|
||||
|
||||
// 根据appid查询merchantId
|
||||
@@ -312,24 +315,18 @@ public class MemberService {
|
||||
* @param authCode
|
||||
* @return
|
||||
*/
|
||||
private String getAccessToken(String authCode) {
|
||||
private String getAccessToken(String authCode) throws AlipayApiException {
|
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
// 设置授权码
|
||||
request.setCode(authCode);
|
||||
// 设置授权方式
|
||||
request.setGrantType("authorization_code");
|
||||
AlipaySystemOauthTokenResponse response = null;
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
} catch (AlipayApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ALIPAY_ACCESS_TOKEN_ERROR);
|
||||
}
|
||||
String accessToken = "";
|
||||
if (response.isSuccess()) {
|
||||
System.out.println("调用成功");
|
||||
accessToken = response.getAccessToken();
|
||||
}
|
||||
return accessToken;
|
||||
log.info("支付宝getAccessToken:{}", JSON.toJSONString(response));
|
||||
return response.getAccessToken();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user