身份证二要素

This commit is contained in:
Yifei Kuang 2024-11-18 13:41:57 +08:00
parent 94277bce22
commit 482e2225f1
13 changed files with 223 additions and 24 deletions

View File

@ -23,6 +23,31 @@
<version>1.0.3</version>
</dependency>
<!-- 阿里云api-SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dytnsapi20200217</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-openapi</artifactId>
<version>0.3.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-console</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-util</artifactId>
<version>0.2.23</version>
</dependency>
<!-- SpringBoot集成thymeleaf模板 -->
<dependency>

View File

@ -166,6 +166,7 @@ public class OrderController extends BaseController {
return AjaxResult.success(orderGoodsList);
} catch (Exception e) {
e.printStackTrace();
logger.error("派单失败:" + ExceptionUtils.getMessage(e));
return AjaxResult.error(e.getMessage());
}
}

View File

@ -1360,11 +1360,17 @@ public class OrderMasterController extends BaseController {
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated OrderMaster orderMaster) throws BaseAdaPayException {
if (UserConstants.ORDER_CODE_NOT_UNIQUE.equals(orderMasterService.checkOrderMasterCodeUnique(orderMaster))) {
return error("修改主订单'" + orderMaster.getCode() + "'失败,主订单编码已存在");
try {
if (UserConstants.ORDER_CODE_NOT_UNIQUE.equals(orderMasterService.checkOrderMasterCodeUnique(orderMaster))) {
return error("修改主订单'" + orderMaster.getCode() + "'失败,主订单编码已存在");
}
orderMaster.setUpdateBy(getLoginName());
return toAjax(orderMasterService.updateOrderMaster(orderMaster));
}catch (Exception e){
e.printStackTrace();
logger.error("修改订单信息失败:" + e.getMessage());
return AjaxResult.error();
}
orderMaster.setUpdateBy(getLoginName());
return toAjax(orderMasterService.updateOrderMaster(orderMaster));
}
/**
@ -1384,13 +1390,14 @@ public class OrderMasterController extends BaseController {
});
}
// 下单
if(OrderStatus.PLAIN.code() == orderMaster.getOrderStatus()){
if(orderMaster.getOrderStatus() != null && OrderStatus.PLAIN.code() == orderMaster.getOrderStatus()){
OrderMaster model = orderMasterService.selectById(orderMaster.getId());
insuranceService.orderInsurance(model.getCode());
}
return AjaxResult.success("");
} catch (Exception e) {
e.printStackTrace();
logger.error("派单失败:" + ExceptionUtils.getMessage(e));
return AjaxResult.error(e.getMessage());
}
}
@ -1411,7 +1418,8 @@ public class OrderMasterController extends BaseController {
customerAddressService.updateCustomerAddress(address2Update);
return AjaxResult.success();
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
e.printStackTrace();
logger.error("修改服务时间失败:" + ExceptionUtils.getStackTrace(e));
return AjaxResult.error("修改失败");
}
}

View File

@ -0,0 +1,52 @@
package com.ghy.web.controller.tool;
import cn.hutool.json.JSONUtil;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.StringUtils;
import com.ghy.web.pojo.vo.CertNoTwoElementReq;
import com.ghy.web.service.AliCloudService;
import com.ghy.worker.domain.Worker;
import com.ghy.worker.service.WorkerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@Tag(name = "阿里云Api接口")
@Controller
@RequestMapping("/tool/ali")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AliCloudController {
private final AliCloudService aliCloudService;
private final WorkerService workerService;
@Operation(summary = "身份证二要素校验")
@PostMapping("/certNoTwoElementVerification")
@ResponseBody
public AjaxResult certNoTwoElementVerification(@RequestBody CertNoTwoElementReq certNoTwoElementReq){
try {
Worker worker = workerService.selectById(certNoTwoElementReq.getWorkerId());
if(StringUtils.isNotEmpty(worker.getRemark())){
return AjaxResult.success("操作成功!");
}else {
aliCloudService.certNoTwoElementVerification(certNoTwoElementReq);
worker.setRemark(JSONUtil.toJsonStr(certNoTwoElementReq));
workerService.updateWorker(worker);
return AjaxResult.success();
}
}catch (Exception e){
log.error("身份证二要素校验失败:{}", e.getMessage(), e);
return AjaxResult.success(e.getMessage(), "身份证二要素校验失败!");
}
}
}

View File

@ -0,0 +1,38 @@
package com.ghy.web.core.config;
import com.aliyun.dytnsapi20200217.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
public class AliApiConfig {
@Value("${aliyun.accessKey}")
private String accessKey;
@Value("${aliyun.accessSecret}")
private String accessSecret;
@Value("${aliyun.endpoint}")
private String endpoint;
@Value("${aliyun.authCode}")
private String authCode;
@Bean
public Client createClient() throws Exception {
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html
Config config = new Config()
// 必填请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID
.setAccessKeyId(accessKey)
// 必填请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET
.setAccessKeySecret(accessSecret)
.setEndpoint(endpoint);
return new Client(config);
}
}

View File

@ -0,0 +1,14 @@
package com.ghy.web.pojo.vo;
import lombok.Data;
@Data
public class CertNoTwoElementReq {
private Long workerId;
private String certNo;
private String certName;
}

View File

@ -0,0 +1,14 @@
package com.ghy.web.service;
import com.ghy.web.pojo.vo.CertNoTwoElementReq;
import org.springframework.web.bind.annotation.RequestBody;
/**
* <p>阿里云api合集,二次包装在服务内</p>
* @author clunt
*/
public interface AliCloudService {
void certNoTwoElementVerification(@RequestBody CertNoTwoElementReq certNoTwoElementReq) throws Exception;
}

View File

@ -0,0 +1,38 @@
package com.ghy.web.service.impl;
import cn.hutool.core.lang.Assert;
import cn.hutool.json.JSONUtil;
import com.aliyun.dytnsapi20200217.Client;
import com.aliyun.dytnsapi20200217.models.CertNoTwoElementVerificationRequest;
import com.aliyun.dytnsapi20200217.models.CertNoTwoElementVerificationResponse;
import com.ghy.web.core.config.AliApiConfig;
import com.ghy.web.pojo.vo.CertNoTwoElementReq;
import com.ghy.web.service.AliCloudService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AliCloudServiceImpl implements AliCloudService {
private final AliApiConfig aliApiConfig;
@Override
public void certNoTwoElementVerification(CertNoTwoElementReq certNoTwoElementReq) throws Exception{
// 校验是否是历史记录
Client client = aliApiConfig.createClient();
CertNoTwoElementVerificationRequest request = new CertNoTwoElementVerificationRequest();
request.setAuthCode(aliApiConfig.getAuthCode());
request.setCertNo(certNoTwoElementReq.getCertNo());
request.setCertName(certNoTwoElementReq.getCertName());
log.info("调用身份证二要素校验接口,入参:{}", certNoTwoElementReq);
CertNoTwoElementVerificationResponse response =client.certNoTwoElementVerification(request);
log.info("调用身份证二要素校验接口,响应:{}", JSONUtil.toJsonStr(response.getBody()));
Assert.isTrue("OK".equals(response.getBody().getCode()), Exception::new);
Assert.isTrue("1".equals(response.getBody().getData().getIsConsistent()), "身份二要素验证失败!");
}
}

View File

@ -11,10 +11,13 @@ import com.ghy.customer.domain.CustomerAddress;
import com.ghy.customer.service.CustomerAddressService;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderMasterService;
import com.ghy.web.pojo.vo.CertNoTwoElementReq;
import com.ghy.web.pojo.vo.InsuranceOrderReq;
import com.ghy.web.service.InsuranceService;
import com.ghy.worker.domain.Worker;
import com.ghy.worker.domain.WorkerCertification;
import com.ghy.worker.service.IWorkerCertificationService;
import com.ghy.worker.service.WorkerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -38,6 +41,9 @@ public class InsuranceServiceImpl implements InsuranceService {
@Autowired
private IWorkerCertificationService workerCertificationService;
@Autowired
private WorkerService workerService;
@Override
public void orderInsurance(String orderCode) throws Exception{
InsuranceOrderReq req = new InsuranceOrderReq();
@ -49,10 +55,11 @@ public class InsuranceServiceImpl implements InsuranceService {
CustomerAddress customerAddress = customerAddressService.selectByCustomerAddressId(master.getAddressId());
req.setCustomerAddress(customerAddress.getAddress());
req.setCustomerPhone(customerAddress.getPhone());
// 查询师傅信息
WorkerCertification workerCertification = workerCertificationService.selectByWorkerId(master.getWorkerId());
req.setWorkerID(workerCertification.getIdCardNum());
req.setWorkName(workerCertification.getLegalPersionName());
// 查师傅信息
Worker worker = workerService.selectById(master.getWorkerId());
CertNoTwoElementReq certNoTwoElementReq = JSONUtil.toBean(worker.getRemark(), CertNoTwoElementReq.class);
req.setWorkerID(certNoTwoElementReq.getCertNo());
req.setWorkName(certNoTwoElementReq.getCertName());
req.setOrderStartat(DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, 30), DatePattern.NORM_DATETIME_PATTERN));
req.setOrderEndat(DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, 30),DatePattern.NORM_DATETIME_PATTERN));
log.info("调用保险请求url:{},内容:{}", baseUrl+"/platInterface/order", JSONUtil.toJsonStr(req));

View File

@ -138,3 +138,10 @@ sms:
account: '8a216da85f008800015f0eb223620557'
appId: '8a216da85f008800015f0eb224db055d'
token: '3cef1bc80d814637a236d93004e7ffa5'
# 阿里云api接口, 这里是身份证二要素的
aliyun:
accessKey: LTAI5tDmv3T3Ze1Mt9wi5Be6
accessSecret: EV4dzWRfKTQaPRjf3tFziMuVBCsThU
endpoint: dytnsapi.aliyuncs.com
authCode: od2FgE9a9g

View File

@ -480,16 +480,13 @@
</select>
<select id="searchByOrderStartTime" resultMap="OrderDetailResult">
select
<include refid="selectOrderDetail"/>
from
order_detail
<where>
<if test="startTime != null and startTime != ''">
create_time <![CDATA[ >= ]]> #{startTime}
<if test="startTime != null">
and create_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
create_time <![CDATA[ <= ]]> #{endTime}
<if test="endTime != null">
and create_time <![CDATA[ <= ]]> #{endTime}
</if>
</where>
</select>

View File

@ -543,16 +543,13 @@
</select>
<select id="searchByOrderStartTime" parameterType="com.ghy.order.domain.OrderMaster" resultMap="OrderMasterResult">
select
<include refid="selectOrderMaster" />
from
order_master
<where>
<if test="startTime != null and startTime != ''">
create_time <![CDATA[ >= ]]> #{startTime}
<if test="startTime != null">
and create_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
create_time <![CDATA[ <= ]]> #{endTime}
<if test="endTime != null">
and create_time <![CDATA[ <= ]]> #{endTime}
</if>
</where>
</select>

View File

@ -171,6 +171,7 @@
update worker
<set>
<if test="type != null"> type = #{type},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="status != null"> status = #{status},</if>
<if test="wxOpenId != null"> wx_open_id = #{wxOpenId},</if>
<if test="storeStatus != null"> store_status = #{storeStatus},</if>