Quellcode durchsuchen

缴费及缴费确认接口开发

hejinbo vor 2 Jahren
Ursprung
Commit
60d2b490c2

+ 0
- 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java Datei anzeigen

3
 import com.ruoyi.common.annotation.Log;
3
 import com.ruoyi.common.annotation.Log;
4
 import com.ruoyi.common.core.controller.BaseController;
4
 import com.ruoyi.common.core.controller.BaseController;
5
 import com.ruoyi.common.core.domain.AjaxResult;
5
 import com.ruoyi.common.core.domain.AjaxResult;
6
-import com.ruoyi.common.core.domain.entity.SysUser;
7
 import com.ruoyi.common.core.page.TableDataInfo;
6
 import com.ruoyi.common.core.page.TableDataInfo;
8
 import com.ruoyi.common.enums.BusinessType;
7
 import com.ruoyi.common.enums.BusinessType;
9
 import com.ruoyi.common.utils.SecurityUtils;
8
 import com.ruoyi.common.utils.SecurityUtils;
18
 
17
 
19
 import java.util.List;
18
 import java.util.List;
20
 
19
 
21
-import static com.ruoyi.common.core.domain.AjaxResult.error;
22
 
20
 
23
 
21
 
24
 @RestController
22
 @RestController

+ 13
- 0
ruoyi-common/pom.xml Datei anzeigen

126
             <artifactId>javax.servlet-api</artifactId>
126
             <artifactId>javax.servlet-api</artifactId>
127
         </dependency>
127
         </dependency>
128
 
128
 
129
+        <dependency>
130
+            <groupId>org.projectlombok</groupId>
131
+            <artifactId>lombok</artifactId>
132
+            <version>1.18.22</version>
133
+        </dependency>
134
+
135
+        <!-- 腾讯短信sdk -->
136
+        <dependency>
137
+            <groupId>com.tencentcloudapi</groupId>
138
+            <artifactId>tencentcloud-sdk-java</artifactId>
139
+            <version>3.1.270</version>
140
+        </dependency>
141
+
129
     </dependencies>
142
     </dependencies>
130
 
143
 
131
 </project>
144
 </project>

+ 66
- 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/SmsUtils.java Datei anzeigen

1
+package com.ruoyi.common.utils;
2
+
3
+import com.tencentcloudapi.common.Credential;
4
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
5
+import com.tencentcloudapi.sms.v20210111.SmsClient;
6
+import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
7
+import lombok.Data;
8
+import lombok.extern.slf4j.Slf4j;
9
+import lombok.var;
10
+
11
+import java.util.Objects;
12
+
13
+@Slf4j
14
+public class SmsUtils {
15
+    private static final String SDK_APP_ID = "应用id";
16
+    private static final String SECRET_ID = "API的SecretId";
17
+    private static final String SECRET_KEY = "API的SecretKey";
18
+    private static final String SIGN_NAME = "签名内容";
19
+    public static Boolean sendSms(SendSmsRequest request) {
20
+        Credential cred = new Credential(SECRET_ID,SECRET_KEY);
21
+        SmsClient client = new SmsClient(cred, "ap-guangzhou");
22
+
23
+        final var req = new com.tencentcloudapi.sms.v20210111.models.SendSmsRequest();
24
+        req.setPhoneNumberSet(new String[]{"+86" + request.getPhone()});
25
+        req.setSmsSdkAppId(SDK_APP_ID);
26
+        req.setSignName(SIGN_NAME);
27
+        req.setTemplateId(request.getTemplateId());
28
+        req.setTemplateParamSet(request.getTemplateParamSet());
29
+
30
+        SendSmsResponse res = null;
31
+        try {
32
+            res = client.SendSms(req);
33
+        } catch (TencentCloudSDKException e) {
34
+            log.error("发送短信出错:", e);
35
+            return Boolean.FALSE;
36
+        }
37
+        log.error("发送短信结果:", SendSmsResponse.toJsonString(res));
38
+
39
+        if (Objects.nonNull(res.getSendStatusSet()) && res.getSendStatusSet().length > 0 && "Ok".equals(res.getSendStatusSet()[0].getCode())){
40
+            return Boolean.TRUE;
41
+        }
42
+        return Boolean.FALSE;
43
+    }
44
+
45
+    /**
46
+     * 参数对象
47
+     */
48
+    @Data
49
+    public static class SendSmsRequest {
50
+        /**
51
+         * 电话
52
+         */
53
+        private String phone;
54
+
55
+        /**
56
+         * 模板 ID: 必须填写已审核通过的模板 ID
57
+         */
58
+        private String templateId;
59
+
60
+        /**
61
+         * 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空
62
+         */
63
+        private String[] templateParamSet;
64
+
65
+    }
66
+}

+ 33
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/CasePaymentRecord.java Datei anzeigen

1
+package com.ruoyi.wisdomarbitrate.domain;
2
+
3
+import com.fasterxml.jackson.annotation.JsonFormat;
4
+import com.ruoyi.common.core.domain.BaseEntity;
5
+import lombok.Data;
6
+
7
+import java.util.Date;
8
+
9
+@Data
10
+public class CasePaymentRecord extends BaseEntity {
11
+    private static final long serialVersionUID = 1L;
12
+    /**
13
+     * 主键
14
+     */
15
+    private Integer id;
16
+    /**
17
+     * 案件id
18
+     */
19
+    private Long caseId;
20
+    /**
21
+     * 订单号
22
+     */
23
+    private String orderNumber;
24
+    /**
25
+     * 支付状态(0未支付,1已支付)
26
+     */
27
+    private Integer paymentStatus;
28
+    /**
29
+     * 支付时间
30
+     */
31
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
32
+    private Date paymentTime;
33
+}

+ 15
- 4
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/dto/CasePayDTO.java Datei anzeigen

1
 package com.ruoyi.wisdomarbitrate.domain.dto;
1
 package com.ruoyi.wisdomarbitrate.domain.dto;
2
 
2
 
3
 import lombok.Data;
3
 import lombok.Data;
4
-
5
 /**
4
 /**
6
  * 案件缴费传入参数
5
  * 案件缴费传入参数
7
  */
6
  */
8
 @Data
7
 @Data
9
 public class CasePayDTO {
8
 public class CasePayDTO {
10
-    private int totalFee; //订单金额 单位:分
11
-    private String body;//商品描述
9
+    /**
10
+     * 案件id
11
+     */
12
+    private Long caseId;
13
+
14
+    /**
15
+     * 订单金额 单位:分
16
+     */
17
+    private int totalFee;
18
+
19
+    /**
20
+     * 描述
21
+     */
22
+    private String body;
12
     /**
23
     /**
13
      * 交易类型 native(扫码) / jsapi(小程序) / app / h5
24
      * 交易类型 native(扫码) / jsapi(小程序) / app / h5
14
      */
25
      */
17
      * 支付方式 wxpay(微信)  alipay(支付宝)
28
      * 支付方式 wxpay(微信)  alipay(支付宝)
18
      */
29
      */
19
     private String platform;
30
     private String platform;
20
-}
31
+}

+ 11
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CasePaymentRecordMapper.java Datei anzeigen

1
+package com.ruoyi.wisdomarbitrate.mapper;
2
+
3
+import com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord;
4
+
5
+public interface CasePaymentRecordMapper {
6
+    int saveRecord(CasePaymentRecord casePaymentRecord);
7
+
8
+    CasePaymentRecord queryRecord(String orderSn);
9
+
10
+    void update(CasePaymentRecord casePaymentRecord);
11
+}

+ 35
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CallBackHandleServiceImpl.java Datei anzeigen

1
+package com.ruoyi.wisdomarbitrate.service.impl;
2
+
3
+import com.ruoyi.CallBackService;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Component;
7
+
8
+/**
9
+ * 业务回调处理
10
+ */
11
+@Component
12
+@Slf4j
13
+public class CallBackHandleServiceImpl implements CallBackService {
14
+    @Autowired
15
+    private CasePaymentServiceImpl casePaymentService;
16
+    @Override
17
+    public void successPay(String orderSn) {
18
+        casePaymentService.callback(orderSn);
19
+    }
20
+
21
+    @Override
22
+    public void failPay(String orderSn) {
23
+        log.info("支付失败回调!"+orderSn);
24
+    }
25
+
26
+    @Override
27
+    public void successRefund(String orderSn) {
28
+        log.info("退款成功回调!"+orderSn);
29
+    }
30
+
31
+    @Override
32
+    public void failRefund(String orderSn) {
33
+        log.info("退款失败回调!"+orderSn);
34
+    }
35
+}

+ 69
- 5
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CasePaymentServiceImpl.java Datei anzeigen

1
 package com.ruoyi.wisdomarbitrate.service.impl;
1
 package com.ruoyi.wisdomarbitrate.service.impl;
2
 
2
 
3
-import com.ruoyi.CallBackService;
3
+
4
+
4
 import com.ruoyi.ElegentPay;
5
 import com.ruoyi.ElegentPay;
5
 import com.ruoyi.common.constant.CaseApplicationConstants;
6
 import com.ruoyi.common.constant.CaseApplicationConstants;
6
 import com.ruoyi.common.core.domain.AjaxResult;
7
 import com.ruoyi.common.core.domain.AjaxResult;
7
-
8
+import com.ruoyi.common.utils.SmsUtils;
8
 import com.ruoyi.dto.PayRequest;
9
 import com.ruoyi.dto.PayRequest;
9
 import com.ruoyi.dto.PayResponse;
10
 import com.ruoyi.dto.PayResponse;
11
+import com.ruoyi.wisdomarbitrate.domain.CaseAffiliate;
10
 import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
12
 import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
13
+import com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord;
14
+import com.ruoyi.wisdomarbitrate.domain.dto.CasePayDTO;
11
 import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
15
 import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
16
+import com.ruoyi.wisdomarbitrate.mapper.CasePaymentRecordMapper;
12
 import com.ruoyi.wisdomarbitrate.service.ICasePaymentService;
17
 import com.ruoyi.wisdomarbitrate.service.ICasePaymentService;
13
-import com.ruoyi.wisdomarbitrate.domain.dto.CasePayDTO;
14
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.stereotype.Service;
19
 import org.springframework.stereotype.Service;
16
 
20
 
21
+import java.time.LocalDateTime;
22
+import java.util.Date;
23
+import java.util.List;
24
+
17
 @Service
25
 @Service
18
 public class CasePaymentServiceImpl implements ICasePaymentService {
26
 public class CasePaymentServiceImpl implements ICasePaymentService {
19
     private final ElegentPay elegentPay;
27
     private final ElegentPay elegentPay;
20
     private final CaseApplicationMapper caseApplicationMapper;
28
     private final CaseApplicationMapper caseApplicationMapper;
29
+    private final CasePaymentRecordMapper casePaymentRecordMapper;
30
+
21
 
31
 
22
     @Autowired
32
     @Autowired
23
     public CasePaymentServiceImpl(ElegentPay elegentPay
33
     public CasePaymentServiceImpl(ElegentPay elegentPay
24
-            , CaseApplicationMapper caseApplicationMapper) {
34
+            , CaseApplicationMapper caseApplicationMapper
35
+            , CasePaymentRecordMapper casePaymentRecordMapper) {
25
         this.elegentPay = elegentPay;
36
         this.elegentPay = elegentPay;
26
         this.caseApplicationMapper = caseApplicationMapper;
37
         this.caseApplicationMapper = caseApplicationMapper;
38
+        this.casePaymentRecordMapper = casePaymentRecordMapper;
27
     }
39
     }
28
 
40
 
29
     @Override
41
     @Override
33
         payRequest.setOrderSn(System.currentTimeMillis() + "");
45
         payRequest.setOrderSn(System.currentTimeMillis() + "");
34
         payRequest.setTotalFee(casePayDTO.getTotalFee());
46
         payRequest.setTotalFee(casePayDTO.getTotalFee());
35
         PayResponse response = elegentPay.requestPay(payRequest, casePayDTO.getTradeType(), casePayDTO.getPlatform());
47
         PayResponse response = elegentPay.requestPay(payRequest, casePayDTO.getTradeType(), casePayDTO.getPlatform());
48
+        if (response.getCode_url() == null) {
49
+            return AjaxResult.error();
50
+        }
51
+        //缴费记录表里新增数据
52
+        CasePaymentRecord casePaymentRecord = new CasePaymentRecord();
53
+        casePaymentRecord.setCaseId(casePayDTO.getCaseId());
54
+        casePaymentRecord.setOrderNumber(payRequest.getOrderSn());
55
+        casePaymentRecord.setPaymentStatus(0);
56
+        int count = casePaymentRecordMapper.saveRecord(casePaymentRecord);
57
+        if (count < 1) {
58
+            return AjaxResult.error("请检查参数是否有误");
59
+        }
36
         return AjaxResult.success(response);
60
         return AjaxResult.success(response);
37
     }
61
     }
38
 
62
 
63
+
64
+    public AjaxResult callback(String orderSn) {
65
+        //查询记录
66
+        CasePaymentRecord casePaymentRecord = casePaymentRecordMapper.queryRecord(orderSn);
67
+        if (casePaymentRecord == null) {
68
+            return AjaxResult.error("未查询到相关记录");
69
+        }
70
+        Long caseId = casePaymentRecord.getCaseId();
71
+        //更改记录表里的支付状态和支付时间
72
+        casePaymentRecord.setPaymentStatus(1);
73
+        casePaymentRecord.setPaymentTime(new Date());
74
+        casePaymentRecordMapper.update(casePaymentRecord);
75
+        //根据案件id查询案件信息
76
+        CaseApplication caseApplication = new CaseApplication();
77
+        caseApplication.setId(caseId);
78
+        CaseApplication caseApplication1 = caseApplicationMapper.selectCaseApplication(caseApplication);
79
+        caseApplication1.setCaseStatus(CaseApplicationConstants.PENDING_PAYMENT_CONFIRM);
80
+        //修改案件状态
81
+        caseApplicationMapper.submitCaseApplication(caseApplication);
82
+        //发送短信通知
83
+        SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
84
+        List<CaseAffiliate> caseAffiliates = caseApplication1.getCaseAffiliates();//获取案件关联人信息
85
+        if (caseAffiliates!=null&&caseAffiliates.size()>0){
86
+            for (CaseAffiliate caseAffiliate : caseAffiliates) {
87
+                request.setPhone(caseAffiliate.getContactTelphone());
88
+                //获取身份类型
89
+                int identityType = caseAffiliate.getIdentityType();
90
+                if (identityType==1){    //申请人
91
+                    request.setTemplateId("申请人模板id"); //传入申请人模板id
92
+                    // 这个值,要看你的模板中是否预留了占位符,如果没有则不需要设置
93
+                    request.setTemplateParamSet(new String[]{"模板中的参数值,如果没有则为空"});
94
+                } else {       //被申请人
95
+                    request.setTemplateId("被申请人模板id");
96
+                    request.setTemplateParamSet(new String[]{"模板中的参数值,如果没有则为空"});
97
+                }
98
+            }
99
+        }
100
+        SmsUtils.sendSms(request);
101
+        return AjaxResult.success();
102
+    }
39
     @Override
103
     @Override
40
     public AjaxResult confirmPayment(CaseApplication caseApplication) {
104
     public AjaxResult confirmPayment(CaseApplication caseApplication) {
41
         caseApplication.setCaseStatus(CaseApplicationConstants.EVIDENCE_CONFREMED);
105
         caseApplication.setCaseStatus(CaseApplicationConstants.EVIDENCE_CONFREMED);
42
-        int i = caseApplicationMapper.updataCaseApplication(caseApplication);
106
+        int i = caseApplicationMapper.submitCaseApplication(caseApplication);
43
         if (i > 0) {
107
         if (i > 0) {
44
             return AjaxResult.success();
108
             return AjaxResult.success();
45
         }
109
         }

+ 29
- 0
ruoyi-system/src/main/resources/mapper/wisdomarbitrate/CasePaymentRecordMapper.xml Datei anzeigen

1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper
3
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5
+<mapper namespace="com.ruoyi.wisdomarbitrate.mapper.CasePaymentRecordMapper">
6
+    <insert id="saveRecord">
7
+        INSERT INTO case_payment_record (case_id, order_number, payment_status)
8
+        VALUES (#{caseId}, #{orderNumber}, #{paymentStatus})
9
+    </insert>
10
+    <update id="update">
11
+        update case_payment_record
12
+        <set>
13
+            <if test="caseId != null">case_id= #{caseId},</if>
14
+            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
15
+            <if test="paymentTime != null ">payment_time = #{paymentTime},</if>
16
+            <if test="paymentStatus != null ">payment_status = #{paymentStatus},</if>
17
+        </set>
18
+        where id = #{id}
19
+    </update>
20
+    <select id="queryRecord" resultType="com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord">
21
+        select c.id ,c.case_id ,c.order_number ,c.payment_time ,c.create_time ,c.update_time ,c.payment_status
22
+        from case_payment_record c
23
+        <where>
24
+            <if test="orderSn != null ">
25
+                AND c.order_number = #{orderSn}
26
+            </if>
27
+        </where>
28
+    </select>
29
+</mapper>