|
|
@@ -11,8 +11,11 @@ import com.alipay.api.AlipayClient;
|
|
|
import com.alipay.api.DefaultAlipayClient;
|
|
|
import com.alipay.api.request.AlipayUserCertifyOpenCertifyRequest;
|
|
|
import com.alipay.api.request.AlipayUserCertifyOpenInitializeRequest;
|
|
|
+import com.alipay.api.request.AlipayUserCertifyOpenQueryRequest;
|
|
|
import com.alipay.api.response.AlipayUserCertifyOpenCertifyResponse;
|
|
|
import com.alipay.api.response.AlipayUserCertifyOpenInitializeResponse;
|
|
|
+import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
|
|
|
+import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
import com.izouma.nineth.TokenHistory;
|
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
|
@@ -100,6 +103,7 @@ public class UserService {
|
|
|
private TradingAccountRepo tradingAccountRepo;
|
|
|
private AlipayClient alipayClient;
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private FaceAuthRepo faceAuthRepo;
|
|
|
|
|
|
public User update(User user) {
|
|
|
if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
|
|
|
@@ -974,10 +978,11 @@ public class UserService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public String prepareAliAuth(String type, String name, String no) throws AlipayApiException {
|
|
|
+ public String prepareAliAuth(String type, Long userId, String name, String no) throws AlipayApiException {
|
|
|
+ String aliAuthId = snowflakeIdWorker.nextId() + "";
|
|
|
AlipayUserCertifyOpenInitializeRequest request = new AlipayUserCertifyOpenInitializeRequest();
|
|
|
JSONObject biz = new JSONObject();
|
|
|
- biz.put("outer_order_no", snowflakeIdWorker.nextId() + "");
|
|
|
+ biz.put("outer_order_no", aliAuthId);
|
|
|
biz.put("biz_code", "FACE");
|
|
|
JSONObject identity_param = new JSONObject();
|
|
|
identity_param.put("identity_type", "CERT_INFO");
|
|
|
@@ -986,13 +991,20 @@ public class UserService {
|
|
|
identity_param.put("cert_no", no);
|
|
|
biz.put("identity_param", identity_param);
|
|
|
JSONObject merchant_config = new JSONObject();
|
|
|
- merchant_config.put("return_url", "https://www.raex.vip/");
|
|
|
+ merchant_config.put("return_url", "alipays://platformapi/startapp?saId=10000007&qrcode=https://www.raex.vip");
|
|
|
biz.put("merchant_config", merchant_config);
|
|
|
log.info(JSON.toJSONString(biz, true));
|
|
|
request.setBizContent(biz.toJSONString());
|
|
|
AlipayUserCertifyOpenInitializeResponse response = alipayClient.execute(request);
|
|
|
if (response.isSuccess()) {
|
|
|
- return response.getCertifyId();
|
|
|
+ String certifyId = response.getCertifyId();
|
|
|
+ faceAuthRepo.save(FaceAuth.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .name(name)
|
|
|
+ .idNo(no)
|
|
|
+ .certifyId(certifyId)
|
|
|
+ .build());
|
|
|
+ return certifyId;
|
|
|
}
|
|
|
throw new BusinessException(response.getMsg());
|
|
|
}
|
|
|
@@ -1008,4 +1020,69 @@ public class UserService {
|
|
|
}
|
|
|
throw new BusinessException(response.getMsg());
|
|
|
}
|
|
|
+
|
|
|
+ public User oneKeyLogin(String umengKey, String token) {
|
|
|
+ String phone = UmengUtils.getMobile(umengKey, token);
|
|
|
+ if (StringUtils.isBlank(phone)) {
|
|
|
+ throw new BusinessException("登录失败,请尝试其他方式");
|
|
|
+ }
|
|
|
+ User user = userRepo.findByPhoneAndDelFalse(phone).orElse(null);
|
|
|
+ if (user == null) {
|
|
|
+ String name = "0x" + RandomStringUtils.randomAlphabetic(8);
|
|
|
+ user = create(UserRegister.builder()
|
|
|
+ .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
+ .username(name)
|
|
|
+ .nickname(name)
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
+ .phone(phone)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> checkFaceAuth(String certifyId) throws AlipayApiException {
|
|
|
+ AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest();
|
|
|
+ JSONObject biz = new JSONObject();
|
|
|
+ biz.put("certify_id", certifyId);
|
|
|
+ request.setBizContent(biz.toJSONString());
|
|
|
+ AlipayUserCertifyOpenQueryResponse response = alipayClient.execute(request);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ System.out.println("调用成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("调用失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void faceAuthNotify(String certifyId) {
|
|
|
+ try {
|
|
|
+ AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest();
|
|
|
+ JSONObject biz = new JSONObject();
|
|
|
+ biz.put("certify_id", certifyId);
|
|
|
+ request.setBizContent(biz.toJSONString());
|
|
|
+ AlipayUserCertifyOpenQueryResponse response = alipayClient.execute(request);
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
+ if (StringUtils.equals(jsonObject.getString("passed"), "T")) {
|
|
|
+ FaceAuth faceAuth = faceAuthRepo.findByCertifyId(certifyId);
|
|
|
+ if (faceAuth != null) {
|
|
|
+ User user = userRepo.findById(faceAuth.getUserId()).orElse(null);
|
|
|
+ if (user != null) {
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.save(IdentityAuth.builder()
|
|
|
+ .userId(user.getId())
|
|
|
+ .idNo(faceAuth.getIdNo())
|
|
|
+ .realName(faceAuth.getName())
|
|
|
+ .build());
|
|
|
+ user.setAuthStatus(AuthStatus.SUCCESS);
|
|
|
+ user.setAuthId(identityAuth.getId());
|
|
|
+ save(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|