init
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.newyetai.sdk.chuanglan.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 接口链接地址映射
|
||||
* @author fzp on 2021年6月17日09:29:06
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ChuangLanCommonProperties {
|
||||
|
||||
/** 是否启用 **/
|
||||
private Boolean enable = Boolean.FALSE;
|
||||
/** 接口地址 **/
|
||||
private String url;
|
||||
/** 次数限制 **/
|
||||
private Long numLimit;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.newyetai.sdk.chuanglan.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 创蓝配置
|
||||
*
|
||||
* @author sr on 2020-04-09
|
||||
*/
|
||||
@ConfigurationProperties(prefix = ChuangLanProperties.PREFIX)
|
||||
@Data
|
||||
@Component
|
||||
@NoArgsConstructor
|
||||
public class ChuangLanProperties {
|
||||
|
||||
/** 创蓝配置前缀 */
|
||||
public static final String PREFIX = "chuanglan";
|
||||
/** 创蓝三要素配置前缀 */
|
||||
public static final String PHONE_THREE_PREFIX = PREFIX + ".phone3";
|
||||
/** 创蓝三要素配置前缀 */
|
||||
public static final String BANK_CARD_THREE_PREFIX = PREFIX + ".bankCard3";
|
||||
/** 创蓝四要素配置前缀 */
|
||||
public static final String BANK_CARD_FOUR_PREFIX = PREFIX + ".bankCard4";
|
||||
|
||||
/** 创蓝二要素实名认证配置前缀 */
|
||||
public static final String REAL_NAME_TWO_PREFIX = PREFIX + ".realName2";
|
||||
|
||||
/** 创蓝二要素实名认证配置前缀 */
|
||||
public static final String REAL_NAME_TWO_BASE_PREFIX = PREFIX + ".realName2Base";
|
||||
|
||||
/** 是否启用 **/
|
||||
private Boolean enable;
|
||||
/** https://api.253.com */
|
||||
private String domain;
|
||||
|
||||
/** 系统预留手机号 */
|
||||
private String phone;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String appSecret;
|
||||
|
||||
/** 手机号三要素配置 */
|
||||
private ChuangLanCommonProperties phone3;
|
||||
|
||||
/** 银行卡三要素配置 */
|
||||
private ChuangLanCommonProperties bankCard3;
|
||||
|
||||
/** 银行卡四要素配置 */
|
||||
private ChuangLanCommonProperties bankCard4;
|
||||
/** 实名认证二要素配置 */
|
||||
private ChuangLanCommonProperties realName2;
|
||||
|
||||
/** 实名认证二要素配置 (id-card-auth) */
|
||||
private ChuangLanCommonProperties realName2Base;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.newyetai.sdk.chuanglan.constant;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.common.util.JsonUtils;
|
||||
import com.newyetai.sdk.chuanglan.dto.ChuangLanResponseDTO;
|
||||
import com.newyetai.sdk.chuanglan.dto.ChuangLanResultDTO;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author czy
|
||||
* @date 2021-07-05
|
||||
*/
|
||||
|
||||
public enum BankCardVerifyStateEnum {
|
||||
|
||||
/** 认证一致 **/
|
||||
SUC("01", "认证一致", Boolean.TRUE),
|
||||
/** 认证不一致 **/
|
||||
FAIL("02", "认证不一致", Boolean.FALSE),
|
||||
/** 认证不确定 **/
|
||||
UNCERTAIN("03", "认证不确定", null),
|
||||
/** 认证失败 **/
|
||||
EXCEPTION_FAIL("04", "认证失败", null),
|
||||
/** 手机号码不匹配 **/
|
||||
MOBILE_ERROR("05", "手机号码不匹配", Boolean.FALSE),
|
||||
/** 身份证号码不匹配 **/
|
||||
CARD_NO_ERROR("06", "身份证号码不匹配", Boolean.FALSE),
|
||||
/** 姓名不匹配 **/
|
||||
NAME_ERROR("07", "姓名不匹配", Boolean.FALSE);
|
||||
|
||||
private static Map<String, BankCardVerifyStateEnum> stateMap;
|
||||
/** 验证结果 **/
|
||||
private String state;
|
||||
/** 说明 **/
|
||||
private String msg;
|
||||
/** 认证结果 **/
|
||||
private Boolean result;
|
||||
|
||||
|
||||
BankCardVerifyStateEnum(String state, String msg, Boolean result) {
|
||||
this.state = state;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
static {
|
||||
BankCardVerifyStateEnum[] array = BankCardVerifyStateEnum.values();
|
||||
stateMap = Maps.newHashMapWithExpectedSize(array.length);
|
||||
for (BankCardVerifyStateEnum stateEnum : array) {
|
||||
stateMap.put(stateEnum.getState(), stateEnum);
|
||||
}
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Boolean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static AlitaResult<ChuangLanResultDTO> dealState(ChuangLanResponseDTO responseDto) {
|
||||
ChuangLanResultDTO resultDTO = ChuangLanResultDTO.builder()
|
||||
.jsonData(JsonUtils.toJsonString(responseDto)).build();
|
||||
String status = responseDto.getData().getResult();
|
||||
BankCardVerifyStateEnum stateEnum = stateMap.get(status);
|
||||
if (stateEnum == null) {
|
||||
return AlitaResult.success("state not available...", resultDTO);
|
||||
}
|
||||
if (stateEnum == SUC || stateEnum == FAIL || stateEnum == MOBILE_ERROR || stateEnum == CARD_NO_ERROR || stateEnum == NAME_ERROR) {
|
||||
resultDTO.setStatus(stateEnum.getResult());
|
||||
return AlitaResult.success(stateEnum.getMsg(), resultDTO);
|
||||
}
|
||||
return AlitaResult.error(stateEnum.getMsg(), resultDTO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.newyetai.sdk.chuanglan.constant;
|
||||
|
||||
import com.newyetai.sdk.common.constant.SdkConstants;
|
||||
|
||||
/**
|
||||
* @author sr on 2020-04-10
|
||||
*/
|
||||
public interface ChuangLanConstants {
|
||||
|
||||
/** 创蓝接口调用,验证成功码 **/
|
||||
String IMPL_CODE = "01";
|
||||
|
||||
/** 成功码 **/
|
||||
String SUC_CODE = "200000";
|
||||
|
||||
/** ================ chuanglan 调起真实服务前异常msg ================= **/
|
||||
String PROPERTIES_NOT_SET = SdkConstants.CL_CODE + ":配置文件未配置";
|
||||
String ID_SECRET_NOT_ENOUGH = SdkConstants.CL_CODE + ":参数appId或appSecret缺失";
|
||||
/** ================ chuanglanW 调起真实服务前异常msq ================= **/
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.newyetai.sdk.chuanglan.constant;
|
||||
|
||||
/**
|
||||
* sdk创蓝错误码枚举;标识:创蓝(01)
|
||||
* @author sr on 2020-05-22
|
||||
*/
|
||||
public enum ChuangLanErrorCodeEnum {
|
||||
|
||||
/** 创蓝调用返回错误码 **/
|
||||
INVOKE_RETURN_ERROR("060101", "创蓝接口调用失败,返回错误码"),
|
||||
/** 创蓝调用成功,但信息不匹配 **/
|
||||
NOT_EQUAL("060102", "不匹配");
|
||||
|
||||
/** 错误码 **/
|
||||
private String code;
|
||||
/** 错误信息 **/
|
||||
private String msg;
|
||||
|
||||
ChuangLanErrorCodeEnum(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 银行卡四要素请求
|
||||
*
|
||||
* @author fzp 2021年6月15日15:11:31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BankCardFourRequestDTO extends ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 3807618123977056991L;
|
||||
|
||||
/** 姓名 **/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 **/
|
||||
@NotBlank(message = "身份证号不能为空")
|
||||
private String idNum;
|
||||
/** 银行卡号 **/
|
||||
@NotBlank(message = "银行卡号不能为空")
|
||||
private String cardNo;
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
private String mobile;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 银行卡三要素请求
|
||||
*
|
||||
* @author sr on 2020-04-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BankCardThreeRequestDTO extends ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = -6539738426193243916L;
|
||||
|
||||
/** 姓名 **/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 **/
|
||||
@NotBlank(message = "身份证号不能为空")
|
||||
private String idNum;
|
||||
/** 银行卡号 **/
|
||||
@NotBlank(message = "银行卡号不能为空")
|
||||
private String cardNo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 创蓝请求父类dto
|
||||
*
|
||||
* @author fzp on 2021年6月15日16:39:50
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3960499271644654446L;
|
||||
/**
|
||||
* id
|
||||
**/
|
||||
private String appId;
|
||||
/**
|
||||
* secret
|
||||
**/
|
||||
private String appKey;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.sdk.fangxinqian.constant.FxqConstants;
|
||||
import com.newyetai.sdk.fangxinqian.constant.FxqErrorCodeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 创蓝返回
|
||||
*
|
||||
* @param <T>
|
||||
* @author fzp on 2021年6月15日14:55:38
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ChuangLanResponseDTO<T> implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
private static final long serialVersionUID = -4576000729533850612L;
|
||||
/**
|
||||
* 错误码
|
||||
**/
|
||||
private String code;
|
||||
/**
|
||||
* 序列号(每次调用接口返回的唯一值,seqNo 如有接口问题,请提供此值)
|
||||
**/
|
||||
private String seqNo;
|
||||
/**
|
||||
* 错误信息 1
|
||||
**/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 错误信息 2
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 响应结果
|
||||
*/
|
||||
private StatusDataDTO data;
|
||||
|
||||
|
||||
public static ChuangLanResponseDTO buildCommonError() {
|
||||
ChuangLanResponseDTO clResponseDTO = new ChuangLanResponseDTO();
|
||||
clResponseDTO.setCode("999");
|
||||
return clResponseDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回结果处理
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AlitaResult<T> handleResult() {
|
||||
if (FxqConstants.SUC_CODE.equals(this.getCode())) {
|
||||
return AlitaResult.success(handleData());
|
||||
} else {
|
||||
return AlitaResult.error(FxqErrorCodeEnum.INVOKE_RETURN_ERROR.getCode(),
|
||||
StringUtils.isEmpty(this.getMsg()) ?
|
||||
StringUtils.isEmpty(this.getMessage()) ? FxqErrorCodeEnum.INVOKE_RETURN_ERROR.getMsg() : this.getMessage()
|
||||
: this.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类DTO实现 转换为AlitaResult时
|
||||
* 通过 handleData()决定转换为AlitaResult的data返回什么
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected T handleData() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author czy
|
||||
* @date 2021-07-05
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChuangLanResultDTO {
|
||||
|
||||
private Boolean status;
|
||||
|
||||
private String jsonData;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 手机号三要素请求
|
||||
*
|
||||
* @author sr on 2020-04-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class PhoneThreeRequestDTO extends ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = -6539738426193243916L;
|
||||
|
||||
/** 姓名 **/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 **/
|
||||
@NotBlank(message = "身份证号不能为空")
|
||||
private String idNum;
|
||||
/** 银行卡号 **/
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
private String mobile;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实名认证(基础)
|
||||
*
|
||||
* @author fzp 2021年6月15日15:11:31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class RealNameTwoBaseRequestDTO extends ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3985001434329229012L;
|
||||
|
||||
/** 姓名 **/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 **/
|
||||
@NotBlank(message = "身份证号不能为空")
|
||||
private String idNum;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实名认证
|
||||
*
|
||||
* @author fzp 2021年6月15日15:11:31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class RealNameTwoRequestDTO extends ChuangLanRequestDTO implements Serializable {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 3807618123977056991L;
|
||||
|
||||
/** 姓名 **/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 **/
|
||||
@NotBlank(message = "身份证号不能为空")
|
||||
private String idNum;
|
||||
|
||||
/** 身份证有效开始日期 **/
|
||||
@NotBlank(message = "startTime")
|
||||
private String startTime;
|
||||
|
||||
/** 身份证有效结束日期 **/
|
||||
@NotBlank(message = "startTime")
|
||||
private String endTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.newyetai.sdk.chuanglan.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author czy
|
||||
* @date 2021-07-05
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class StatusDataDTO {
|
||||
|
||||
@ApiModelProperty("业务唯一流水号")
|
||||
private String orderNo;
|
||||
|
||||
@ApiModelProperty("查询时间")
|
||||
private String handleTime;
|
||||
|
||||
@ApiModelProperty("认证结果代码")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("银行卡所属银行")
|
||||
private String bankName;
|
||||
|
||||
@ApiModelProperty("银行卡类型")
|
||||
private String cardType;
|
||||
|
||||
@ApiModelProperty("银行卡类型")
|
||||
private String cardCategory;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.newyetai.sdk.chuanglan.service;
|
||||
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.sdk.chuanglan.dto.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
/**
|
||||
* 创蓝
|
||||
*
|
||||
* @author sr on 2020-04-09
|
||||
*/
|
||||
@Validated(Default.class)
|
||||
public interface ChuangLanService {
|
||||
|
||||
String BEAN_ID = "sdk.chuangLanService";
|
||||
String MOCK_BEAN_ID = "mock.chuangLanService";
|
||||
|
||||
/**
|
||||
* 二要素(基础)
|
||||
*
|
||||
* @param requestDTO 请求dto
|
||||
* @return {@link AlitaResult}<{@link ChuangLanResultDTO}>
|
||||
*/
|
||||
AlitaResult<ChuangLanResultDTO> checkRealNameTwoBase(RealNameTwoBaseRequestDTO requestDTO);
|
||||
|
||||
/**
|
||||
* 手机三要素
|
||||
*
|
||||
* @param phoneThreeRequestDTO 电话请求dto
|
||||
* @return {@link AlitaResult}<{@link ChuangLanResultDTO}>
|
||||
*/
|
||||
AlitaResult<ChuangLanResultDTO> checkPhoneThree(
|
||||
@NotNull @Valid PhoneThreeRequestDTO phoneThreeRequestDTO);
|
||||
|
||||
/**
|
||||
* 银行卡三要素
|
||||
*
|
||||
* @param bankCardThreeRequestDto
|
||||
* @return success-false真实调用第三方未成功,未拿到返回值;
|
||||
* success-true获取到第三方返回,data-true校验成功,data-false校验不一致并返回失败原因(msg)
|
||||
* @author sr on 2020-04-10
|
||||
*/
|
||||
AlitaResult<ChuangLanResultDTO> checkBankCardThree(
|
||||
@NotNull @Valid BankCardThreeRequestDTO bankCardThreeRequestDto);
|
||||
|
||||
/**
|
||||
* 银行卡四要素
|
||||
*
|
||||
* @param bankCardFourRequestDto
|
||||
* @return success-false真实调用第三方未成功,未拿到返回值;
|
||||
* success-true获取到第三方返回,data-true校验成功,data-false校验不一致并返回失败原因(msg)
|
||||
* @author sr on 2020-05-22
|
||||
*/
|
||||
AlitaResult<ChuangLanResultDTO> checkBankCardFour(
|
||||
@NotNull @Valid BankCardFourRequestDTO bankCardFourRequestDto);
|
||||
|
||||
/**
|
||||
* 二要素--实名认证
|
||||
*
|
||||
* @param realNameTwoRequestDTO
|
||||
* @return success-false真实调用第三方未成功,未拿到返回值;
|
||||
* success-true获取到第三方返回,data-true校验成功,data-false校验不一致并返回失败原因(msg)
|
||||
* @author sr on 2020-05-22
|
||||
*/
|
||||
AlitaResult<ChuangLanResultDTO> realNameTwoAuthentication(
|
||||
@NotNull @Valid RealNameTwoRequestDTO realNameTwoRequestDTO);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.newyetai.sdk.chuanglan.service.impl;
|
||||
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.common.annotation.CheckAndMock;
|
||||
import com.newyetai.common.exception.util.Assert;
|
||||
import com.newyetai.sdk.chuanglan.config.ChuangLanCommonProperties;
|
||||
import com.newyetai.sdk.chuanglan.config.ChuangLanProperties;
|
||||
import com.newyetai.sdk.chuanglan.constant.BankCardVerifyStateEnum;
|
||||
import com.newyetai.sdk.chuanglan.constant.ChuangLanConstants;
|
||||
import com.newyetai.sdk.chuanglan.dto.*;
|
||||
import com.newyetai.sdk.chuanglan.service.ChuangLanService;
|
||||
import com.newyetai.sdk.chuanglan.util.ChuangLanUtils;
|
||||
import com.newyetai.sdk.chuanglan.util.HttpUtilCl;
|
||||
import com.newyetai.sdk.common.constant.SdkConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author fzp on 2021年6月15日16:46:26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service(ChuangLanService.BEAN_ID)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class ChuangLanServiceImpl implements ChuangLanService {
|
||||
|
||||
private final ChuangLanProperties chuangLanProperties;
|
||||
|
||||
@Override
|
||||
@CheckAndMock(mockClass = MockChuangLanServiceImpl.class,
|
||||
propertyPrefix = ChuangLanProperties.REAL_NAME_TWO_BASE_PREFIX)
|
||||
public AlitaResult<ChuangLanResultDTO> checkRealNameTwoBase(RealNameTwoBaseRequestDTO requestDTO) {
|
||||
return this.check(requestDTO, chuangLanProperties.getRealName2Base());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CheckAndMock(mockClass = MockChuangLanServiceImpl.class,
|
||||
propertyPrefix = ChuangLanProperties.PHONE_THREE_PREFIX)
|
||||
public AlitaResult<ChuangLanResultDTO> checkPhoneThree(PhoneThreeRequestDTO requestDTO) {
|
||||
return this.check(requestDTO, chuangLanProperties.getPhone3());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CheckAndMock(mockClass = MockChuangLanServiceImpl.class,
|
||||
propertyPrefix = ChuangLanProperties.BANK_CARD_THREE_PREFIX)
|
||||
public AlitaResult<ChuangLanResultDTO> checkBankCardThree(BankCardThreeRequestDTO bankCardThreeRequestDto) {
|
||||
return this.check(bankCardThreeRequestDto, chuangLanProperties.getBankCard3());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CheckAndMock(mockClass = MockChuangLanServiceImpl.class,
|
||||
propertyPrefix = ChuangLanProperties.BANK_CARD_FOUR_PREFIX)
|
||||
public AlitaResult<ChuangLanResultDTO> checkBankCardFour(BankCardFourRequestDTO bankCardFourRequestDto) {
|
||||
return this.check(bankCardFourRequestDto, chuangLanProperties.getBankCard4());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CheckAndMock(mockClass = MockChuangLanServiceImpl.class,
|
||||
propertyPrefix = ChuangLanProperties.REAL_NAME_TWO_PREFIX)
|
||||
public AlitaResult<ChuangLanResultDTO> realNameTwoAuthentication(RealNameTwoRequestDTO realNameTwoRequestDTO){
|
||||
return this.check(realNameTwoRequestDTO, chuangLanProperties.getRealName2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 父类dto 添加请求父类,可以指定appId,appSecret调用接口
|
||||
* @param requestDto
|
||||
* @param commonProperties
|
||||
* @return
|
||||
*/
|
||||
private AlitaResult<ChuangLanResultDTO> check(ChuangLanRequestDTO requestDto, ChuangLanCommonProperties commonProperties) {
|
||||
// 校验部分
|
||||
if (commonProperties == null || chuangLanProperties == null) {
|
||||
return AlitaResult.error(SdkConstants.SDK_INVOKE_NOT_REACH_CODE,
|
||||
ChuangLanConstants.PROPERTIES_NOT_SET);
|
||||
}
|
||||
if (!Boolean.TRUE.equals(chuangLanProperties.getEnable())) {
|
||||
return AlitaResult.error(SdkConstants.SDK_INVOKE_NOT_REACH_CODE,
|
||||
"暂不支持要素认证");
|
||||
}
|
||||
if (!ChuangLanUtils.dealAppIdAndSecret(commonProperties, requestDto, chuangLanProperties)) {
|
||||
return AlitaResult.error(SdkConstants.SDK_INVOKE_NOT_REACH_CODE,
|
||||
ChuangLanConstants.ID_SECRET_NOT_ENOUGH);
|
||||
}
|
||||
// 执行
|
||||
ChuangLanResponseDTO responseDto = HttpUtilCl.execute(chuangLanProperties.getDomain().concat(commonProperties.getUrl()), requestDto);
|
||||
|
||||
// 返回结果校验
|
||||
if (!ChuangLanConstants.SUC_CODE.equals(responseDto.getCode())) {
|
||||
// 返回结果验证错误
|
||||
return AlitaResult.error(SdkConstants.SDK_HTTP_INVOKE_RESPONSE_FAIL_CODE, responseDto.getMessage() );
|
||||
}
|
||||
|
||||
return BankCardVerifyStateEnum.dealState(responseDto);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.newyetai.sdk.chuanglan.service.impl;
|
||||
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.sdk.chuanglan.config.ChuangLanProperties;
|
||||
import com.newyetai.sdk.chuanglan.dto.*;
|
||||
import com.newyetai.sdk.chuanglan.service.ChuangLanService;
|
||||
import com.newyetai.sdk.common.constant.SdkConstants;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author sr on 2020-04-09
|
||||
*/
|
||||
@Service(ChuangLanService.MOCK_BEAN_ID)
|
||||
@Slf4j
|
||||
public class MockChuangLanServiceImpl implements ChuangLanService {
|
||||
|
||||
private final static ChuangLanResultDTO result =
|
||||
ChuangLanResultDTO.builder().status(Boolean.TRUE).build();
|
||||
|
||||
@Autowired
|
||||
private ChuangLanProperties chuangLanProperties;
|
||||
|
||||
private AlitaResult<ChuangLanResultDTO> check() {
|
||||
// 校验部分
|
||||
if (chuangLanProperties == null || !Boolean.TRUE.equals(chuangLanProperties.getEnable())) {
|
||||
return AlitaResult.error(SdkConstants.SDK_INVOKE_NOT_REACH_CODE,
|
||||
"暂不支持要素认证");
|
||||
}
|
||||
return AlitaResult.success(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlitaResult<ChuangLanResultDTO> checkRealNameTwoBase(
|
||||
RealNameTwoBaseRequestDTO requestDTO) {
|
||||
log.info("chuanglan checkRealNameTwoBase mock...");
|
||||
return check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlitaResult<ChuangLanResultDTO> checkPhoneThree(
|
||||
PhoneThreeRequestDTO phoneThreeRequestDTO) {
|
||||
log.info("chuanglan checkPhoneThree mock...");
|
||||
return check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlitaResult<ChuangLanResultDTO> checkBankCardThree(
|
||||
@NotNull @Valid BankCardThreeRequestDTO bankCardThreeRequestDto) {
|
||||
log.info("chuanglan checkBankCardThree mock...");
|
||||
return check();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AlitaResult<ChuangLanResultDTO> checkBankCardFour(
|
||||
@NotNull @Valid BankCardFourRequestDTO bankCardFourRequestDto) {
|
||||
log.info("chuanglan checkBankCardFour mock...");
|
||||
return check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlitaResult<ChuangLanResultDTO> realNameTwoAuthentication(
|
||||
RealNameTwoRequestDTO realNameTwoRequestDTO) {
|
||||
log.info("chuanglan checkRealNameTwo mock...");
|
||||
return check();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.newyetai.sdk.chuanglan.util;
|
||||
|
||||
import com.newyetai.sdk.chuanglan.config.ChuangLanCommonProperties;
|
||||
import com.newyetai.sdk.chuanglan.config.ChuangLanProperties;
|
||||
import com.newyetai.sdk.chuanglan.dto.ChuangLanRequestDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*
|
||||
* @author fzp on 2021年6月15日14:22:18
|
||||
*/
|
||||
public final class ChuangLanUtils {
|
||||
|
||||
/**
|
||||
* 私有
|
||||
*/
|
||||
private ChuangLanUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理appId和appSecret参数
|
||||
*
|
||||
* @param <T>
|
||||
* @param commonProperties
|
||||
* @param requestDto
|
||||
* @author fzp on 2021年6月15日16:20:49
|
||||
*/
|
||||
public static <T extends ChuangLanRequestDTO> boolean dealAppIdAndSecret(ChuangLanCommonProperties commonProperties,
|
||||
T requestDto, ChuangLanProperties chuangLanProperties) {
|
||||
|
||||
String appId = requestDto.getAppId();
|
||||
String appKey = requestDto.getAppKey();
|
||||
|
||||
// 如果appId为空,则从nacos配置文件读取
|
||||
if (StringUtils.isBlank(appId) && commonProperties.getEnable()) {
|
||||
appId = chuangLanProperties.getAppId();
|
||||
}
|
||||
if (StringUtils.isBlank(appKey) && commonProperties.getEnable()) {
|
||||
appKey = chuangLanProperties.getAppSecret();
|
||||
}
|
||||
if (StringUtils.isBlank(appId) || StringUtils.isBlank(appKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
requestDto.setAppId(appId);
|
||||
requestDto.setAppKey(appKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.newyetai.sdk.chuanglan.util;
|
||||
|
||||
import com.newyetai.common.util.JsonUtils;
|
||||
import com.newyetai.sdk.chuanglan.constant.ChuangLanConstants;
|
||||
import com.newyetai.sdk.chuanglan.dto.ChuangLanResponseDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HttpUtilCl<T, R> {
|
||||
|
||||
private static RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
public HttpUtilCl() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Http 通用请求封装
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param requestDto 请求实体
|
||||
* @param <T>
|
||||
* @param <R>
|
||||
* @return
|
||||
*/
|
||||
public static <T, R extends ChuangLanResponseDTO> ChuangLanResponseDTO execute(String url, T requestDto) {
|
||||
ChuangLanResponseDTO result;
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
try {
|
||||
String reqJson = JsonUtils.toJsonString(requestDto);
|
||||
log.info("chuanglan request url :{}", url);
|
||||
log.info("chuanglan request requestDto :{}", reqJson);
|
||||
|
||||
MultiValueMap requestBody = new LinkedMultiValueMap();
|
||||
Map paramMap = JsonUtils.toMap(reqJson);
|
||||
paramMap.forEach((k,v) -> {
|
||||
if(Objects.nonNull(v)){
|
||||
requestBody.add(k,v);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
HttpEntity request = new HttpEntity(requestBody, headers);
|
||||
String response = restTemplate.postForObject(url, request, String.class);
|
||||
log.info("chuanglan 响应结果 :{}", response);
|
||||
|
||||
result = formatDto(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("chuanglan {} invoke error:{}", requestDto.getClass().getName(), e);
|
||||
stopWatch.stop();
|
||||
return ChuangLanResponseDTO.buildCommonError();
|
||||
}
|
||||
stopWatch.stop();
|
||||
log.info("chuanglan consuming {} s", stopWatch.getTotalTimeSeconds());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ChuangLanResponseDTO formatDto(String json){
|
||||
if(StringUtils.isBlank(json)){
|
||||
return ChuangLanResponseDTO.buildCommonError();
|
||||
}
|
||||
ChuangLanResponseDTO result = JsonUtils.toObject(json,ChuangLanResponseDTO.class);
|
||||
Map<String,Object> map = JsonUtils.toMap(json);
|
||||
if(map.get("data") != null){
|
||||
LinkedHashMap data = (LinkedHashMap) map.get("data");
|
||||
// 创蓝接口验证失败
|
||||
if(!ChuangLanConstants.IMPL_CODE.equals(data.get("result"))){
|
||||
result.setMsg(data.get("remark") + "");
|
||||
result.setMessage(data.get("remark") + "");
|
||||
// result.setCode(data.get("result") + "");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user