临时提交

This commit is contained in:
墨大叔 2024-09-20 16:42:12 +08:00
parent 87b2bd73e7
commit 5441c04743
13 changed files with 291 additions and 11 deletions

View File

@ -92,4 +92,13 @@ public class HttpStatus
*/
public static final int WARN = 601;
/**
* 未实名
*/
public static final int NO_REAL_NAME = 10001;
/**
* 限制提现
*/
public static final int LIMIT_WITHDRAW = 10002;
}

View File

@ -0,0 +1,49 @@
package com.ruoyi.common.valid.face;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author wjh
* 2024/9/20
*/
@Data
public class FaceResponseData {
@JSONField(name = "order_no")
private String orderNo;
//score 比较结果分值0-1之间的小数参考指标0.40以下系统判断为不同人0.40-0.45不能确定是否为同一人0.45以上系统判断为同一人
private BigDecimal score;
private String msg;
/**
* incorrect详解
* 1编号说明
* 100 比对成功还要根据score的值来判断是否同一人
* 101 身份证号码姓名不一致
* 102 库中无此号
* 103 身份核验成功数据非法公安已经进行了身份核验姓名身份证号码一致公安返回的错误: 除库中无照片109特征提取失败110检测到多于一张人脸(111)人脸识别系统异常(106)图片不合法(112)以外的情况
* 104 数据非法公安未进行身份核验前图片校验公安返回的错误: 除照片质量不合格(107)上传图片文件过大(108)人像比对服务异常(113)以外的情况
* 106 身份核验成功人脸识别系统异常
* 107 照片质量不合格
* 108 上传图片文件过大
* 109 身份核验成功库中无照片
* 110 身份核验成功特征提取失败
* 111 身份核验成功检测到多于一张人脸
* 112 身份核验成功图片不合法
* 113 人像比对服务异常
* 103 身份核验成功数据非法
*
* 2103104区别
* 103证件号码一致照片比对时报错104未进行证件号校验数据检验报错
*
* 3104107区别
* 107检测到的公安错误104未检测到的公安错误
*/
private Integer incorrect;
}

View File

@ -0,0 +1,55 @@
package com.ruoyi.common.valid.face;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.http.AliHttpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.valid.liveness.LivenessResponseBody;
import com.ruoyi.common.valid.liveness.LivenessResponseTokenData;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author wjh
* 2024/9/20
*/
public class FaceUtils {
public static final String APP_KEY = SpringUtils.getRequiredProperty("face.appKey");
public static final String APP_CODE = SpringUtils.getRequiredProperty("face.appCode");
public static final String APP_SECRET = SpringUtils.getRequiredProperty("face.appSecret");
/**
* 获取活体检测token
* @param returnUrl 前端跳转地址
* @param colorLiveParam 自定义颜色逗号分隔
* @param actionLiveParam 自定义动作逗号分隔
*/
public static LivenessResponseTokenData getToken(String returnUrl, String colorLiveParam, String actionLiveParam) {
String host = "https://smkjhtjc.market.alicloudapi.com";
String path = "/liveness/h5/token";
String method = "GET";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + APP_CODE);
Map<String, String> querys = new HashMap<String, String>();
querys.put("returnUrl", returnUrl);
querys.put("colorLiveParam", colorLiveParam);
querys.put("actionLiveParam", actionLiveParam);
try {
HttpResponse res = AliHttpUtils.doGet(host, path, method, headers, querys);
LivenessResponseBody<LivenessResponseTokenData> body = JSON.parseObject(EntityUtils.toString(res.getEntity()), LivenessResponseBody.class);
ServiceUtil.assertion(body.getCode() == null || !body.getCode().equals("200"), body.getMsg());
return body.getData();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,17 @@
package com.ruoyi.common.valid.liveness;
import lombok.Data;
/**
* @author wjh
* 2024/9/20
*/
@Data
public class LivenessResponseBody<T> {
private String msg;
private Boolean success;
private String code;
private T data;
}

View File

@ -0,0 +1,21 @@
package com.ruoyi.common.valid.liveness;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;
/**
* @author wjh
* 2024/9/20
*/
@Data
public class LivenessResponseQueryData {
@JSONField(name = "order_no")
private String orderNo;
private String token;
private Integer result; //0通过;1不通过2未找到活体检测结果
private String faceImage;
}

View File

@ -0,0 +1,14 @@
package com.ruoyi.common.valid.liveness;
import lombok.Data;
/**
* @author wjh
* 2024/9/20
*/
@Data
public class LivenessResponseTokenData {
private String token;
}

View File

@ -0,0 +1,79 @@
package com.ruoyi.common.valid.liveness;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.http.AliHttpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
/**
* 活体检测
* https://market.aliyun.com/apimarket/detail/cmapi00064393?spm=5176.730005.result.10.2271414a01R1ZI#sku=yuncode5839300001
* @author wjh
* 2024/9/20
*/
public class LivenessUtils {
public static final String APP_KEY = SpringUtils.getRequiredProperty("liveness.appKey");
public static final String APP_CODE = SpringUtils.getRequiredProperty("liveness.appCode");
public static final String APP_SECRET = SpringUtils.getRequiredProperty("liveness.appSecret");
/**
* 获取活体检测token
* @param returnUrl 前端跳转地址
* @param colorLiveParam 自定义颜色逗号分隔
* @param actionLiveParam 自定义动作逗号分隔
*/
public static LivenessResponseTokenData getToken(String returnUrl, String colorLiveParam, String actionLiveParam) {
String host = "https://smkjhtjc.market.alicloudapi.com";
String path = "/liveness/h5/token";
String method = "GET";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + APP_CODE);
Map<String, String> querys = new HashMap<String, String>();
querys.put("returnUrl", returnUrl);
querys.put("colorLiveParam", colorLiveParam);
querys.put("actionLiveParam", actionLiveParam);
try {
HttpResponse res = AliHttpUtils.doGet(host, path, method, headers, querys);
LivenessResponseBody<LivenessResponseTokenData> body = JSON.parseObject(EntityUtils.toString(res.getEntity()), LivenessResponseBody.class);
ServiceUtil.assertion(body.getCode() == null || !body.getCode().equals("200"), body.getMsg());
return body.getData();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 查询活体检测结果
*/
public static LivenessResponseQueryData queryResult(String token) {
String host = "https://smkjhtjc.market.alicloudapi.com";
String path = "/liveness/h5/result";
String method = "GET";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + APP_CODE);
Map<String, String> querys = new HashMap<String, String>();
querys.put("token", token);
try {
HttpResponse res = AliHttpUtils.doGet(host, path, method, headers, querys);
LivenessResponseBody<LivenessResponseQueryData> body = JSON.parseObject(EntityUtils.toString(res.getEntity()), LivenessResponseBody.class);
ServiceUtil.assertion(body.getCode() == null || !body.getCode().equals("200"), body.getMsg());
return body.getData();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -2,8 +2,10 @@ package com.ruoyi.ss.transactionBill.service.impl;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.enums.BusinessStatus;
import com.ruoyi.common.enums.WithdrawServiceType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.*;
@ -413,8 +415,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
AccountVO account = bo.getAccount();
ServiceUtil.assertion(user == null, "用户不存在");
ServiceUtil.assertion(user.getIsReal() == null || !user.getIsReal(), "用户未实名认证,无法提现");
ServiceUtil.assertion(user.getLimitWithdraw() != null && user.getLimitWithdraw(), "您被限制提现:" + user.getLimitWithdrawReason());
ServiceUtil.assertion(user.getIsReal() == null || !user.getIsReal(), "用户未实名认证,无法提现", HttpStatus.NO_REAL_NAME);
ServiceUtil.assertion(user.getLimitWithdraw() != null && user.getLimitWithdraw(), "您被限制提现:" + user.getLimitWithdrawReason(), HttpStatus.LIMIT_WITHDRAW);
// 判断今天提现成功和正在审核中的提现是否超过限额
String dailyLimitStr = sysConfigService.selectConfigByKey(ConfigKey.DAILY_WITHDRAW_AMOUNT.getKey());

View File

@ -34,4 +34,6 @@ public class UserRealNameDTO {
@Pattern(regexp = RegexpUtils.MOBILE_PHONE_REGEXP, message = "手机号格式错误")
private String realPhone;
private String faceReturnUrl;
}

View File

@ -0,0 +1,16 @@
package com.ruoyi.ss.user.domain.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author wjh
* 2024/9/20
*/
@Data
public class UserRealNameVO {
@ApiModelProperty("人脸识别token")
private String faceToken;
}

View File

@ -6,6 +6,7 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.common.valid.liveness.LivenessUtils;
import com.ruoyi.common.valid.realName.RealNameValidUtils;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
@ -287,14 +288,19 @@ public class SmUserServiceImpl implements ISmUserService
boolean check = RealNameValidUtils.validMobile3Info(dto.getRealIdCard(), dto.getRealPhone(), dto.getRealName());
ServiceUtil.assertion(!check, "请输入正确的身份信息:姓名、身份证、手机号需要一致");
// 获取活体检测token
LivenessUtils.getToken(dto.getFaceReturnUrl(), );
// TODO 存入缓存
// 修改实名信息
SmUser data = new SmUserQuery();
data.setUserId(dto.getUserId());
data.setRealName(dto.getRealName());
data.setRealIdCard(dto.getRealIdCard());
data.setRealPhone(dto.getRealPhone());
data.setIsReal(true);
return smUserMapper.updateSmUser(data);
// SmUser data = new SmUserQuery();
// data.setUserId(dto.getUserId());
// data.setRealName(dto.getRealName());
// data.setRealIdCard(dto.getRealIdCard());
// data.setRealPhone(dto.getRealPhone());
// data.setIsReal(true);
// return smUserMapper.updateSmUser(data);
}
@Override

View File

@ -72,7 +72,7 @@ public class AppUserController extends BaseController {
@PutMapping("/realName")
public AjaxResult realName(@RequestBody @Validated UserRealNameDTO dto) {
dto.setUserId(getUserId());
return toAjax(userService.realName(dto));
return success(userService.realName(dto));
}
@ApiOperation("标记用户已读商户协议")

View File

@ -53,6 +53,17 @@ realName:
appKey: 204590328
appCode: 32b6c6445b1a42ed862dd4202392c47d
appSecret: td0vIGZRy9GxIrpfnIrxSXFXVW34JxDh
# 活体检测
liveness:
appKey: 204590328
appCode: 32b6c6445b1a42ed862dd4202392c47d
appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh
# 人像比对
face:
appKey: 204590328
appCode: 32b6c6445b1a42ed862dd4202392c47d
appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh
# 项目相关配置
ruoyi:
@ -151,7 +162,6 @@ lock:
# 重试次数
retry: 3
org:
quartz:
jobStore: