缴费及缴费确认接口开发
This commit is contained in:
-2
@@ -3,7 +3,6 @@ package com.ruoyi.web.controller.wisdomarbitrate;
|
|||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
@@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.ruoyi.common.core.domain.AjaxResult.error;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|||||||
@@ -126,6 +126,19 @@
|
|||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.22</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 腾讯短信sdk -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
|
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||||
|
<version>3.1.270</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import com.tencentcloudapi.common.Credential;
|
||||||
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import lombok.var;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SmsUtils {
|
||||||
|
private static final String SDK_APP_ID = "应用id";
|
||||||
|
private static final String SECRET_ID = "API的SecretId";
|
||||||
|
private static final String SECRET_KEY = "API的SecretKey";
|
||||||
|
private static final String SIGN_NAME = "签名内容";
|
||||||
|
public static Boolean sendSms(SendSmsRequest request) {
|
||||||
|
Credential cred = new Credential(SECRET_ID,SECRET_KEY);
|
||||||
|
SmsClient client = new SmsClient(cred, "ap-guangzhou");
|
||||||
|
|
||||||
|
final var req = new com.tencentcloudapi.sms.v20210111.models.SendSmsRequest();
|
||||||
|
req.setPhoneNumberSet(new String[]{"+86" + request.getPhone()});
|
||||||
|
req.setSmsSdkAppId(SDK_APP_ID);
|
||||||
|
req.setSignName(SIGN_NAME);
|
||||||
|
req.setTemplateId(request.getTemplateId());
|
||||||
|
req.setTemplateParamSet(request.getTemplateParamSet());
|
||||||
|
|
||||||
|
SendSmsResponse res = null;
|
||||||
|
try {
|
||||||
|
res = client.SendSms(req);
|
||||||
|
} catch (TencentCloudSDKException e) {
|
||||||
|
log.error("发送短信出错:", e);
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
log.error("发送短信结果:", SendSmsResponse.toJsonString(res));
|
||||||
|
|
||||||
|
if (Objects.nonNull(res.getSendStatusSet()) && res.getSendStatusSet().length > 0 && "Ok".equals(res.getSendStatusSet()[0].getCode())){
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class SendSmsRequest {
|
||||||
|
/**
|
||||||
|
* 电话
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板 ID: 必须填写已审核通过的模板 ID
|
||||||
|
*/
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空
|
||||||
|
*/
|
||||||
|
private String[] templateParamSet;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.ruoyi.wisdomarbitrate.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CasePaymentRecord extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 案件id
|
||||||
|
*/
|
||||||
|
private Long caseId;
|
||||||
|
/**
|
||||||
|
* 订单号
|
||||||
|
*/
|
||||||
|
private String orderNumber;
|
||||||
|
/**
|
||||||
|
* 支付状态(0未支付,1已支付)
|
||||||
|
*/
|
||||||
|
private Integer paymentStatus;
|
||||||
|
/**
|
||||||
|
* 支付时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date paymentTime;
|
||||||
|
}
|
||||||
@@ -1,14 +1,25 @@
|
|||||||
package com.ruoyi.wisdomarbitrate.domain.dto;
|
package com.ruoyi.wisdomarbitrate.domain.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 案件缴费传入参数
|
* 案件缴费传入参数
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class CasePayDTO {
|
public class CasePayDTO {
|
||||||
private int totalFee; //订单金额 单位:分
|
/**
|
||||||
private String body;//商品描述
|
* 案件id
|
||||||
|
*/
|
||||||
|
private Long caseId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单金额 单位:分
|
||||||
|
*/
|
||||||
|
private int totalFee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String body;
|
||||||
/**
|
/**
|
||||||
* 交易类型 native(扫码) / jsapi(小程序) / app / h5
|
* 交易类型 native(扫码) / jsapi(小程序) / app / h5
|
||||||
*/
|
*/
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.ruoyi.wisdomarbitrate.mapper;
|
||||||
|
|
||||||
|
import com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord;
|
||||||
|
|
||||||
|
public interface CasePaymentRecordMapper {
|
||||||
|
int saveRecord(CasePaymentRecord casePaymentRecord);
|
||||||
|
|
||||||
|
CasePaymentRecord queryRecord(String orderSn);
|
||||||
|
|
||||||
|
void update(CasePaymentRecord casePaymentRecord);
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package com.ruoyi.wisdomarbitrate.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.CallBackService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务回调处理
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class CallBackHandleServiceImpl implements CallBackService {
|
||||||
|
@Autowired
|
||||||
|
private CasePaymentServiceImpl casePaymentService;
|
||||||
|
@Override
|
||||||
|
public void successPay(String orderSn) {
|
||||||
|
casePaymentService.callback(orderSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failPay(String orderSn) {
|
||||||
|
log.info("支付失败回调!"+orderSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void successRefund(String orderSn) {
|
||||||
|
log.info("退款成功回调!"+orderSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failRefund(String orderSn) {
|
||||||
|
log.info("退款失败回调!"+orderSn);
|
||||||
|
}
|
||||||
|
}
|
||||||
+70
-6
@@ -1,29 +1,41 @@
|
|||||||
package com.ruoyi.wisdomarbitrate.service.impl;
|
package com.ruoyi.wisdomarbitrate.service.impl;
|
||||||
|
|
||||||
import com.ruoyi.CallBackService;
|
|
||||||
|
|
||||||
import com.ruoyi.ElegentPay;
|
import com.ruoyi.ElegentPay;
|
||||||
import com.ruoyi.common.constant.CaseApplicationConstants;
|
import com.ruoyi.common.constant.CaseApplicationConstants;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.utils.SmsUtils;
|
||||||
import com.ruoyi.dto.PayRequest;
|
import com.ruoyi.dto.PayRequest;
|
||||||
import com.ruoyi.dto.PayResponse;
|
import com.ruoyi.dto.PayResponse;
|
||||||
|
import com.ruoyi.wisdomarbitrate.domain.CaseAffiliate;
|
||||||
import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
||||||
import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
|
import com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord;
|
||||||
import com.ruoyi.wisdomarbitrate.service.ICasePaymentService;
|
|
||||||
import com.ruoyi.wisdomarbitrate.domain.dto.CasePayDTO;
|
import com.ruoyi.wisdomarbitrate.domain.dto.CasePayDTO;
|
||||||
|
import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
|
||||||
|
import com.ruoyi.wisdomarbitrate.mapper.CasePaymentRecordMapper;
|
||||||
|
import com.ruoyi.wisdomarbitrate.service.ICasePaymentService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CasePaymentServiceImpl implements ICasePaymentService {
|
public class CasePaymentServiceImpl implements ICasePaymentService {
|
||||||
private final ElegentPay elegentPay;
|
private final ElegentPay elegentPay;
|
||||||
private final CaseApplicationMapper caseApplicationMapper;
|
private final CaseApplicationMapper caseApplicationMapper;
|
||||||
|
private final CasePaymentRecordMapper casePaymentRecordMapper;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CasePaymentServiceImpl(ElegentPay elegentPay
|
public CasePaymentServiceImpl(ElegentPay elegentPay
|
||||||
, CaseApplicationMapper caseApplicationMapper) {
|
, CaseApplicationMapper caseApplicationMapper
|
||||||
|
, CasePaymentRecordMapper casePaymentRecordMapper) {
|
||||||
this.elegentPay = elegentPay;
|
this.elegentPay = elegentPay;
|
||||||
this.caseApplicationMapper = caseApplicationMapper;
|
this.caseApplicationMapper = caseApplicationMapper;
|
||||||
|
this.casePaymentRecordMapper = casePaymentRecordMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,13 +45,65 @@ public class CasePaymentServiceImpl implements ICasePaymentService {
|
|||||||
payRequest.setOrderSn(System.currentTimeMillis() + "");
|
payRequest.setOrderSn(System.currentTimeMillis() + "");
|
||||||
payRequest.setTotalFee(casePayDTO.getTotalFee());
|
payRequest.setTotalFee(casePayDTO.getTotalFee());
|
||||||
PayResponse response = elegentPay.requestPay(payRequest, casePayDTO.getTradeType(), casePayDTO.getPlatform());
|
PayResponse response = elegentPay.requestPay(payRequest, casePayDTO.getTradeType(), casePayDTO.getPlatform());
|
||||||
|
if (response.getCode_url() == null) {
|
||||||
|
return AjaxResult.error();
|
||||||
|
}
|
||||||
|
//缴费记录表里新增数据
|
||||||
|
CasePaymentRecord casePaymentRecord = new CasePaymentRecord();
|
||||||
|
casePaymentRecord.setCaseId(casePayDTO.getCaseId());
|
||||||
|
casePaymentRecord.setOrderNumber(payRequest.getOrderSn());
|
||||||
|
casePaymentRecord.setPaymentStatus(0);
|
||||||
|
int count = casePaymentRecordMapper.saveRecord(casePaymentRecord);
|
||||||
|
if (count < 1) {
|
||||||
|
return AjaxResult.error("请检查参数是否有误");
|
||||||
|
}
|
||||||
return AjaxResult.success(response);
|
return AjaxResult.success(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AjaxResult callback(String orderSn) {
|
||||||
|
//查询记录
|
||||||
|
CasePaymentRecord casePaymentRecord = casePaymentRecordMapper.queryRecord(orderSn);
|
||||||
|
if (casePaymentRecord == null) {
|
||||||
|
return AjaxResult.error("未查询到相关记录");
|
||||||
|
}
|
||||||
|
Long caseId = casePaymentRecord.getCaseId();
|
||||||
|
//更改记录表里的支付状态和支付时间
|
||||||
|
casePaymentRecord.setPaymentStatus(1);
|
||||||
|
casePaymentRecord.setPaymentTime(new Date());
|
||||||
|
casePaymentRecordMapper.update(casePaymentRecord);
|
||||||
|
//根据案件id查询案件信息
|
||||||
|
CaseApplication caseApplication = new CaseApplication();
|
||||||
|
caseApplication.setId(caseId);
|
||||||
|
CaseApplication caseApplication1 = caseApplicationMapper.selectCaseApplication(caseApplication);
|
||||||
|
caseApplication1.setCaseStatus(CaseApplicationConstants.PENDING_PAYMENT_CONFIRM);
|
||||||
|
//修改案件状态
|
||||||
|
caseApplicationMapper.submitCaseApplication(caseApplication);
|
||||||
|
//发送短信通知
|
||||||
|
SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
|
||||||
|
List<CaseAffiliate> caseAffiliates = caseApplication1.getCaseAffiliates();//获取案件关联人信息
|
||||||
|
if (caseAffiliates!=null&&caseAffiliates.size()>0){
|
||||||
|
for (CaseAffiliate caseAffiliate : caseAffiliates) {
|
||||||
|
request.setPhone(caseAffiliate.getContactTelphone());
|
||||||
|
//获取身份类型
|
||||||
|
int identityType = caseAffiliate.getIdentityType();
|
||||||
|
if (identityType==1){ //申请人
|
||||||
|
request.setTemplateId("申请人模板id"); //传入申请人模板id
|
||||||
|
// 这个值,要看你的模板中是否预留了占位符,如果没有则不需要设置
|
||||||
|
request.setTemplateParamSet(new String[]{"模板中的参数值,如果没有则为空"});
|
||||||
|
} else { //被申请人
|
||||||
|
request.setTemplateId("被申请人模板id");
|
||||||
|
request.setTemplateParamSet(new String[]{"模板中的参数值,如果没有则为空"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SmsUtils.sendSms(request);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult confirmPayment(CaseApplication caseApplication) {
|
public AjaxResult confirmPayment(CaseApplication caseApplication) {
|
||||||
caseApplication.setCaseStatus(CaseApplicationConstants.EVIDENCE_CONFREMED);
|
caseApplication.setCaseStatus(CaseApplicationConstants.EVIDENCE_CONFREMED);
|
||||||
int i = caseApplicationMapper.updataCaseApplication(caseApplication);
|
int i = caseApplicationMapper.submitCaseApplication(caseApplication);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.wisdomarbitrate.mapper.CasePaymentRecordMapper">
|
||||||
|
<insert id="saveRecord">
|
||||||
|
INSERT INTO case_payment_record (case_id, order_number, payment_status)
|
||||||
|
VALUES (#{caseId}, #{orderNumber}, #{paymentStatus})
|
||||||
|
</insert>
|
||||||
|
<update id="update">
|
||||||
|
update case_payment_record
|
||||||
|
<set>
|
||||||
|
<if test="caseId != null">case_id= #{caseId},</if>
|
||||||
|
<if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
|
||||||
|
<if test="paymentTime != null ">payment_time = #{paymentTime},</if>
|
||||||
|
<if test="paymentStatus != null ">payment_status = #{paymentStatus},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
<select id="queryRecord" resultType="com.ruoyi.wisdomarbitrate.domain.CasePaymentRecord">
|
||||||
|
select c.id ,c.case_id ,c.order_number ,c.payment_time ,c.create_time ,c.update_time ,c.payment_status
|
||||||
|
from case_payment_record c
|
||||||
|
<where>
|
||||||
|
<if test="orderSn != null ">
|
||||||
|
AND c.order_number = #{orderSn}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user