Parcourir la source

身份证校验

xdd il y a 3 semaines
Parent
commit
8885234fa8

+ 5 - 2
fs-admin/src/main/java/com/fs/store/controller/FsTestReportController.java

@@ -11,6 +11,7 @@ import com.fs.store.param.FsTestReportParam;
 import com.fs.store.service.IFsTestReportService;
 import com.fs.store.vo.FsTestReportListVO;
 import com.fs.store.vo.FsTestReportVO;
+import com.hc.openapi.tool.util.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -40,7 +41,9 @@ public class FsTestReportController extends BaseController
         startPage();
         List<FsTestReportListVO> list = fsTestReportService.selectFsTestReportListVO(fsTestReport);
         for (FsTestReportListVO vo : list) {
-            vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
+            if(StringUtils.isNotBlank(vo.getPhone())) {
+                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
+            }
         }
         return getDataTable(list);
     }
@@ -69,7 +72,7 @@ public class FsTestReportController extends BaseController
         if (fsTestReportVO.getPhone()!=null){
             fsTestReportVO.setPhone(fsTestReportVO.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
         }
-        return AjaxResult.success();
+        return AjaxResult.success(fsTestReportVO);
     }
 
     /**

+ 73 - 0
fs-common/src/main/java/com/fs/common/dto/PersonIdentityDTO.java

@@ -0,0 +1,73 @@
+package com.fs.common.dto;
+
+import lombok.Data;
+import lombok.Builder;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateUtils;
+
+import java.io.Serializable;
+import java.text.ParseException;
+import java.util.Date;
+
+/**
+ * 个人身份信息DTO
+ *
+ * @author xdd
+ * @since 2025-02-27
+ * @version 1.0
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class PersonIdentityDTO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 姓名
+     */
+    private String name;
+
+    /**
+     * 身份证号
+     */
+    private String idcard;
+
+    /**
+     * 验证结果
+     * 验证结果代码(1-一致,2-不一致)
+     */
+    private String res;
+
+    /**
+     * 验证描述
+     */
+    private String description;
+
+    /**
+     * 性别
+     */
+    private String sex;
+
+    /**
+     * 出生日期
+     * 格式:YYYYMMDD
+     */
+    private String birthday;
+
+    public Date getBirthdayDate() throws ParseException {
+        if(StringUtils.isBlank(birthday)) {
+            return null;
+        }
+        return DateUtils.parseDate(birthday,"yyyyMMdd");
+    }
+
+    /**
+     * 户籍地址
+     */
+    private String address;
+
+}

+ 76 - 0
fs-common/src/main/java/com/fs/common/utils/ParseUtils.java

@@ -1,6 +1,18 @@
 package com.fs.common.utils;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.fs.common.dto.PersonIdentityDTO;
+import lombok.extern.slf4j.Slf4j;
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
+@Slf4j
 public class ParseUtils {
 
     public static String parsePhone(String phone) {
@@ -30,4 +42,68 @@ public class ParseUtils {
         }
 
     }
+
+    public static void main(String[] args) {
+        PersonIdentityDTO dto = validateIdCard("向董董", "513022199804185613");
+        log.info(dto.toString());
+    }
+
+    /**
+     * 校验身份证和姓名是否一致
+     * @param name 姓名
+     * @param idCard 身份证
+     * @return 1一致,否则抛出异常
+     */
+    public static PersonIdentityDTO validateIdCard(String name,String idCard){
+        return checkIdCardAndName("10b395a78f4b43c2be8f8d2d59d16c1f", name, idCard);
+    }
+    /**
+     * 使用 Hutool 工具包进行身份二要素实名认证
+     * <p>
+     * 业务逻辑:
+     * 1. 调用 API,获取 JSON 响应。
+     * 2. 解析 JSON,检查外层 'code' 字段。
+     * 3. 如果 'code' 不为 "0",抛出包含 'message' 信息的 RuntimeException。
+     * 4. 如果 'code' 为 "0",检查内层 'result.res' 字段。
+     * 5. 如果 'result.res' 为 "1",方法返回字符串 "1"。
+     * 6. 如果 'result.res' 不为 "1",抛出包含 'result.description' 信息的 RuntimeException。
+     *
+     * @param appCode 你的阿里云市场 AppCode
+     * @param name    待校验的姓名
+     * @param idcard  待校验的身份证号
+     * @return 如果校验成功且信息一致,返回 "1"
+     * @throws RuntimeException 当 API 返回错误或校验结果不一致时抛出
+     */
+    private static PersonIdentityDTO checkIdCardAndName(String appCode, String name, String idcard) {
+        String url = "https://eid.shumaidata.com/eid/checkbody";
+        Map<String, Object> params = new HashMap<>();
+        params.put("idcard", idcard);
+        params.put("name", name);
+        String body = HttpRequest.post(url)
+                .header("Authorization", "APPCODE " + appCode)
+                .form(params)
+                .timeout(10000)
+                .execute()
+                .body(); // 获取响应体
+        System.out.println("API 原始返回: " + body);
+        JSONObject responseJson = JSONUtil.parseObj(body);
+        String code = responseJson.getStr("code");
+        if (!"0".equals(code)) {
+            String message = responseJson.getStr("message", "未知错误");
+            throw new RuntimeException(message);
+        }
+        JSONObject resultObj = responseJson.getJSONObject("result");
+        if (resultObj == null || resultObj.isEmpty()) {
+            throw new RuntimeException("API调用成功,但返回的result内容为空");
+        }
+        String res = resultObj.getStr("res");
+        if ("1".equals(res)) {
+            PersonIdentityDTO dto = JSON.parseObject(resultObj.toString(), PersonIdentityDTO.class);
+            return dto;
+        } else {
+            // 核验结果不一致或无记录, 抛出 description
+            String description = resultObj.getStr("description", "核验不一致或无此记录");
+            throw new RuntimeException("校验结果:"+description+",请检查身份证信息是否正确!");
+        }
+    }
 }

+ 1 - 0
fs-service-system/src/main/java/com/fs/pay/pay/service/impl/PayApiServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.pay.pay.service.impl;
 
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.parser.ParserConfig;
 import com.fs.common.utils.spring.SpringUtils;
 import com.fs.huifuPay.sdk.opps.core.config.MerConfig;
 import com.fs.pay.pay.config.PayConfig;

+ 0 - 8
fs-service-system/src/main/java/com/fs/store/domain/FsPayConfig.java

@@ -65,14 +65,6 @@ public class FsPayConfig {
      */
     private String uuid;
 
-    /**
-     * 应用 ID
-     * <p>
-     * 示例值: "wx19c8813ffc33d1cb"
-     * </p>
-     */
-    private String appid;
-
     /**
      * 平台商户号
      */

+ 1 - 1
fs-service-system/src/main/java/com/fs/store/domain/FsPrescribe.java

@@ -34,7 +34,7 @@ public class FsPrescribe extends BaseEntity
 
     /** 店铺订单ID */
     @Excel(name = "店铺订单ID")
-    private Long storeOrderId;
+    private Long orderId;
 
     /** 用户ID */
     @Excel(name = "用户ID")

+ 1 - 1
fs-service-system/src/main/java/com/fs/store/mapper/FsTestReportMapper.java

@@ -75,7 +75,7 @@ public interface FsTestReportMapper
             "</script>"})
     List<FsTestReportListVO> selectFsTestReportListVO(FsTestReportParam fsTestReport);
 
-    @Select("select tr.*,t.`name`,u.nick_name,u.phone FROM fs_test_report tr LEFT JOIN fs_test_temp t ON t.temp_id=tr.temp_id LEFT JOIN fs_user u ON u.user_id=tr.user_id where tr.report_id =#{reportId}")
+    @Select("select tr.*,t.`name`,u.nickname,u.phone FROM fs_test_report tr LEFT JOIN fs_test_temp t ON t.temp_id=tr.temp_id LEFT JOIN fs_user u ON u.user_id=tr.user_id where tr.report_id =#{reportId}")
     FsTestReportVO selectFsTestReportByReportIdVO(Long reportId);
 
 

+ 1 - 0
fs-service-system/src/main/java/com/fs/store/param/FsPatientAddEditParam.java

@@ -35,4 +35,5 @@ public class FsPatientAddEditParam implements Serializable
     @NotNull(message = "性别不能为空")
     private Integer gender;
 
+
 }

+ 2 - 53
fs-service-system/src/main/java/com/fs/store/service/impl/FsPrescribeServiceImpl.java

@@ -145,9 +145,6 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         if(order==null){
             throw  new CustomException("订单不存在");
         }
-//      if(order.getStatus()!=1){
-//           throw  new CustomException("未支付订单不能开处方");
-//      }
         FsPrescribe checkPrescribe=fsPrescribeMapper.selectFsPrescribeByOrderId(order.getId());
         if(checkPrescribe!=null){
             throw  new CustomException("已提交处方申请,正在开方...");
@@ -155,52 +152,8 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         FsStoreOrderItem orderItemMap=new FsStoreOrderItem();
         orderItemMap.setOrderId(order.getId());
         orderItemMap.setIsPrescribe(1);
-        List<FsStoreOrderItem> items= orderItemService.selectFsStoreOrderItemList(orderItemMap);
         String rpId=OrderUtils.getOrderNo();
         FsPatient patient=patientService.selectFsPatientById(param.getPatientId());
-        FsUser user=userService.selectFsUserById(userId);
-        PrescribeV2Param prescribeParam=new PrescribeV2Param();
-        PrescribeV2 prescribe=new PrescribeV2();
-        prescribe.setDrugType("01");
-        prescribe.setOnlyId(rpId);
-        prescribe.setDrugstoreName("零利润药房");
-        prescribe.setPatientName(patient.getPatientName());
-        prescribe.setPatientAge(DateUtils.getAge(patient.getBirthday()));
-//        prescribe.setPatientTel(user.getPhone());
-        prescribe.setPatientSex(patient.getGender());
-        prescribe.setPatientAllergy(param.getIsAllergic()?1:0);
-        prescribe.setLiverUnusual(param.getIsLiver()?1:0);
-        prescribe.setRenalUnusual(param.getIsRenal()?1:0);
-        prescribe.setLactationFlag(param.getIsLactation()?1:0);
-        prescribe.setChiefComplaint(param.getChiefComplaint());
-        prescribe.setNowIllness(param.getNowIllness());
-        prescribe.setHistoryIllness(param.getHistoryIllness());
-        if(StringUtils.isNotEmpty(param.getRecordPic())){
-            prescribe.setRecordPic(param.getRecordPic().split(","));
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date now = new Date();
-        prescribe.setCreateTime(sdf.format(now));
-        prescribe.setPictureType("png");
-//        prescribe.setLactationFlag("否");
-        prescribe.setCallbackUrl(fsSysConfig.getCallbackUrl());
-
-        List<DrugV2> drug_list=new ArrayList<>();
-        for(FsStoreOrderItem item:items){
-            FsStoreProduct product=productService.selectFsStoreProductById(item.getProductId());
-            DrugV2 drug=new DrugV2();
-            drug.setDrugCommonName(product.getPrescribeName());
-            drug.setDrugSpecification(product.getPrescribeSpec());
-            drug.setSaleAmount(item.getNum().toString());
-            drug.setSaleUnit(product.getUnitName());
-            drug.setApprovalNumber(product.getPrescribeCode());
-            drug.setDrugCode(product.getProductId());
-            drug_list.add(drug);
-            prescribe.setDrugList(drug_list);
-            prescribeParam.setData(prescribe);
-        }
-        R response=prescribeService.doPrescribeV2(prescribeParam);
-//        if(response.get("code").equals(200)){
         FsPrescribe fsPrescribe=new FsPrescribe();
         fsPrescribe.setRpId(rpId);
         fsPrescribe.setUserId(userId);
@@ -209,7 +162,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         fsPrescribe.setPharmacyName("零利润药房");
         fsPrescribe.setStatus(0);
         fsPrescribe.setPrescribeType(1);
-        fsPrescribe.setStoreOrderId(order.getId());
+        fsPrescribe.setOrderId(order.getId());
         fsPrescribe.setCreateTime(new Date());
         fsPrescribe.setPatientGender(patient.getGender().toString());
         fsPrescribe.setPatientName(patient.getPatientName());
@@ -229,10 +182,6 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         orderMap.setPrescribeId(fsPrescribe.getPrescribeId());
         orderService.updateFsStoreOrder(orderMap);
         return R.ok("操作成功").put("order",order);
-//        }
-//        else{
-//            return R.error(response.get("msg").toString());
-//        }
     }
 
     @Override
@@ -262,7 +211,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         if (f==null){
             return "";
         }
-        FsStoreOrder fsStoreOrder = orderService.selectFsStoreOrderById(f.getStoreOrderId());
+        FsStoreOrder fsStoreOrder = orderService.selectFsStoreOrderById(f.getOrderId());
         FsInquiryOrderVO order = fsInquiryOrderMapper.selectFsInquiryOrderVOByOrderId(f.getInquiryOrderId());
         if (f.getPrescribeImgUrl()==null||f.getPrescribeImgUrl().equals("")){
             FsPrescribeDrug d = new FsPrescribeDrug();

+ 9 - 3
fs-service-system/src/main/java/com/fs/store/vo/FsPrescribeVO.java

@@ -20,9 +20,15 @@ public class FsPrescribeVO implements Serializable {
     @Excel(name = "订单ID")
     private Long inquiryOrderId;
 
-    /** 店铺订单ID */
-    @Excel(name = "店铺订单ID")
-    private Long storeOrderId;
+    /**
+     * 处方单Id
+     */
+    @Excel(name = "处方单ID")
+    private String rpId;
+
+    /** 订单id **/
+    @Excel(name = "订单ID")
+    private Long orderId;
     /** 用户id */
     @Excel(name = "用户昵称")
     private String nickName;

+ 7 - 7
fs-service-system/src/main/resources/mapper/store/FsPrescribeMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fs.store.mapper.FsPrescribeMapper">
-    
+
     <resultMap type="FsPrescribe" id="FsPrescribeResult">
         <result property="prescribeId"    column="prescribe_id"    />
         <result property="prescribeType"    column="prescribe_type"    />
@@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectFsPrescribeList" parameterType="FsPrescribe" resultMap="FsPrescribeResult">
         <include refid="selectFsPrescribeVo"/>
-        <where>  
+        <where>
             <if test="prescribeType != null "> and prescribe_type = #{prescribeType}</if>
             <if test="orderId != null "> and order_id = #{orderId}</if>
             <if test="userId != null "> and user_id = #{userId}</if>
@@ -75,12 +75,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="status != null  and status != ''"> and status = #{status}</if>
         </where>
     </select>
-    
+
     <select id="selectFsPrescribeById" parameterType="Long" resultMap="FsPrescribeResult">
         <include refid="selectFsPrescribeVo"/>
         where prescribe_id = #{prescribeId}
     </select>
-        
+
     <insert id="insertFsPrescribe" parameterType="FsPrescribe" useGeneratedKeys="true" keyProperty="prescribeId">
         insert into fs_prescribe
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -191,10 +191,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteFsPrescribeByIds" parameterType="String">
-        delete from fs_prescribe where prescribe_id in 
+        delete from fs_prescribe where prescribe_id in
         <foreach item="prescribeId" collection="array" open="(" separator="," close=")">
             #{prescribeId}
         </foreach>
     </delete>
-    
-</mapper>
+
+</mapper>

+ 25 - 5
fs-user-app/src/main/java/com/fs/app/controller/PatientController.java

@@ -3,7 +3,10 @@ package com.fs.app.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.fs.app.annotation.Login;
+import com.fs.app.exception.FSException;
 import com.fs.common.core.domain.R;
+import com.fs.common.dto.PersonIdentityDTO;
+import com.fs.common.utils.ParseUtils;
 import com.fs.store.domain.FsPatient;
 import com.fs.store.param.FsPatientAddEditParam;
 import com.fs.store.service.IFsPatientService;
@@ -14,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
+import java.text.ParseException;
+import java.util.Date;
 import java.util.List;
 
 
@@ -55,15 +60,21 @@ public class PatientController extends  AppBaseController {
     @Login
     @ApiOperation("添加病人")
     @PostMapping("/addPatient")
-    public R addPatient(@Valid @RequestBody FsPatientAddEditParam param){
-        if(param.getBirthday()==null){
-            return R.error("生日不能为空");
-        }
+    public R addPatient(@Valid @RequestBody FsPatientAddEditParam param) throws ParseException {
+        // 身份证二要素验证
+        PersonIdentityDTO dto = ParseUtils.validateIdCard(param.getPatientName(), param.getIdCard());
+
         param.setUserId(Long.parseLong(getUserId()));
         FsPatient patient=new FsPatient();
         BeanUtil.copyProperties(param, patient);
+        if(dto == null) {
+            throw new FSException("身份证二要素验证失败!");
+        }
+        patient.setBirthday(dto.getBirthdayDate());
         patient.setIsDel(0);
         patient.setStatus(1);
+        patient.setCreateTime(new Date());
+        patient.setUpdateTime(new Date());
         patientService.insertFsPatient(patient);
         return R.ok("操作成功");
     }
@@ -71,9 +82,18 @@ public class PatientController extends  AppBaseController {
     @Login
     @ApiOperation("编辑病人")
     @PostMapping("/editPatient")
-    public R editPatient(@Valid @RequestBody FsPatientAddEditParam param){
+    public R editPatient(@Valid @RequestBody FsPatientAddEditParam param) throws ParseException {
+        // 身份证二要素验证
+        PersonIdentityDTO dto = ParseUtils.validateIdCard(param.getPatientName(), param.getIdCard());
+
         FsPatient patient=new FsPatient();
         BeanUtil.copyProperties(param, patient);
+
+        if(dto == null) {
+            throw new FSException("身份证二要素验证失败!");
+        }
+        patient.setBirthday(dto.getBirthdayDate());
+
         patientService.updateFsPatient(patient);
         return R.ok("操作成功");
     }

+ 11 - 0
fs-user-app/src/main/java/com/fs/app/exception/FSExceptionHandler.java

@@ -37,6 +37,17 @@ public class FSExceptionHandler {
 
 		return r;
 	}
+	/**
+	 * 处理自定义异常
+	 */
+	@ExceptionHandler(RuntimeException.class)
+	public R handleRuntimeException(RuntimeException e){
+		R r = new R();
+		r.put("code", 500);
+		r.put("msg", e.getMessage());
+
+		return r;
+	}
 
 	@ExceptionHandler(NoHandlerFoundException.class)
 	public R handlerNoFoundException(Exception e) {