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