提交 8bdb779e 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

bizCode值都放到code中 抛异常出去

上级 00d4ce52
流水线 #22165 已失败 于阶段
in 6 second
...@@ -16,6 +16,7 @@ import com.pica.cloud.account.account.server.util.*; ...@@ -16,6 +16,7 @@ import com.pica.cloud.account.account.server.util.*;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse; import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.foundation.redis.ICacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.CommonUtil; import com.pica.cloud.foundation.utils.utils.CommonUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils; import com.pica.cloud.foundation.utils.utils.ValidateUtils;
...@@ -80,26 +81,14 @@ public class AutoCodeController extends AccountBaseController { ...@@ -80,26 +81,14 @@ public class AutoCodeController extends AccountBaseController {
if (request.getBizType() != null && request.getBizType().equals(1)) { if (request.getBizType() != null && request.getBizType().equals(1)) {
// 调用风控接口 // 调用风控接口
UnifiedVerificationResp rcResp = this.rcValidate( this.rcValidate(request.getMobile(), request.getFlag(),
request.getMobile(), IPUtil.getIpAdrress(req), super.getDeviceInfo(),
request.getFlag(),
IPUtil.getIpAdrress(req),
super.getDeviceInfo(),
request.getDevice_token()); request.getDevice_token());
if (rcResp == null) { // 发送短信验证码
// 风控接口调用异常也继续后面的逻辑 processSysCode(request.getMobile(), request.getFlag());
return getPicaResponse(request); return PicaResponse.toResponse();
} else {
if (null == rcResp.getBizCode()) {
// 风控校验后允许发送短信验证码
return getPicaResponse(request);
} else {
// 风控接口调用正常,并返回业务提示给前端
return PicaResponse.toResponse(rcResp);
}
}
} else { } else {
// 老版本业务 // 老版本业务(发送短信验证码)
processSysCode(request.getMobile(), request.getFlag()); processSysCode(request.getMobile(), request.getFlag());
// 记录风控数据 // 记录风控数据
recordRcData(req, request); recordRcData(req, request);
...@@ -107,14 +96,6 @@ public class AutoCodeController extends AccountBaseController { ...@@ -107,14 +96,6 @@ public class AutoCodeController extends AccountBaseController {
} }
} }
private PicaResponse getPicaResponse(BaseRequest request) {
processSysCode(request.getMobile(), request.getFlag());
UnifiedVerificationResp rcResp = new UnifiedVerificationResp();
rcResp.setBizCode(1);
rcResp.setBizMsg("验证码发送成功");
return PicaResponse.toResponse(rcResp);
}
@ApiOperation("获取短信验证码,需要图形验证码,如H5端和PC端;验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 4重置密码 5忘记密码 7患者招募提交问卷(效验)") @ApiOperation("获取短信验证码,需要图形验证码,如H5端和PC端;验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 4重置密码 5忘记密码 7患者招募提交问卷(效验)")
@PostMapping("/account/authCode") @PostMapping("/account/authCode")
public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity, public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity,
...@@ -264,10 +245,8 @@ public class AutoCodeController extends AccountBaseController { ...@@ -264,10 +245,8 @@ public class AutoCodeController extends AccountBaseController {
* @Params [mobile] * @Params [mobile]
* @Return com.pica.cloud.account.account.server.resp.UnifiedVerificationResp * @Return com.pica.cloud.account.account.server.resp.UnifiedVerificationResp
*/ */
private UnifiedVerificationResp rcValidate(String mobile, private void rcValidate(String mobile,Integer flag,
Integer flag, String publicIp,String deviceInfoStr,
String publicIp,
String deviceInfoStr,
String deviceToken) { String deviceToken) {
// 调用风控接口 // 调用风控接口
try { try {
...@@ -285,61 +264,43 @@ public class AutoCodeController extends AccountBaseController { ...@@ -285,61 +264,43 @@ public class AutoCodeController extends AccountBaseController {
if (picaResponse != null && if (picaResponse != null &&
PicaResultCode.SUCCESS.code().equals(picaResponse.getCode())) { PicaResultCode.SUCCESS.code().equals(picaResponse.getCode())) {
Object data = picaResponse.getData(); Object data = picaResponse.getData();
if (Objects.isNull(data)) { if (Objects.nonNull(data)) {
return null;
}
CheckcodeRiskResp respData = JSON.parseObject( CheckcodeRiskResp respData = JSON.parseObject(
JSON.toJSONString(data), CheckcodeRiskResp.class); JSON.toJSONString(data), CheckcodeRiskResp.class);
if(StringUtils.isEmpty(respData.getProcessCode())){ if(StringUtils.isNotEmpty(respData.getProcessCode())){
// 请求返回异常
return null;
}
Integer processCode = Integer.valueOf(respData.getProcessCode()); Integer processCode = Integer.valueOf(respData.getProcessCode());
if(null == processCode){ if(null != processCode){
// 请求返回的processCode异常
return null;
}
// 请求返回正常 // 请求返回正常
if (processCode.equals(BizTypeRespEnum.RC_SEND_FAIL.getCode())) { if (processCode.equals(BizTypeRespEnum.RC_SEND_FAIL.getCode())) {
UnifiedVerificationResp resp = new UnifiedVerificationResp(); throw new PicaWarnException(AccountExceptionEnum.PICA_RC_SEND_FAIL.getCode(),
resp.setBizCode(BizTypeRespEnum.RC_SEND_FAIL.getCode()); AccountExceptionEnum.PICA_RC_SEND_FAIL.getMessage());
resp.setBizMsg(BizTypeRespEnum.RC_SEND_FAIL.getMsg());
return resp;
} else if (processCode.equals(BizTypeRespEnum.RC_TRIGGER.getCode())) { } else if (processCode.equals(BizTypeRespEnum.RC_TRIGGER.getCode())) {
UnifiedVerificationResp resp = new UnifiedVerificationResp(); throw new PicaWarnException(AccountExceptionEnum.PICA_RC_TRIGGER.getCode(),
resp.setBizCode(BizTypeRespEnum.RC_TRIGGER.getCode()); AccountExceptionEnum.PICA_RC_TRIGGER.getMessage());
resp.setBizMsg(BizTypeRespEnum.RC_TRIGGER.getMsg());
return resp;
} else if (processCode.equals(BizTypeRespEnum.RC_BLACKLIST.getCode())) { } else if (processCode.equals(BizTypeRespEnum.RC_BLACKLIST.getCode())) {
UnifiedVerificationResp resp = new UnifiedVerificationResp(); throw new PicaWarnException(AccountExceptionEnum.PICA_RC_BLACKLIST.getCode(),
resp.setBizCode(BizTypeRespEnum.RC_BLACKLIST.getCode()); AccountExceptionEnum.PICA_RC_BLACKLIST.getMessage());
resp.setBizMsg(BizTypeRespEnum.RC_BLACKLIST.getMsg());
return resp;
} else if (processCode.equals(BizTypeRespEnum.RC_DAY_LIMIT.getCode())) { } else if (processCode.equals(BizTypeRespEnum.RC_DAY_LIMIT.getCode())) {
UnifiedVerificationResp resp = new UnifiedVerificationResp(); throw new PicaWarnException(AccountExceptionEnum.PICA_RC_DAY_LIMIT.getCode(),
resp.setBizCode(BizTypeRespEnum.RC_DAY_LIMIT.getCode()); AccountExceptionEnum.PICA_RC_DAY_LIMIT.getMessage());
resp.setBizMsg(BizTypeRespEnum.RC_DAY_LIMIT.getMsg());
return resp;
} else if (processCode.equals(BizTypeRespEnum.RC_60_SECOND_LIMIT.getCode())) { } else if (processCode.equals(BizTypeRespEnum.RC_60_SECOND_LIMIT.getCode())) {
UnifiedVerificationResp resp = new UnifiedVerificationResp();
resp.setBizCode(BizTypeRespEnum.RC_60_SECOND_LIMIT.getCode());
// 获取剩余秒数 // 获取剩余秒数
Long time = cacheClient.get(this.getAuthCodeKey(mobile, flag.toString()) + "-secure", Long.class); Long time = cacheClient.get(this.getAuthCodeKey(mobile, flag.toString()) + "-secure", Long.class);
int remainTime = 59 - (int) (System.currentTimeMillis() - time) / 1000; int remainTime = 59 - (int) (System.currentTimeMillis() - time) / 1000;
if (remainTime > 0) { if (remainTime > 0) {
resp.setBizMsg(BizTypeRespEnum.RC_60_SECOND_LIMIT.getMsg() throw new PicaWarnException(AccountExceptionEnum.PICA_RC_60_SECOND_LIMIT.getCode(),
.replace("{remainTime}", String.valueOf(remainTime))); AccountExceptionEnum.PICA_RC_60_SECOND_LIMIT.getMessage().replace("{remainTime}", String.valueOf(remainTime)));
} }
return resp;
} else { } else {
// processCode=1(允许发送短信验证码) // processCode=1(允许发送短信验证码)
return new UnifiedVerificationResp();
} }
} }
return null; }
}
}
} catch (Exception e) { } catch (Exception e) {
logger.error("风控接口调用异常", e); logger.error("风控接口调用异常", e);
return null;
} }
} }
......
...@@ -213,7 +213,8 @@ public class LoginController extends AccountBaseController { ...@@ -213,7 +213,8 @@ public class LoginController extends AccountBaseController {
@PostMapping("/unifiedVerification") @PostMapping("/unifiedVerification")
public PicaResponse unifiedVerification(@RequestBody EncryptEntity entity) throws Exception{ public PicaResponse unifiedVerification(@RequestBody EncryptEntity entity) throws Exception{
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
return PicaResponse.toResponse(loginService.preLoginValidate(request)); loginService.preLoginValidate(request);
return PicaResponse.toResponse();
} }
@ApiOperation(value = "苹果授权登录") @ApiOperation(value = "苹果授权登录")
......
...@@ -37,6 +37,18 @@ public enum AccountExceptionEnum { ...@@ -37,6 +37,18 @@ public enum AccountExceptionEnum {
PICA_APPLE_BIND_OTHER("216529", "该Apple账号已绑定其他账户"), PICA_APPLE_BIND_OTHER("216529", "该Apple账号已绑定其他账户"),
PICA_MOBILE_BIND_OTHER("216530", "该手机号已绑定其他Apple账号"), PICA_MOBILE_BIND_OTHER("216530", "该手机号已绑定其他Apple账号"),
PICA_MOBILE_REG_FALSE("216531", "请输入正确的手机号"),
PICA_MOBILE_NOT_REGIST("216533", "该手机号{mobile}尚未设置密码,请先设置密码。"),
PICA_MOBILE_NOT_SETED_PASSWORD("216534", "该手机号{mobile}尚未设置密码,请先设置密码。"),
// 风控禁止发送
PICA_RC_SEND_FAIL("216536", "发送失败"),
PICA_RC_TRIGGER("216537", "需要触发风控滑动验证"),
// 账号、IP、设备在黑名单内,前端提示发送成功,后端不发送短信
PICA_RC_BLACKLIST("216538", "发送成功"),
PICA_RC_DAY_LIMIT("216539", "今日获取验证码次数已超过上限,请使用账户密码登录"),
PICA_RC_60_SECOND_LIMIT("216540", "验证码发送频率过高,请{remainTime}秒后再试"),
xxx_xxx("",""); xxx_xxx("","");
......
...@@ -18,12 +18,6 @@ public enum BizTypeRespEnum { ...@@ -18,12 +18,6 @@ public enum BizTypeRespEnum {
RC_DAY_LIMIT(5, "今日获取验证码次数已超过上限,请使用账户密码登录"), RC_DAY_LIMIT(5, "今日获取验证码次数已超过上限,请使用账户密码登录"),
RC_60_SECOND_LIMIT(6, "验证码发送频率过高,请{remainTime}秒后再试"), RC_60_SECOND_LIMIT(6, "验证码发送频率过高,请{remainTime}秒后再试"),
MOBILE_REG_FALSE(7, "请输入正确的手机号"),
MOBILE_REG_TRUE(8, "手机号符合规则"),
MOBILE_NOT_REGIST(9, "该手机号{mobile}尚未设置密码,请先设置密码。"),
MOBILE_NOT_SETED_PASSWORD(10, "该手机号{mobile}尚未设置密码,请先设置密码。"),
MOBILE_SETED_PASSWORD(11, "手机号已设置密码"),
XXX(0, "xxxxxx"); XXX(0, "xxxxxx");
......
...@@ -68,7 +68,7 @@ public interface LoginService { ...@@ -68,7 +68,7 @@ public interface LoginService {
* @Params [request] * @Params [request]
* @Return com.pica.cloud.foundation.entity.PicaResponse * @Return com.pica.cloud.foundation.entity.PicaResponse
*/ */
UnifiedVerificationResp preLoginValidate(BaseRequest request); void preLoginValidate(BaseRequest request);
LoginResult oneClickLogin(OneClickLoginReq req); LoginResult oneClickLogin(OneClickLoginReq req);
......
...@@ -4,6 +4,7 @@ package com.pica.cloud.account.account.server.service.impl; ...@@ -4,6 +4,7 @@ package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.auth0.jwk.InvalidPublicKeyException;
import com.auth0.jwk.Jwk; import com.auth0.jwk.Jwk;
import com.pica.cloud.account.account.server.constants.Constants; import com.pica.cloud.account.account.server.constants.Constants;
import com.pica.cloud.account.account.server.entity.*; import com.pica.cloud.account.account.server.entity.*;
...@@ -28,6 +29,7 @@ import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants; ...@@ -28,6 +29,7 @@ import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils; import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.foundation.redis.ICacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.ValidateUtils; import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import com.pica.cloud.patient.smartcontract.common.utils.HttpClientCloudUtils; import com.pica.cloud.patient.smartcontract.common.utils.HttpClientCloudUtils;
...@@ -534,55 +536,44 @@ public class LoginServiceImpl implements LoginService { ...@@ -534,55 +536,44 @@ public class LoginServiceImpl implements LoginService {
* @Return com.pica.cloud.foundation.entity.PicaResponse * @Return com.pica.cloud.foundation.entity.PicaResponse
*/ */
@Override @Override
public UnifiedVerificationResp preLoginValidate(BaseRequest request) { public void preLoginValidate(BaseRequest request) {
UnifiedVerificationResp resp = new UnifiedVerificationResp();
Integer bizType = request.getBizType(); Integer bizType = request.getBizType();
String mobile = request.getMobile(); String mobile = request.getMobile();
if (null == bizType) { if (null == bizType) {
logger.info("bizType is null"); logger.info("bizType is null");
return resp; throw new PicaWarnException(PicaResultCode.PARAM_IS_BLANK.code(),
PicaResultCode.PARAM_IS_BLANK.message());
} }
if(bizType.equals(2)) { if (bizType.equals(2)) {
// 手机号规则校验 // 手机号规则校验
if (StringUtils.isNotEmpty(mobile) && if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) { !ValidateUtils.isMobile(mobile)) {
resp.setBizCode(BizTypeRespEnum.MOBILE_REG_FALSE.getCode()); throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
resp.setBizMsg(BizTypeRespEnum.MOBILE_REG_FALSE.getMsg()); AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
} else {
resp.setBizCode(BizTypeRespEnum.MOBILE_REG_TRUE.getCode());
resp.setBizMsg(BizTypeRespEnum.MOBILE_REG_TRUE.getMsg());
} }
}else if(bizType.equals(3)){ } else if (bizType.equals(3)) {
// 手机号规则校验 // 手机号规则校验
if (StringUtils.isNotEmpty(mobile) && if (StringUtils.isNotEmpty(mobile) &&
!ValidateUtils.isMobile(mobile)) { !ValidateUtils.isMobile(mobile)) {
resp.setBizMsg(BizTypeRespEnum.MOBILE_REG_FALSE.getMsg()); throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getCode(),
resp.setBizCode(BizTypeRespEnum.MOBILE_REG_FALSE.getCode()); AccountExceptionEnum.PICA_MOBILE_REG_FALSE.getMessage());
return resp;
} }
// 手机号是否注册 // 手机号是否注册
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile)); AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfo == null) { if (accountInfo == null) {
resp.setBizCode(BizTypeRespEnum.MOBILE_NOT_REGIST.getCode()); throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getCode(),
resp.setBizMsg(BizTypeRespEnum.MOBILE_NOT_REGIST.getMsg() AccountExceptionEnum.PICA_MOBILE_NOT_REGIST.getMessage());
.replace("{mobile}", mobile));
return resp;
} }
// 手机号是否设置了密码 // 手机号是否设置了密码
if (StringUtils.isEmpty(accountInfo.getPassword())) { if (StringUtils.isEmpty(accountInfo.getPassword())) {
resp.setBizCode(BizTypeRespEnum.MOBILE_NOT_SETED_PASSWORD.getCode()); throw new PicaWarnException(AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getCode(),
resp.setBizMsg(BizTypeRespEnum.MOBILE_NOT_SETED_PASSWORD.getMsg() AccountExceptionEnum.PICA_MOBILE_NOT_SETED_PASSWORD.getMessage());
.replace("{mobile}", mobile));
} else {
resp.setBizMsg(BizTypeRespEnum.MOBILE_SETED_PASSWORD.getMsg());
resp.setBizCode(BizTypeRespEnum.MOBILE_SETED_PASSWORD.getCode());
} }
} }
return resp;
} }
/** /**
...@@ -603,7 +594,6 @@ public class LoginServiceImpl implements LoginService { ...@@ -603,7 +594,6 @@ public class LoginServiceImpl implements LoginService {
} }
// identifyToken校验 // identifyToken校验
if(!checkIdentifyToken(request)){ if(!checkIdentifyToken(request)){
logger.info(JSON.toJSONString(request));
throw new PicaException( throw new PicaException(
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getCode(), AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getCode(),
AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getMessage()); AccountExceptionEnum.PICA_APPLE_TOKEN_ERROR.getMessage());
...@@ -700,6 +690,54 @@ public class LoginServiceImpl implements LoginService { ...@@ -700,6 +690,54 @@ public class LoginServiceImpl implements LoginService {
return false; return false;
} }
public static void main(String[] args) throws InvalidPublicKeyException {
String jwt = "eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnl1bnF1ZXlpLkRvY3RvciIsImV4cCI6MTU4Mjc4MjE2NSwiaWF0IjoxNTgyNzgxNTY1LCJzdWIiOiIwMDExMzAuMmI4NzE0NjVmZDFmNDVmZmFmNWRjMjg3ZTQ4OWVlZjEuMDMxNSIsImNfaGFzaCI6Ing1b3lsbXRCdG9XRy02eFVzakRNRUEiLCJlbWFpbCI6IjdnZ2E1cmo1dGNAcHJpdmF0ZXJlbGF5LmFwcGxlaWQuY29tIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwiaXNfcHJpdmF0ZV9lbWFpbCI6InRydWUiLCJhdXRoX3RpbWUiOjE1ODI3ODE1NjUsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.QKybdVM-1cQBNYeVzYvoQY8rc2ZdRAeq8dJQqbd0zagkmz8X9eoVoKvLxI-cO09bbpRAGMv7Bz-bVcIDgUjIxhxudInmhU2vltfYGEt5meKHjsgKg_qdjyK_WC_bG3N-LhfHUhiA1n3rU0owSxVOWdBxmnYZhftjMd2kGphY-leVPYMoUJRKPteJAMx-F8er1L9nBkrfazoE61Y5GR_y8qtdVFIqlo9oPEGlb1qUC7A4kSGp5OVb4vRvWiqQj7MTjsYIGfqUWQmnkoA7dvlCpbiHdel3Lq6UexS4XzC_FBYC7ekBFU1EO-5rFUflhzmxepPnD8S51eS1CO0ProwwOA";
//jwt= "eyJraWQiOiI4NkQ4OEtmIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnl1bnF1ZXlpLkRvY3RvciIsImV4cCI6MTU4Mjc4MDgzMiwiaWF0IjoxNTgyNzgwMjMyLCJzdWIiOiIwMDExMzAuMmI4NzE0NjVmZDFmNDVmZmFmNWRjMjg3ZTQ4OWVlZjEuMDMxNSIsImNfaGFzaCI6Ilg0TzJGQnBQNlJHSm5yTTJaX2toYXciLCJlbWFpbCI6IjdnZ2E1cmo1dGNAcHJpdmF0ZXJlbGF5LmFwcGxlaWQuY29tIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwiaXNfcHJpdmF0ZV9lbWFpbCI6InRydWUiLCJhdXRoX3RpbWUiOjE1ODI3ODAyMzIsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.fB6Av1KK38U65HbP5XDfNjWyl2i9C9ojHSxAytDKjXHTCaXB2VMHmmnGzEaoSMnS0WR7LilugrmznqOIXkV8i-SyATw-Wx6hWg_9aiBOj-1eeQhUrqZGsWhjklxCFfK0WpAiyNNSAwiklgiZY41P0jrHzNbxk_5WVIxb0sEQ-igLYQhonTeLQ8WuYuCB6iRMlWHxwNdpSNXb-IlzjEKNm1cozf8RRjg0Y00Hu2VPEai2NJzGx5Ro7x7OpvCfePjxlyJze0tSYDVWxBnklBvHGDHXuTqKqMwNNHzo53JIiSARQD7JHxNCgtNTVIYX075zHNn8UgiLZy1mEdf1KnoXHg";
// 向苹果后台获取公钥参数
String appleResp = null;
try {
appleResp = HttpClientCloudUtils.getHttpExecute(Constants.APPLE_GET_PUBLIC_KEY_URL);
} catch (Exception e) {
System.out.println("checkIdentifyToken-get apple public key fail");
throw new PicaException("get apple public key fail Exception", e.getMessage());
}
JSONObject jsonObject = JSONObject.parseObject(appleResp);
String keys = jsonObject.getString("keys");
JSONArray arr = JSONObject.parseArray(keys);
JSONObject jsonObject1 = JSONObject.parseObject(arr.getString(0));
System.out.println("jsonObject1:"+jsonObject1);
Jwk jwa = Jwk.fromValues(jsonObject1);
PublicKey publicKey = jwa.getPublicKey();
String audience= "com.yunqueyi.Doctor";
String subject= "001130.2b871465fd1f45ffaf5dc287e489eef1.0315";
JwtParser jwtParser = Jwts.parser().setSigningKey(publicKey);
jwtParser.requireIssuer(Constants.APPLE_ISSUE_URL);
jwtParser.requireAudience(audience);
jwtParser.requireSubject(subject);
try {
System.out.println("checkIdentifyToken-apple-verify-starting");
Jws<Claims> claim = jwtParser.parseClaimsJws(jwt);
System.out.println("checkIdentifyToken-apple-verify-claim:"+ JSON.toJSONString(claim));
if (claim != null && claim.getBody().containsKey("auth_time")) {
JSONObject claimBody = JSONObject.parseObject(JSON.toJSONString(claim.getBody()), JSONObject.class);
System.out.println("success......");
}
} catch (ExpiredJwtException e) {
System.out.println("checkIdentifyToken-apple token expired" + e.getMessage());
throw new PicaException("apple token expired Exception", e.getMessage());
} catch (Exception e) {
System.out.println("checkIdentifyToken-apple token illegal" + e.getMessage());
throw new PicaException("apple token illegal Exception", e.getMessage());
}
}
/** /**
* @Description 验证苹果公钥 * @Description 验证苹果公钥
* @Author Chongwen.jiang * @Author Chongwen.jiang
......
...@@ -8,7 +8,6 @@ import org.apache.commons.lang3.StringUtils; ...@@ -8,7 +8,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册