day03-支付微服务
新入职的你加入了开发一组,也接到了开发任务,并且你也顺利的完成了网关的鉴权业务的开发。现在开发三组所负责的支付微服务需要你来支援一下,目前支付微服务完成了支付宝和微信的对接,主要实现的功能有支付渠道的维护、扫码支付(微信称Native支付,支付宝称当面付)、退款等功能。其中扫码支付功能是快递员上门取件时,会亮出二维码,用户可以通过支付宝或微信进行扫描后,对运费的支付。流程说明:【付款方式】判断寄付
课程安排
- 支付微服务的需求
- 了解项目中的代码规范
- 阅读渠道管理相关的代码
- 理解分布式锁的应用
- 阅读支付宝扫码支付的代码
- 阅读微信支付扫码支付的代码
- xxl-job的入门学习
- 读懂同步支付状态的两种方式
1、背景说明
新入职的你加入了开发一组,也接到了开发任务,并且你也顺利的完成了网关的鉴权业务的开发。现在开发三组所负责的支付微服务需要你来支援一下,目前支付微服务完成了支付宝和微信的对接,主要实现的功能有支付渠道的维护、扫码支付(微信称Native支付,支付宝称当面付)、退款等功能。
其中扫码支付功能是快递员上门取件时,会亮出二维码,用户可以通过支付宝或微信进行扫描后,对运费的支付。
2、需求分析
2.1、整体流程
流程说明:
- 用户下单成功后,系统会为其分配快递员
- 快递员根据取件任务进行上门取件,与用户确认物品信息、重量、体积、运费等内容,确认无误后,取件成功
- 快递员会询问用户,是支付宝还是微信付款,根据用户的选择,展现支付二维码
- 用户使用手机,打开支付宝或微信进行扫描操作,用户进行付款操作,最终会有支付成功或失败情况
- 后续的逻辑暂时不考虑,支付微服务只考虑支付部分的逻辑即可
2.2、业务功能
2.3、产品需求
【付款方式】判断寄付/到付交互
- 寄付→点击【取件】进入取件成功页面,点击左上方返回按钮返回待取件任务列表;点击【去收款】按钮进入扫码支付页面,此时用户有双向选择:
- 在用户端【待支付】页面进行支付
- 在快递员端【扫码支付】页面进行支付,可选择微信或支付宝进行支付,分别生成不同的收款码,用户进行扫码支付;
- 点击页面左上方返回按钮页面返回至上一页;
- 两种方式支付成功,均显示支付成功页面,点击【知道了】,返回任务列表首页
- 到付→点击【取件】按钮,进入取件成功页面,点击返回主页按钮进入任务列表主页
2.4、分析
支付业务与其他业务相比,相对独立,所以比较适合将支付业务划分为一个微服务,而支付业务并不关系物流业务中运输、取派件等业务,只关心付款金额、付款平台、所支付的订单等。
支付微服务在整个系统架构中的业务时序图:
## 2.5、开发环境
2.5.1、微服务工程规范
在神领物流项目中,微服务代码是独立的工程(非聚合项目结构),这样更适合多团队间的协作,在部署方面更加的独立方便。
1个微服务需要创建3个工程,分别是:
- sl-express-ms-xxx-api(定义Feign接口)
- sl-express-ms-xxx-domain(定义DTO、枚举对象)
- sl-express-ms-xxx-service(微服务的实现)
它们之间的依赖关系如下:
2.5.2、拉取代码
需要拉取的工程有3个:
工程名 | git地址 |
---|---|
sl-express-ms-trade-domain | http://git.sl-express.com/sl/sl-express-ms-trade-domain.git |
sl-express-ms-trade-api | http://git.sl-express.com/sl/sl-express-ms-trade-api.git |
sl-express-ms-trade-service | http://git.sl-express.com/sl/sl-express-ms-trade-service.git |
在idea中拉取开发会有2种方式:
- 每一个工程打开一个idea窗口
- 将多个工程合并到一个idea窗口开发(非maven聚合),每一个工程作为一个module进行开发
在这里我们建议使用第2中方法,这样在开发过程中可以减少多窗口间的切换。
拉取代码完成后,需要添加到项目的modules中:
git分支说明:
在学习阶段我们统一使用master分支。
下面展现了支付微服务的工程结构:
├─sl-express-ms-trade-api 支付Feign接口
├─sl-express-ms-trade-domain 接口DTO实体
└─sl-express-ms-trade-service 支付具体实现
├─com.sl.ms.trade.config 配置包,二维码、Redisson、xxl-job
├─com.sl.ms.trade.constant 常量类包
├─com.sl.ms.trade.controller web控制器包
├─com.sl.ms.trade.entity 数据库实体包
├─com.sl.ms.trade.enums 枚举包
├─com.sl.ms.trade.handler 三方平台的对接实现(支付宝、微信)
├─com.sl.ms.trade.job 定时任务,扫描支付状态
├─com.sl.ms.trade.mapper mybatis接口
├─com.sl.ms.trade.service 服务包
├─com.sl.ms.trade.util 工具包
2.5.3、代码规范
2.5.3.1、DTO对象
在神领物流项目中,微服务之间的对象传输都使用DTO,命名规范:XxxxDTO(DTO必须大写),并且将DTO类放置到domain工程中,如下:
DTO类中统一使用lombok的@Data注解进行标注。
2.5.3.2、数据校验
微服务之间的接口调用,对于传输的数据是需要做校验的,一般校验方式有2种:
- 方式一:采用hibernate-validator注解方式校验,如下:
- 方式二:在程序中通过if()进行判断,如下:
我们采用哪一种方式呢?实际上在项目中,我们采用二者结合的方式进行校验。
对于第一种方式的补充说明:
- 在Controller中需要增加
@Validated
注解,来开启校验
- 对于表单、url参数校验,在Controller中方法增加校验规则
- 对于@RequestBody对象的校验,校验规则写的DTO对象中,统一通过Spring的AOP进行校验,具体在common工程中的
com.sl.transport.common.aspect.ValidatedAspect
进实现:
2.5.3.3、自定义异常
在神领物流项目中,我们统一做了自定义异常的处理。
定义了2个异常:
com.sl.transport.common.exception.SLException
- 用于微服务之前接口调用抛出的异常
com.sl.transport.common.exception.SLWebException
- 用于前后端交互时抛出的异常
SLException的定义:
SLWebException的定义:
这两个异常的区别在于code、status的值不同。
:::danger
疑问:为什么不使用一个,而是要设置两个?
这个主要是前端和后端的设计不同,一般在微服务间接口调用时会采用标准的RESTful方式,按照RESTful的规范响应的状态码要使用标准的http状态码,成功->200,失败->500,没有权限->401等。
而前后端进行交互时,一般都是响应200,即使出错也是200,只是响应结果中通过msg和code进行表达是否成功。
基于以上的场景,所以设置了两个异常类。
:::
统一异常处理:
具体的业务逻辑在com.sl.transport.common.handler.GlobalExceptionHandler
中实现。
关键代码如下:
在该类中对于4种异常做处理,分别是:
ValidationException
SLException
SLWebException
Exception
2.5.3.4、@Resource注入
在项目中,涉及到注入Spring容器中bean对象时,均使用@Resource
,目前IDEA不推荐使用@Autowired
,原因是它是Spring提供,并非是Java标准,而@Resource
是Java标准中定义的,建议使用。
如果想要使用@Autowired
的话,建议通过构造器注入。
两者区别:
- @Autowired:默认是ByType,可以使用@Qualifier指定Name,可以对构造器、方法、参数、字段使用。
- @Resource:默认ByName,如果找不到则ByType,只能对方法、字段使用,不能用于构造器。
- @Autowired是Spring提供的,@Resource是JSR-250提供的。
- 总结:基本上@Resource可以完全替代@Autowired。
2.5.4、配置文件
2.5.4.1、SpringBoot配置文件
文件 | 说明 |
---|---|
bootstrap.yml | 通用配置项,服务名、日志文件、swagger配置等 |
bootstrap-local.yml | 多环境配置,本地开发环境 |
bootstrap-prod.yml | 多环境配置,生成环境(学习阶段忽略该文件) |
bootstrap-stu.yml | 多环境配置,学生101环境 |
bootstrap-test.yml | 多环境配置,开发组测试环境(学习阶段忽略该文件) |
对于配置文件的补充说明:
- 关于swagger的配置,统一在【
com.sl.transport.common.properties.SwaggerConfigProperties
】中读取,并且在【com.sl.transport.common.config.Knife4jConfiguration
】中进行了初始化Knife4j。 spring.profiles.active
默认local
,部署发布到101机器,在Jenkins中发布时设置为stu。
#启动dokcer命令
docker run -d -p $SERVER_PORT:8080 --name $SERVER_NAME -e SERVER_PORT=8080 -e SPRING_CLOUD_NACOS_DISCOVERY_IP=${SPRING_CLOUD_NACOS_DISCOVERY_IP} -e SPRING_CLOUD_NACOS_DISCOVERY_PORT=${port} -e SPRING_PROFILES_ACTIVE=stu $SERVER_NAME:$SERVER_VERSION
:::danger
通过环境变量的方式配置了spring.profiles.active、发布到注册中心的ip和端口。
规则:环境变量统一采用大写字母,不允许使用.-符号,采用下划线“_”取代点“.” 减号“-”直接删除。
:::
- 为了与101环境中服务互通,所以在local环境中固定设置了注册到注册中心的服务地址
- 具体的一些项目配置统一使用nacos的配置中心管理,并且在这里使用nacos的共享配置机制,这样可以在多个项目中共享相同的配置
2.5.4.2、seata配置
seata:
registry:
type: nacos
nacos:
server-addr: 192.168.150.101:8848
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
group: DEFAULT_GROUP
application: seata-server
username: nacos
password: nacos
tx-service-group: sl-seata # 事务组名称
service:
vgroup-mapping: # 事务组与cluster的映射关系
sl-seata: default
seata服务的配置:
#指定seata存储的数据库
store.mode = db
store.db.datasource = druid
store.db.dbType = mysql
store.db.driverClassName = com.mysql.cj.jdbc.Driver
store.db.url = jdbc:mysql://192.168.150.101:3306/seata?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false
store.db.user = root
store.db.password = 123
store.db.minConn = 5
store.db.maxConn = 100
store.db.globalTable = global_table
store.db.branchTable = branch_table
store.db.lockTable = lock_table
store.db.distributedLockTable = distributed_lock
store.db.queryLimit = 100
store.db.maxWait = 5000
seata服务地址: http://seata.sl-express.com/ 账号信息:seata/seata
2.5.4.3、mysql配置
spring:
datasource: #数据库的配置
driver-class-name: ${jdbc.driver:com.mysql.cj.jdbc.Driver}
url: ${jdbc.url}
username: ${jdbc.username}
password: ${jdbc.password}
具体的配置项在每个微服务自己的配置文件中,例如支付服务:
jdbc.url = jdbc:mysql://192.168.150.101:3306/sl_trade?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false
jdbc.username = root
jdbc.password = 123
:::danger
需要说明的是,${jdbc.driver:com.mysql.cj.jdbc.Driver} 这种写法冒号后面的是默认值,如果不配置jdbc.driver就采用默认值。
:::
2.5.4.4、mybatis-plus配置
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
global-config:
db-config:
id-type: ASSIGN_ID
在配置文件中指定的默认的id策略为ASSIGN_ID,只当插入对象ID为空时,自动填充雪花id。
2.5.4.5、redis配置
spring:
redis: #redis的配置
port: ${redis.port}
host: ${redis.host}
password: ${redis.password}
具体的配置在微服务自身的配置文件中:
2.5.4.6、xxl-job配置
xxl:
job:
admin:
addresses: http://192.168.150.101:28080/xxl-job-admin
executor:
ip: 192.168.150.101
appname: ${xxl.job.executor.appname}
#执行器运行日志文件存储磁盘路径
logpath: /data/applogs/xxl-job/jobhandler
#执行器日志文件保存天数
logretentiondays: 30
2.5.5、日志
项目中统一使用logback日志框架,其配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!--scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。-->
<!--scanPeriod: 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。-->
<!--debug: 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。-->
<configuration debug="false" scan="false" scanPeriod="60 seconds">
<springProperty scope="context" name="appName" source="spring.application.name"/>
<!--文件名-->
<property name="logback.appname" value="${appName}"/>
<!--文件位置-->
<property name="logback.logdir" value="/data/logs"/>
<!-- 定义控制台输出 -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - [%thread] - %-5level - %logger{50} - %msg%n</pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<File>${logback.logdir}/${logback.appname}/${logback.appname}.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logback.logdir}/${logback.appname}/${logback.appname}.%d{yyyy-MM-dd}.log.zip</FileNamePattern>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
</encoder>
</appender>
<!--evel:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,-->
<!--不能设置为INHERITED或者同义词NULL。默认是DEBUG。-->
<root level="INFO">
<appender-ref ref="stdout"/>
</root>
</configuration>
3、支付渠道管理【阅读代码】
支付是对接支付平台完成的,例如支付宝、微信、京东支付等,一般在这些平台上需要申请账号信息,通过这些账号信息完成与支付平台的交互,在我们的支付微服务中,将这些数据称之为【支付渠道】,并且将其存储到数据库中,通过程序可以支付渠道进行管理。
3.1、表结构
支付微服务的数据是:sl_trade,支付渠道的表为:sl_pay_channel,表结构如下:
其中表中已经包含了2条数据,分别是支付宝和微信的账号信息,可以直接与支付平台对接。
3.2、阅读代码
阅读代码顺序:Entity → Mapper → Service → Controller
代码git地址:
工程 | 地址 |
---|---|
sl-express-ms-trade-service | http://git.sl-express.com/sl/sl-express-ms-trade-service |
sl-express-ms-trade-api | http://git.sl-express.com/sl/sl-express-ms-trade-api |
sl-express-ms-trade-domain | http://git.sl-express.com/sl/sl-express-ms-trade-domain |
注意:由于渠道管理目前项目中没有需求进行维护操作,所以不对外提供Feign接口。
3.2.1、PayChannelEntity
:::info
PayChannelEntity类是对sl_pay_channel表的映射,Entity类继承BaseEntity,在BaseEntity中统一定义了id、created、updated,其中created、updated是使用MybatisPlus自动填充的。
:::
package com.sl.ms.trade.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* @Description:交易渠道表
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("sl_pay_channel")
public class PayChannelEntity extends BaseEntity {
private static final long serialVersionUID = -1452774366739615656L;
@ApiModelProperty(value = "通道名称")
private String channelName;
@ApiModelProperty(value = "通道唯一标记")
private String channelLabel;
@ApiModelProperty(value = "域名")
private String domain;
@ApiModelProperty(value = "商户appid")
private String appId;
@ApiModelProperty(value = "支付公钥")
private String publicKey;
@ApiModelProperty(value = "商户私钥")
private String merchantPrivateKey;
@ApiModelProperty(value = "其他配置")
private String otherConfig;
@ApiModelProperty(value = "AES混淆密钥")
private String encryptKey;
@ApiModelProperty(value = "说明")
private String remark;
@ApiModelProperty(value = "回调地址")
private String notifyUrl;
@ApiModelProperty(value = "是否有效")
protected String enableFlag;
@ApiModelProperty(value = "商户号")
private Long enterpriseId;
}
3.2.2、PayChannelMapper
:::info
PayChannelMapper继承了MP的BaseMapper,并且加了@Mapper注解。
:::
package com.sl.ms.trade.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.trade.entity.PayChannelEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 交易渠道表Mapper接口
*/
@Mapper
public interface PayChannelMapper extends BaseMapper<PayChannelEntity> {
}
3.2.3、PayChannelService
:::info
该Service中定义了6个方法,可以对支付渠道的数据进行CRUD的管理,其中findByEnterpriseId()方法将是我们常用的一个方法,根据业务商户id查询和通道唯一标记符查询支付渠道。该方法是需要对数据做缓存的,目前并没有实现缓存,这个需要由你来实现。
:::
package com.sl.ms.trade.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.trade.domain.PayChannelDTO;
import com.sl.ms.trade.entity.PayChannelEntity;
import java.util.List;
/**
* @Description: 支付通道服务类
*/
public interface PayChannelService extends IService<PayChannelEntity> {
/**
* @param payChannelDTO 查询条件
* @param pageNum 当前页
* @param pageSize 当前页
* @return Page<PayChannel> 分页对象
* @Description 支付通道列表
*/
Page<PayChannelEntity> findPayChannelPage(PayChannelDTO payChannelDTO, int pageNum, int pageSize);
/**
* 根据商户id查询渠道配置,该配置会被缓存10分钟
*
* @param enterpriseId 商户id
* @param channelLabel 通道唯一标记
* @return PayChannelEntity 交易渠道对象
*/
PayChannelEntity findByEnterpriseId(Long enterpriseId, String channelLabel);
/**
* @param payChannelDTO 对象信息
* @return PayChannelEntity 交易渠道对象
* @Description 创建支付通道
*/
PayChannelEntity createPayChannel(PayChannelDTO payChannelDTO);
/**
* @param payChannelDTO 对象信息
* @return Boolean 是否成功
* @Description 修改支付通道
*/
Boolean updatePayChannel(PayChannelDTO payChannelDTO);
/**
* @param checkedIds 选择的支付通道ID
* @return Boolean 是否成功
* @Description 删除支付通道
*/
Boolean deletePayChannel(String[] checkedIds);
/**
* @param channelLabel 支付通道标识
* @return 支付通道列表
* @Description 查找渠道标识
*/
List<PayChannelEntity> findPayChannelList(String channelLabel);
}
3.2.4、PayChannelServiceImpl
:::info
- 该类继承了MP的ServiceImpl,可以实现基本的CRUD方法
- findByEnterpriseId()方法中的TODO需要在实战中完成
:::
package com.sl.ms.trade.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.trade.constant.Constants;
import com.sl.ms.trade.domain.PayChannelDTO;
import com.sl.ms.trade.entity.PayChannelEntity;
import com.sl.ms.trade.mapper.PayChannelMapper;
import com.sl.ms.trade.service.PayChannelService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
/**
* @Description: 服务实现类
*/
@Service
public class PayChannelServiceImpl extends ServiceImpl<PayChannelMapper, PayChannelEntity> implements PayChannelService {
@Override
public Page<PayChannelEntity> findPayChannelPage(PayChannelDTO payChannelDTO, int pageNum, int pageSize) {
Page<PayChannelEntity> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<PayChannelEntity> queryWrapper = new LambdaQueryWrapper<>();
//设置条件
queryWrapper.eq(StrUtil.isNotEmpty(payChannelDTO.getChannelLabel()), PayChannelEntity::getChannelLabel, payChannelDTO.getChannelLabel());
queryWrapper.likeRight(StrUtil.isNotEmpty(payChannelDTO.getChannelName()), PayChannelEntity::getChannelName, payChannelDTO.getChannelName());
queryWrapper.eq(StrUtil.isNotEmpty(payChannelDTO.getEnableFlag()), PayChannelEntity::getEnableFlag, payChannelDTO.getEnableFlag());
//设置排序
queryWrapper.orderByAsc(PayChannelEntity::getCreated);
return super.page(page, queryWrapper);
}
@Override
public PayChannelEntity findByEnterpriseId(Long enterpriseId, String channelLabel) {
LambdaQueryWrapper<PayChannelEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PayChannelEntity::getEnterpriseId, enterpriseId)
.eq(PayChannelEntity::getChannelLabel, channelLabel)
.eq(PayChannelEntity::getEnableFlag, Constants.YES);
//TODO 缓存
return super.getOne(queryWrapper);
}
@Override
public PayChannelEntity createPayChannel(PayChannelDTO payChannelDTO) {
PayChannelEntity payChannel = BeanUtil.toBean(payChannelDTO, PayChannelEntity.class);
boolean flag = super.save(payChannel);
if (flag) {
return payChannel;
}
return null;
}
@Override
public Boolean updatePayChannel(PayChannelDTO payChannelDTO) {
PayChannelEntity payChannel = BeanUtil.toBean(payChannelDTO, PayChannelEntity.class);
return super.updateById(payChannel);
}
@Override
public Boolean deletePayChannel(String[] checkedIds) {
List<String> ids = Arrays.asList(checkedIds);
return super.removeByIds(ids);
}
@Override
public List<PayChannelEntity> findPayChannelList(String channelLabel) {
LambdaQueryWrapper<PayChannelEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PayChannelEntity::getChannelLabel, channelLabel)
.eq(PayChannelEntity::getEnableFlag, Constants.YES);
return list(queryWrapper);
}
}
3.2.5、PayChannelController
:::info
该类中对于支付渠道维护的各种方法的维护,确保可以对外提供服务。
:::
package com.sl.ms.trade.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sl.ms.trade.domain.PayChannelDTO;
import com.sl.ms.trade.entity.PayChannelEntity;
import com.sl.ms.trade.service.PayChannelService;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@Slf4j
@RestController
@Api(tags = "支付通道")
@RequestMapping("payChannel")
public class PayChannelController {
@Resource
private PayChannelService payChannelService;
/**
* 支付通道列表
*
* @param payChannelDTO 查询条件
* @return 分页数据对象
*/
@PostMapping("page/{pageNum}/{pageSize}")
@ApiOperation(value = "查询支付通道分页", notes = "查询支付通道分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "payChannelDTO", value = "支付通道查询对象", required = true),
@ApiImplicitParam(name = "pageNum", value = "页码"),
@ApiImplicitParam(name = "pageSize", value = "每页条数")
})
public PageResponse<PayChannelDTO> findPayChannelPage(
@RequestBody PayChannelDTO payChannelDTO,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
Page<PayChannelEntity> payChannelVoPage = payChannelService.findPayChannelPage(payChannelDTO, pageNum, pageSize);
return new PageResponse<>(payChannelVoPage, PayChannelDTO.class);
}
/**
* 添加支付通道
*
* @param payChannelDTO 对象信息
*/
@PostMapping
@ApiOperation(value = "添加支付通道", notes = "添加支付通道")
@ApiImplicitParam(name = "payChannelDTO", value = "支付通道对象", required = true)
public void createPayChannel(@RequestBody PayChannelDTO payChannelDTO) {
PayChannelEntity payChannel = this.payChannelService.createPayChannel(payChannelDTO);
if (null != payChannel) {
return;
}
throw new SLException("添加支付通道失败", HttpStatus.INTERNAL_SERVER_ERROR.value());
}
/**
* 修改支付通道
*
* @param payChannelDTO 对象信息
*/
@PutMapping
@ApiOperation(value = "修改支付通道", notes = "修改支付通道")
@ApiImplicitParam(name = "payChannelDTO", value = "支付通道对象", required = true)
public void updatePayChannel(@RequestBody PayChannelDTO payChannelDTO) {
Boolean flag = this.payChannelService.updatePayChannel(payChannelDTO);
if (flag) {
return;
}
throw new SLException("修改支付通道失败", HttpStatus.INTERNAL_SERVER_ERROR.value());
}
/**
* 删除支付通道
*
* @param payChannelDTO 查询对象
*/
@DeleteMapping
@ApiOperation(value = "删除支付通道", notes = "删除支付通道")
@ApiImplicitParam(name = "payChannelDTO", value = "支付通道查询对象", required = true)
public void deletePayChannel(@RequestBody PayChannelDTO payChannelDTO) {
String[] checkedIds = payChannelDTO.getCheckedIds();
Boolean flag = this.payChannelService.deletePayChannel(checkedIds);
if (flag) {
return;
}
throw new SLException("删除支付通道失败", HttpStatus.INTERNAL_SERVER_ERROR.value());
}
@PutMapping("update-payChannel-enableFlag")
@ApiOperation(value = "修改支付通道状态", notes = "修改支付通道状态")
@ApiImplicitParam(name = "payChannelDTO", value = "支付通道查询对象", required = true)
public void updatePayChannelEnableFlag(@RequestBody PayChannelDTO payChannelDTO) {
Boolean flag = this.payChannelService.updatePayChannel(payChannelDTO);
if (flag) {
return;
}
throw new SLException("修改支付通道状态失败", HttpStatus.INTERNAL_SERVER_ERROR.value());
}
}
3.3、测试
通过swagger接口进行测试:http://192.168.150.101:18096/doc.html
其他的方法就不进行测试了,同学们可以自行测试。
4、扫码支付【阅读代码】
扫码支付的基本原理就是通过调用支付平台的接口,提交支付请求,支付平台会返回支付链接,将此支付链接生成二维码,用户通过手机上的支付宝或微信进行扫码支付。流程如下:
4.1、交易单表结构
【交易单表 sl_trading】是指,针对于订单进行支付的记录表,其中记录了订单号,支付状态、支付平台、金额、是否有退款等信息。具体表结构如下:
4.2、代码流程
下面展现了整体的扫描支付代码调用流程,我们将按照下面的流程进行代码的阅读。
## 4.3、幂等性处理
在向支付平台申请支付之前对交易单对象做幂等性处理,主要是防止重复的生成交易单以及一些业务逻辑的处理,具体是在com.sl.ms.trade.handler.impl.BeforePayHandlerImpl#idempotentCreateTrading()
方法中完成的。
其代码如下:
@Override
public void idempotentCreateTrading(TradingEntity tradingEntity) throws SLException {
TradingEntity trading = tradingService.findTradByProductOrderNo(tradingEntity.getProductOrderNo());
if (ObjectUtil.isEmpty(trading)) {
//新交易单,生成交易号
Long id = Convert.toLong(identifierGenerator.nextId(tradingEntity));
tradingEntity.setId(id);
tradingEntity.setTradingOrderNo(id);
return;
}
TradingStateEnum tradingState = trading.getTradingState();
if (ObjectUtil.equalsAny(tradingState, TradingStateEnum.YJS, TradingStateEnum.MD)) {
//已结算、免单:直接抛出重复支付异常
throw new SLException(TradingEnum.TRADING_STATE_SUCCEED);
} else if (ObjectUtil.equals(TradingStateEnum.FKZ, tradingState)) {
//付款中,如果支付渠道一致,说明是重复,抛出支付中异常,否则需要更换支付渠道
//举例:第一次通过支付宝付款,付款中用户取消,改换了微信支付
if (StrUtil.equals(trading.getTradingChannel(), tradingEntity.getTradingChannel())) {
throw new SLException(TradingEnum.TRADING_STATE_PAYING);
} else {
tradingEntity.setId(trading.getId()); // id设置为原订单的id
//重新生成交易号,在这里就会出现id 与 TradingOrderNo 数据不同的情况,其他情况下是一样的
tradingEntity.setTradingOrderNo(Convert.toLong(identifierGenerator.nextId(tradingEntity)));
}
} else if (ObjectUtil.equalsAny(tradingState, TradingStateEnum.QXDD, TradingStateEnum.GZ)) {
//取消订单,挂账:创建交易号,对原交易单发起支付
tradingEntity.setId(trading.getId()); // id设置为原订单的id
//重新生成交易号,在这里就会出现id 与 TradingOrderNo 数据不同的情况,其他情况下是一样的
tradingEntity.setTradingOrderNo(Convert.toLong(identifierGenerator.nextId(tradingEntity)));
} else {
//其他情况:直接交易失败
throw new SLException(TradingEnum.PAYING_TRADING_FAIL);
}
}
在此代码中,主要是逻辑是:
- 如果根据订单号查询交易单数据,如果不存在说明新交易单,生成交易单号后直接返回,这里的交易单号也是使用雪花id。
- 如果支付状态是已经【支付成功】或是【免单 - 不需要支付】,直接抛出异常。
- 如果支付状态是【付款中】,此时有两种情况
- 如果支付渠道相同(此前使用支付宝付款,本次也是使用支付宝付款),这种情况抛出异常
- 如果支付渠道不同,我们是允许在生成二维码后更换支付渠道,此时需要重新生成交易单号,此时交易单号与id将不同。
- 如果支付状态是【取消订单】或【挂账】,将id设置为原交易号,交易号重新生成,这样做的目的是既保留了原订单的交易号,又可以生成新的交易号(不重新生成的话,没有办法在支付平台进行支付申请),与之前不会有影响。
4.4、HandlerFactory
对于NativePayHandler会有不同平台的实现,比如:支付宝、微信,每个平台的接口参数、返回值都不一样,所以是没有办法共用的,只要是每个平台都去编写一个实现类。
那问题来了,我们该如何选择呢?
在这里我们采用了工厂模式进行获取对应的NativePayHandler实例,在不同的渠道实现类中,都指定了@PayChannel
注解,通过type
属性指定具体的平台(支付宝/微信):
有了这个注解标识后,在HandlerFactory中就可以根据指定的参数获取对应的渠道实现。
核心代码如下:
public static <T> T get(PayChannelEnum payChannel, Class<T> handler) {
Map<String, T> beans = SpringUtil.getBeansOfType(handler);
for (Map.Entry<String, T> entry : beans.entrySet()) {
PayChannel payChannelAnnotation = entry.getValue().getClass().getAnnotation(PayChannel.class);
if (ObjectUtil.isNotEmpty(payChannelAnnotation) && ObjectUtil.equal(payChannel, payChannelAnnotation.type())) {
return entry.getValue();
}
}
return null;
}
使用:
4.4、生成二维码
支付宝或微信的扫码支付返回是一个链接,并不是二维码,所以我们需要根据链接生成二维码,生成二维码的库使用的是:(最终生成的二维码图片使用的base64字符串返回给前端)
具体代码实现:
package com.sl.ms.trade.service.impl;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.sl.ms.trade.config.QRCodeConfig;
import com.sl.ms.trade.enums.PayChannelEnum;
import com.sl.ms.trade.service.QRCodeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class QRCodeServiceImpl implements QRCodeService {
@Resource
private QRCodeConfig qrCodeConfig;
@Override
public String generate(String content, PayChannelEnum payChannel) {
QrConfig qrConfig = new QrConfig();
//设置边距
qrConfig.setMargin(this.qrCodeConfig.getMargin());
//二维码颜色
qrConfig.setForeColor(HexUtil.decodeColor(this.qrCodeConfig.getForeColor()));
//设置背景色
qrConfig.setBackColor(HexUtil.decodeColor(this.qrCodeConfig.getBackColor()));
//纠错级别
qrConfig.setErrorCorrection(ErrorCorrectionLevel.valueOf(this.qrCodeConfig.getErrorCorrectionLevel()));
//设置宽
qrConfig.setWidth(this.qrCodeConfig.getWidth());
//设置高
qrConfig.setHeight(this.qrCodeConfig.getHeight());
if (ObjectUtil.isNotEmpty(payChannel)) {
//设置logo
qrConfig.setImg(this.qrCodeConfig.getLogo(payChannel));
}
return QrCodeUtil.generateAsBase64(content, qrConfig, ImgUtil.IMAGE_TYPE_PNG);
}
@Override
public String generate(String content) {
return generate(content, null);
}
}
具体的配置存储在nacos中:
#二维码配置
#边距,二维码和背景之间的边距
qrcode.margin = 2
#二维码颜色,默认黑色
qrcode.fore-color = #000000
#背景色,默认白色
qrcode.back-color = #ffffff
#低级别的像素块更大,可以远距离识别,但是遮挡就会造成无法识别。高级别则相反,像素块小,允许遮挡一定范围,但是像素块更密集。
#纠错级别,可选参数:L、M、Q、H,默认:M
qrcode.error-correction-level = M
#宽
qrcode.width = 300
#高
qrcode.height = 300
配置的映射类:
package com.sl.ms.trade.config;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import com.sl.ms.trade.enums.PayChannelEnum;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.awt.*;
/**
* 二维码生成参数配置
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "sl.qrcode")
public class QRCodeConfig {
private static Image WECHAT_LOGO;
private static Image ALIPAY_LOGO;
static {
WECHAT_LOGO = ImgUtil.read(ResourceUtil.getResource("logos/wechat.png"));
ALIPAY_LOGO = ImgUtil.read(ResourceUtil.getResource("logos/alipay.png"));
}
//边距,二维码和背景之间的边距
private Integer margin = 2;
// 二维码颜色,默认黑色
private String foreColor = "#000000";
//背景色,默认白色
private String backColor = "#ffffff";
//纠错级别,可选参数:L、M、Q、H,默认:M
//低级别的像素块更大,可以远距离识别,但是遮挡就会造成无法识别。高级别则相反,像素块小,允许遮挡一定范围,但是像素块更密集。
private String errorCorrectionLevel = "M";
//宽
private Integer width = 300;
//高
private Integer height = 300;
public Image getLogo(PayChannelEnum payChannelEnum) {
switch (payChannelEnum) {
case ALI_PAY: {
return ALIPAY_LOGO;
}
case WECHAT_PAY: {
return WECHAT_LOGO;
}
default: {
return null;
}
}
}
}
生成的效果:
以上二维码对应的base64字符串如下:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAXL0lEQVR4Xu2UwYokuxbE7v//9Hvr0mJEkA5st49AmwERPjlN/fe/YRiGS/iP/zAMw3Aq84M1DMM1zA/WMAzXMD9YwzBcw/xgDcNwDfODNQzDNcwP1jAM1zA/WMMwXMP8YA3DcA3zgzUMwzXMD9YwDNcwP1jDMFzD/GANw3AN84M1DMM1zA/WMAzXMD9YwzBcw/xgDcNwDfODNQzDNcwP1jAM1zA/WMMwXMP8YA3DcA3zgzUMwzXMD9YwDNdQ/8H677//xoWmsDdPg+8zU9iP32xTX+BB4zdT2JunwfeZKezHb7apL/Cg8Zsp7M3T4PvMFPbjN9vUF3jQ+M0U9uZp8H1mCvvxm23qCzxo/GYKe/M0+D4zhf34zTb1BR40fjOFvXkafJ+Zwn78Zpv6Ag8av5nC3jwNvs9MYT9+s019gQeN30xhb54G32emsB+/2aa+wIPGb6awN0+D7zNT2I/fbFNf4EHjN1PYm6fB95kp7Mdvtqkv8KDxmynszdPg+8wU9uM329QXeND4zRT25mnwfWYK+/GbbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMh8Dd5vtuHeak+D7zNfg/ebbeoLPMhMYb/bFPZmCnvzNPg+M4W9mcJ+tynszTb1BR5kprDfbQp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wnxtrTCv9Ma9gQMprTBfWyvMK8cG51daYV5phfnaWmFe6Y17AwdSWmG+tlaYV44Nzq+0wrzSCvO1tcK80hv3Bg6ktMJ8ba0wrxwbnF9phXmlFeZra4V5pTfuDRxIaYX52lphXjk2OL/SCvNKK8zX1grzSm/cGziQ0grztbXCvHJscH6lFeaVVpivrRXmld64N3AgpRXma2uFeeXY4PxKK8wrrTBfWyvMK71xb+BASivM19YK88qxwfmVVphXWmG+tlaYV3rj3sCBlFaYr60V5pXesG9oWmFeaYX52lphXumNewMHUlphvrZWmFd6w76haYV5pRXma2uFeaU37g0cSGmF+dpaYV7pDfuGphXmlVaYr60V5pXeuDdwIKUV5mtrhXmlN+wbmlaYV1phvrZWmFd6497AgZRWmK+tFeaV3rBvaFphXmmF+dpaYV7pjXsDB1JaYb62VphXesO+oWmFeaUV5mtrhXmlN+4NHEhphfnaWmFe6Q37hqYV5pVWmK+tFeaV3rg3cCClFeZra4V5pTfsG5pWmFdaYb62VphXeuPewIGUVpivrRXmld6wb2haYV5phfnaWmFe6Y17AwdSWmG+tlaYV3rDvqFphXmlFeZra4V5pTfuDRxIaYX52lphXukN+4amFeaVVpivrRXmld64N3AgpRXma2uFeaU37BuaVphXWmG+tlaYV3rj3sCBlGOD8yutMF/bvsH1KccG51d6497AgZRjg/MrrTBf277B9SnHBudXeuPewIGUY4PzK60wX9u+wfUpxwbnV3rj3sCBlGOD8yutMF/bvsH1KccG51d6497AgZRjg/MrrTBf277B9SnHBudXeuPewIGUY4PzK60wX9u+wfUpxwbnV3rj3sCBlGOD8yutMF/bvsH1KccG51d6497AgZRjg/MrrTBf277B9SnHBudXeuPewIGUY4PzK60wX9u+wfUpxwbnV3rj3sCBlGOD8yutMF/bvsH1KccG51d6497AgZRjg/MrrTBf277B9SnHBudXeuPewIGUY4PzK60wX9u+wfUpxwbnV3rj3sCBwm5aYV5phXmlFeaVVpgPu+mNewMHCrtphXmlFeaVVphXWmE+7KY37g0cKOymFeaVVphXWmFeaYX5s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EBKM8C91Jmw/pKF+aU2bC+cnU4rzIb1o+6EiXT8ADaXRfmlKvDeaO6MKd0YS7q6nBeZQUlXbhYu+vCnHJ1OG9UF+aULsxFXR3Oq6ygpAsXa3ddmFOuDueN6sKc0oW5qKvDeZUVlHThYu2uC3PK1eG8UV2YU7owF3V1OK+ygpIuXKzddWFOuTqcN6oLc0oX5qKuDudVVlDShYu1uy7MKVeH80Z1YU7pwlzU1eG8ygpKunCxdteFOeXqcN6oLswpXZiLujqcV1lBSRcu1u66MKdcHc4b1YU5pQtzUVeH8yorKOnCxdpdF+aUq8N5o7owp3RhLurqcF5lBSVduFi768KccnU4b1QX5pQuzEVdHc6rrKCmS9M0TQJ9YTVNcxj6wmqa5jD0hdU0zWHoC6tpmsPQF1bTNIehL6ymaQ5DX1hN0xyGvrCapjkMfWE1TXMY+sJqmuYw9IXVNM1h6AuraZrD0BdW0zSHoS+spmkOQ19YTdMchr6wmqY5DH1hNU1zGPrCaprmMPSF1TTNYegLq2maw9AXVtM0h6EvrKZpDkNfWE3THIa+sJqmOQz/F5SAXTtwa9usAAAAAElFTkSuQmCC
在线base64转图片工具:
4.5、测试
{
"enterpriseId": 2088241317544335,
"memo": "运费",
"productOrderNo": 11112241,
"tradingAmount": 1,
"tradingChannel": "ALI_PAY"
}
{
"qrCode": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAosklEQVR4Xu3decyt+1nW8f7fPxwRp4hTEIcIKsYhBoc4RnOKGhNNxCqJmBgTMdaWkrZIsQOUoYJCT1GkFCgEpDS0CC2DFAKSMjpQZhBKQlugUEsr0PbxPHux7DqfPVzn1/t+hrX2802+KZxz7eu+f8973l/ed+213/2k6eDg4OBKeJL/4ODg4GCvHBfWwcHB1XBcWAcHB1fDcWEdHBxcDceFdXBwcDUcF9bBwcHVcFxYBwcHV8NxYR0cHFwNx4V1cHBwNRwX1sHBwdVwXFgHBwdXw3FhHRwcXA3HhXVwcHA1HBfWwcHB1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qaXFD3jvtqFftGTZjXhHlNmNeE+bVdGudpFfv2ZhdtTS6oe8d9tYp9oybMa8K8JsxrwvzaLo3ztIp9e7OLtiYX1L3jvlrFvlET5jVhXhPmNWF+bZfGeVrFvr3ZRVuTC96aCfOjJsxrFfs0YV4T5td2a9xHq9jX7Vq0TfIAt2bC/KgJ81rFPk2Y14T5td0a99Eq9nW7Fm2TPMCtmTA/asK8VrFPE+Y1YX5tt8Z9tIp93a5F2yQPcGsmzI+aMK9V7NOEeU2YX9utcR+tYl+3a9E2yQPcmgnzoybMaxX7NGFeE+bXdmvcR6vY1+1atE3yALdmwvyoCfNaxT5NmNeE+bXdGvfRKvZ1uxZtkzzArZkwP2rCvFaxTxPmNWF+bbfGfbSKfd2uRdskD3BrJsyPmjCvVezThHlNmF/brXEfrWJft2ux3qSDg4ODIseFdXBwcDUcF9bBwcHVcFxYBwcHV8NxYR0cHFwNx4V1cHBwNRwX1sHBwdVwXFgHBwdXw3FhHRwcXA3HhXVwcHA1HBfWwcHB1XBcWAcHB1fDcWEdHBxcDceFdXBwcDUcF9bBwcHVcFxYBwcHV8NxYR0cHFwNx4V1cHBwNfw/rGWA53Vvd8cAAAAASUVORK5CYII=",
"productOrderNo": "11112241",
"tradingOrderNo": "1559096271641808897",
"tradingChannel": "ALI_PAY"
}
4.6、优化(练习)
在生成二维码时,我们采用的是服务端生成二维码方式,这种方式会比较消耗服务器的CPU、内存资源,比较好的做法是生成二维码的动作交由客户端(前端)来生成。
实际上,我们前端已经做了兼容处理,在返回的【qrCode】字段中,如果内容以【data:image/png;】开头,直接展现,否则就将返回的数据(支付宝或微信返回的原始数据,例如:https://qr.alipay.com/bax034140c7lyawo6oiy55f2)生成二维码。
这个优化交由学生来完成。
4.7、支付宝扫码支付
4.7.1、AlipayConfig
在项目中,通com.sl.ms.trade.handler.alipay.AlipayConfig#getConfig(Long enterpriseId)
方法可以按照商户id查询支付宝的配置,如果配置查询不到会抛出异常。
代码如下:
package com.sl.ms.trade.handler.alipay;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alipay.easysdk.kernel.Config;
import com.sl.ms.trade.constant.TradingConstant;
import com.sl.ms.trade.entity.PayChannelEntity;
import com.sl.ms.trade.enums.TradingEnum;
import com.sl.ms.trade.service.PayChannelService;
import com.sl.transport.common.exception.SLException;
/**
* 支付宝支付的配置
*/
public class AlipayConfig {
/**
* 将支付渠道配置转化为支付宝的配置
*
* @param enterpriseId 商户ID
* @return 支付宝的配置
*/
public static Config getConfig(Long enterpriseId) {
// 查询配置
PayChannelService payChannelService = SpringUtil.getBean(PayChannelService.class);
PayChannelEntity payChannel = payChannelService.findByEnterpriseId(enterpriseId, TradingConstant.TRADING_CHANNEL_ALI_PAY);
if (ObjectUtil.isEmpty(payChannel)) {
throw new SLException(TradingEnum.CONFIG_EMPTY);
}
Config config = new Config();
config.protocol = "https";
config.gatewayHost = payChannel.getDomain();
config.signType = "RSA2";
config.appId = payChannel.getAppId();
//配置应用私钥
config.merchantPrivateKey = payChannel.getMerchantPrivateKey();
//配置支付宝公钥
config.alipayPublicKey = payChannel.getPublicKey();
//可设置异步通知接收服务地址(可选)
config.notifyUrl = StrUtil.replace(payChannel.getNotifyUrl(), "{enterpriseId}", Convert.toStr(enterpriseId));
//设置AES密钥,调用AES加解密相关接口时需要(可选)
config.encryptKey = payChannel.getEncryptKey();
return config;
}
}
关于异步通知的url的说明:
数据库表中存储的数据类似这样:[https://61d25503.cpolar.cn/trade/notify/alipay/{enterpriseId}](https://61d25503.cpolar.cn/trade/notify/alipay/{enterpriseId})
其中,61d25503.cpolar.cn
这个域名是内网穿透的地址,后面会将,暂时忽略。{enterpriseId}
这个是占位符,在真正设置值时,会用【商户id】进行替换,最终的通知地址类似:[https://61d25503.cpolar.cn/trade/notify/alipay/2088241317544335](https://61d25503.cpolar.cn/trade/notify/alipay/2088241317544335)
4.7.2、具体实现
package com.sl.ms.trade.handler.alipay;
import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.sl.ms.trade.annotation.PayChannel;
import com.sl.ms.trade.entity.TradingEntity;
import com.sl.ms.trade.enums.PayChannelEnum;
import com.sl.ms.trade.enums.TradingEnum;
import com.sl.ms.trade.enums.TradingStateEnum;
import com.sl.ms.trade.handler.NativePayHandler;
import com.sl.transport.common.exception.SLException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 支付宝的扫描支付的具体实现
*/
@Slf4j
@Component("aliNativePayHandler")
@PayChannel(type = PayChannelEnum.ALI_PAY)
public class AliNativePayHandler implements NativePayHandler {
@Override
public void createDownLineTrading(TradingEntity tradingEntity) throws SLException {
//查询配置
Config config = AlipayConfig.getConfig(tradingEntity.getEnterpriseId());
//Factory使用配置
Factory.setOptions(config);
AlipayTradePrecreateResponse response;
try {
//调用支付宝API面对面支付
response = Factory
.Payment
.FaceToFace()
.preCreate(tradingEntity.getMemo(), //订单描述
Convert.toStr(tradingEntity.getTradingOrderNo()), //业务订单号
Convert.toStr(tradingEntity.getTradingAmount())); //金额
} catch (Exception e) {
log.error("支付宝统一下单创建失败:tradingEntity = {}", tradingEntity, e);
throw new SLException(TradingEnum.NATIVE_PAY_FAIL, e);
}
//受理结果【只表示请求是否成功,而不是支付是否成功】
boolean isSuccess = ResponseChecker.success(response);
//6.1、受理成功:修改交易单
if (isSuccess) {
String subCode = response.getSubCode();
String subMsg = response.getQrCode();
tradingEntity.setPlaceOrderCode(subCode); //返回的编码
tradingEntity.setPlaceOrderMsg(subMsg); //二维码需要展现的信息
tradingEntity.setPlaceOrderJson(JSONUtil.toJsonStr(response));
tradingEntity.setTradingState(TradingStateEnum.FKZ);
return;
}
throw new SLException(JSONUtil.toJsonStr(response), TradingEnum.NATIVE_PAY_FAIL.getCode(), TradingEnum.NATIVE_PAY_FAIL.getStatus());
}
}
4.8、微信扫码支付
4.8.1、SDK二次封装
在sl_pay_channel表中已经提供了微信对接的相关信息。
package com.sl.ms.trade.handler.wechat;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath;
import cn.hutool.core.net.url.UrlQuery;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sl.ms.trade.constant.TradingConstant;
import com.sl.ms.trade.entity.PayChannelEntity;
import com.sl.ms.trade.enums.TradingEnum;
import com.sl.ms.trade.handler.wechat.response.WeChatResponse;
import com.sl.ms.trade.service.PayChannelService;
import com.sl.transport.common.exception.SLException;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.ByteArrayInputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.util.Map;
/**
* 微信支付远程调用对象
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WechatPayHttpClient {
private String mchId; //商户号
private String appId; //应用号
private String privateKey; //私钥字符串
private String mchSerialNo; //商户证书序列号
private String apiV3Key; //V3密钥
private String domain; //请求域名
private String notifyUrl; //请求地址
public static WechatPayHttpClient get(Long enterpriseId) {
// 查询配置
PayChannelService payChannelService = SpringUtil.getBean(PayChannelService.class);
PayChannelEntity payChannel = payChannelService.findByEnterpriseId(enterpriseId, TradingConstant.TRADING_CHANNEL_WECHAT_PAY);
if (ObjectUtil.isEmpty(payChannel)) {
throw new SLException(TradingEnum.CONFIG_EMPTY);
}
//通过渠道对象转化成微信支付的client对象
JSONObject otherConfig = JSONUtil.parseObj(payChannel.getOtherConfig());
return WechatPayHttpClient.builder()
.appId(payChannel.getAppId())
.domain(payChannel.getDomain())
.privateKey(payChannel.getMerchantPrivateKey())
.mchId(otherConfig.getStr("mchId"))
.mchSerialNo(otherConfig.getStr("mchSerialNo"))
.apiV3Key(otherConfig.getStr("apiV3Key"))
.notifyUrl(payChannel.getNotifyUrl())
.build();
}
/***
* 构建CloseableHttpClient远程请求对象
* @return org.apache.http.impl.client.CloseableHttpClient
*/
public CloseableHttpClient createHttpClient() throws Exception {
// 加载商户私钥(privateKey:私钥字符串)
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes(StandardCharsets.UTF_8)));
// 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3密钥)
PrivateKeySigner privateKeySigner = new PrivateKeySigner(mchSerialNo, merchantPrivateKey);
WechatPay2Credentials wechatPay2Credentials = new WechatPay2Credentials(mchId, privateKeySigner);
// 向证书管理器增加需要自动更新平台证书的商户信息
CertificatesManager certificatesManager = CertificatesManager.getInstance();
certificatesManager.putMerchant(mchId, wechatPay2Credentials, apiV3Key.getBytes(StandardCharsets.UTF_8));
// 初始化httpClient
return com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder.create()
.withMerchant(mchId, mchSerialNo, merchantPrivateKey)
.withValidator(new WechatPay2Validator(certificatesManager.getVerifier(mchId)))
.build();
}
/***
* 支持post请求的远程调用
*
* @param apiPath api地址
* @param params 携带请求参数
* @return 返回字符串
*/
public WeChatResponse doPost(String apiPath, Map<String, Object> params) throws Exception {
String url = StrUtil.format("https://{}{}", this.domain, apiPath);
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
String body = JSONUtil.toJsonStr(params);
httpPost.setEntity(new StringEntity(body, CharsetUtil.UTF_8));
CloseableHttpResponse response = this.createHttpClient().execute(httpPost);
return new WeChatResponse(response);
}
/***
* 支持get请求的远程调用
* @param apiPath api地址
* @param params 在路径中请求的参数
* @return 返回字符串
*/
public WeChatResponse doGet(String apiPath, Map<String, Object> params) throws Exception {
URI uri = UrlBuilder.create()
.setHost(this.domain)
.setScheme("https")
.setPath(UrlPath.of(apiPath, CharsetUtil.CHARSET_UTF_8))
.setQuery(UrlQuery.of(params))
.setCharset(CharsetUtil.CHARSET_UTF_8)
.toURI();
return this.doGet(uri);
}
/***
* 支持get请求的远程调用
* @param apiPath api地址
* @return 返回字符串
*/
public WeChatResponse doGet(String apiPath) throws Exception {
URI uri = UrlBuilder.create()
.setHost(this.domain)
.setScheme("https")
.setPath(UrlPath.of(apiPath, CharsetUtil.CHARSET_UTF_8))
.setCharset(CharsetUtil.CHARSET_UTF_8)
.toURI();
return this.doGet(uri);
}
private WeChatResponse doGet(URI uri) throws Exception {
HttpGet httpGet = new HttpGet(uri);
httpGet.addHeader("Accept", "application/json");
CloseableHttpResponse response = this.createHttpClient().execute(httpGet);
return new WeChatResponse(response);
}
}
代码说明:
- 通过
get(Long enterpriseId)
方法查询商户对应的配置信息,最后封装到WechatPayHttpClient
对象中。 - 通过
createHttpClient()
方法封装了请求微信接口必要的参数,最后返回CloseableHttpClient
对象。 - 封装了
doGet()、doPost()
方便对微信接口进行调用。
4.8.2、具体实现
package com.sl.ms.trade.handler.wechat;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil;
import com.sl.ms.trade.annotation.PayChannel;
import com.sl.ms.trade.entity.TradingEntity;
import com.sl.ms.trade.enums.PayChannelEnum;
import com.sl.ms.trade.enums.TradingEnum;
import com.sl.ms.trade.enums.TradingStateEnum;
import com.sl.ms.trade.handler.NativePayHandler;
import com.sl.ms.trade.handler.wechat.response.WeChatResponse;
import com.sl.ms.trade.service.PayChannelService;
import com.sl.transport.common.exception.SLException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
/**
* 微信二维码支付
*/
@Component("wechatNativePayHandler")
@PayChannel(type = PayChannelEnum.WECHAT_PAY)
public class WechatNativePayHandler implements NativePayHandler {
@Override
public void createDownLineTrading(TradingEntity tradingEntity) throws SLException {
// 查询配置
WechatPayHttpClient client = WechatPayHttpClient.get(tradingEntity.getEnterpriseId());
//请求地址
String apiPath = "/v3/pay/transactions/native";
//请求参数
Map<String, Object> params = MapUtil.<String, Object>builder()
.put("mchid", client.getMchId())
.put("appid", client.getAppId())
.put("description", tradingEntity.getMemo())
.put("notify_url", client.getNotifyUrl())
.put("out_trade_no", Convert.toStr(tradingEntity.getTradingOrderNo()))
.put("amount", MapUtil.<String, Object>builder()
.put("total", Convert.toInt(NumberUtil.mul(tradingEntity.getTradingAmount(), 100))) //金额,单位:分
.put("currency", "CNY") //人民币
.build())
.build();
try {
WeChatResponse response = client.doPost(apiPath, params);
if (!response.isOk()) {
//下单失败
throw new SLException(TradingEnum.NATIVE_PAY_FAIL);
}
//指定统一下单code
tradingEntity.setPlaceOrderCode(Convert.toStr(response.getStatus()));
//二维码需要展现的信息
tradingEntity.setPlaceOrderMsg(JSONUtil.parseObj(response.getBody()).getStr("code_url"));
//指定统一下单json字符串
tradingEntity.setPlaceOrderJson(JSONUtil.toJsonStr(response));
//指定交易状态
tradingEntity.setTradingState(TradingStateEnum.FKZ);
} catch (Exception e) {
throw new SLException(TradingEnum.NATIVE_PAY_FAIL);
}
}
}
5、基础服务【阅读代码】
在支付宝或微信平台中,支付方式是多种多样的,对于一些服务而言是通用的,比如:查询交易单、退款、查询退款等,所以我们将基于这些通用的接口封装基础服务。
5.1、查询交易
用户创建交易后,到底有没有支付成功,还是取消支付,这个可以通过查询交易单接口查询的,支付宝和微信也都提供了这样的接口服务。
5.1.1、Controller
/***
* 统一收单线下交易查询
* 该接口提供所有支付订单的查询,商户可以通过该接口主动查询订单状态,完成下一步的业务逻辑。
*
* @param tradingOrderNo 交易单号
* @return 交易单
*/
@PostMapping("query/{tradingOrderNo}")
@ApiOperation(value = "查询统一收单线下交易", notes = "查询统一收单线下交易")
@ApiImplicitParam(name = "tradingOrderNo", value = "交易单", required = true)
public TradingDTO queryTrading(@PathVariable("tradingOrderNo") Long tradingOrderNo) {
return this.basicPayService.queryTrading(tradingOrderNo);
}
5.1.2、Service
在Service中实现了交易单查询的逻辑,代码结构与扫描支付类似。具体与支付平台的对接由BasicPayHandler完成。
@Override
public TradingDTO queryTrading(Long tradingOrderNo) throws SLException {
//通过单号查询交易单数据
TradingEntity trading = this.tradingService.findTradByTradingOrderNo(tradingOrderNo);
//查询前置处理:检测交易单参数
this.beforePayHandler.checkQueryTrading(trading);
String key = TradingCacheConstant.QUERY_PAY + tradingOrderNo;
RLock lock = redissonClient.getFairLock(key);
try {
//获取锁
if (lock.tryLock(TradingCacheConstant.REDIS_WAIT_TIME, TimeUnit.SECONDS)) {
//选取不同的支付渠道实现
BasicPayHandler handler = HandlerFactory.get(trading.getTradingChannel(), BasicPayHandler.class);
Boolean result = handler.queryTrading(trading);
if (result) {
//如果交易单已经完成,需要将二维码数据删除,节省数据库空间,如果有需要可以再次生成
if (ObjectUtil.equalsAny(trading.getTradingState(), TradingStateEnum.YJS, TradingStateEnum.QXDD)) {
trading.setQrCode("");
}
//更新数据
this.tradingService.saveOrUpdate(trading);
}
return BeanUtil.toBean(trading, TradingDTO.class);
}
throw new SLException(TradingEnum.NATIVE_QUERY_FAIL);
} catch (SLException e) {
throw e;
} catch (Exception e) {
log.error("查询交易单数据异常: trading = {}", trading, e);
throw new SLException(TradingEnum.NATIVE_QUERY_FAIL);
} finally {
lock.unlock();
}
}
5.1.3、支付宝实现
@Override
public Boolean queryTrading(TradingEntity trading) throws SLException {
//查询配置
Config config = AlipayConfig.getConfig(trading.getEnterpriseId());
//Factory使用配置
Factory.setOptions(config);
AlipayTradeQueryResponse queryResponse;
try {
//调用支付宝API:通用查询支付情况
queryResponse = Factory
.Payment
.Common()
.query(String.valueOf(trading.getTradingOrderNo()));
} catch (Exception e) {
String msg = StrUtil.format("查询支付宝统一下单失败:trading = {}", trading);
log.error(msg, e);
throw new SLException(msg, TradingEnum.NATIVE_QUERY_FAIL.getCode(), TradingEnum.NATIVE_QUERY_FAIL.getStatus());
}
//修改交易单状态
trading.setResultCode(queryResponse.getSubCode());
trading.setResultMsg(queryResponse.getSubMsg());
trading.setResultJson(JSONUtil.toJsonStr(queryResponse));
boolean success = ResponseChecker.success(queryResponse);
//响应成功,分析交易状态
if (success) {
String tradeStatus = queryResponse.getTradeStatus();
if (StrUtil.equals(TradingConstant.ALI_TRADE_CLOSED, tradeStatus)) {
//支付取消:TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)
trading.setTradingState(TradingStateEnum.QXDD);
} else if (StrUtil.equalsAny(tradeStatus, TradingConstant.ALI_TRADE_SUCCESS, TradingConstant.ALI_TRADE_FINISHED)) {
// TRADE_SUCCESS(交易支付成功)
// TRADE_FINISHED(交易结束,不可退款)
trading.setTradingState(TradingStateEnum.YJS);
} else {
//非最终状态不处理,当前交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)不处理
return false;
}
return true;
}
throw new SLException(trading.getResultJson(), TradingEnum.NATIVE_QUERY_FAIL.getCode(), TradingEnum.NATIVE_QUERY_FAIL.getStatus());
}
5.1.4、微信支付实现
@Override
public Boolean queryTrading(TradingEntity trading) throws SLException {
// 获取微信支付的client对象
WechatPayHttpClient client = WechatPayHttpClient.get(trading.getEnterpriseId());
//请求地址
String apiPath = StrUtil.format("/v3/pay/transactions/out-trade-no/{}", trading.getTradingOrderNo());
//请求参数
Map<String, Object> params = MapUtil.<String, Object>builder()
.put("mchid", client.getMchId())
.build();
WeChatResponse response;
try {
response = client.doGet(apiPath, params);
} catch (Exception e) {
log.error("调用微信接口出错!apiPath = {}, params = {}", apiPath, JSONUtil.toJsonStr(params), e);
throw new SLException(NATIVE_REFUND_FAIL, e);
}
if (response.isOk()) {
JSONObject jsonObject = JSONUtil.parseObj(response.getBody());
// 交易状态,枚举值:
// SUCCESS:支付成功
// REFUND:转入退款
// NOTPAY:未支付
// CLOSED:已关闭
// REVOKED:已撤销(仅付款码支付会返回)
// USERPAYING:用户支付中(仅付款码支付会返回)
// PAYERROR:支付失败(仅付款码支付会返回)
String tradeStatus = jsonObject.getStr("trade_state");
if (StrUtil.equalsAny(tradeStatus, TradingConstant.WECHAT_TRADE_CLOSED, TradingConstant.WECHAT_TRADE_REVOKED)) {
trading.setTradingState(TradingStateEnum.QXDD);
} else if (StrUtil.equalsAny(tradeStatus, TradingConstant.WECHAT_REFUND_SUCCESS, TradingConstant.WECHAT_TRADE_REFUND)) {
trading.setTradingState(TradingStateEnum.YJS);
} else if (StrUtil.equalsAny(tradeStatus, TradingConstant.WECHAT_TRADE_NOTPAY)) {
//如果是未支付,需要判断下时间,超过2小时未知的订单需要关闭订单以及设置状态为QXDD
long between = LocalDateTimeUtil.between(trading.getCreated(), LocalDateTimeUtil.now(), ChronoUnit.HOURS);
if (between >= 2) {
return this.closeTrading(trading);
}
} else {
//非最终状态不处理
return false;
}
//修改交易单状态
trading.setResultCode(tradeStatus);
trading.setResultMsg(jsonObject.getStr("trade_state_desc"));
trading.setResultJson(response.getBody());
return true;
}
throw new SLException(response.getBody(), NATIVE_REFUND_FAIL.getCode(), NATIVE_REFUND_FAIL.getCode());
}
5.2、退款
5.2.1、Controller
/***
* 统一收单交易退款接口
* 当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,
* 将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。
* @param tradingOrderNo 交易单号
* @param refundAmount 退款金额
* @return
*/
@PostMapping("refund")
@ApiOperation(value = "统一收单交易退款", notes = "统一收单交易退款")
@ApiImplicitParams({
@ApiImplicitParam(name = "tradingOrderNo", value = "交易单号", required = true),
@ApiImplicitParam(name = "refundAmount", value = "退款金额", required = true)
})
public void refundTrading(@RequestParam("tradingOrderNo") Long tradingOrderNo,
@RequestParam("refundAmount") BigDecimal refundAmount) {
Boolean result = this.basicPayService.refundTrading(tradingOrderNo, refundAmount);
if (!result) {
throw new SLException(TradingEnum.BASIC_REFUND_COUNT_OUT_FAIL);
}
}
5.2.2、Service
@Override
@Transactional
public Boolean refundTrading(Long tradingOrderNo, BigDecimal refundAmount) throws SLException {
//通过单号查询交易单数据
TradingEntity trading = this.tradingService.findTradByTradingOrderNo(tradingOrderNo);
//设置退款金额
trading.setRefund(NumberUtil.add(refundAmount, trading.getRefund()));
//入库前置检查
this.beforePayHandler.checkRefundTrading(trading);
String key = TradingCacheConstant.REFUND_PAY + tradingOrderNo;
RLock lock = redissonClient.getFairLock(key);
try {
//获取锁
if (lock.tryLock(TradingCacheConstant.REDIS_WAIT_TIME, TimeUnit.SECONDS)) {
//幂等性的检查
RefundRecordEntity refundRecord = this.beforePayHandler.idempotentRefundTrading(trading, refundAmount);
if (null == refundRecord) {
return false;
}
//选取不同的支付渠道实现
BasicPayHandler handler = HandlerFactory.get(refundRecord.getTradingChannel(), BasicPayHandler.class);
Boolean result = handler.refundTrading(refundRecord);
if (result) {
//更新退款记录数据
this.refundRecordService.saveOrUpdate(refundRecord);
//设置交易单是退款订单
trading.setIsRefund(Constants.YES);
this.tradingService.saveOrUpdate(trading);
}
return true;
}
throw new SLException(TradingEnum.NATIVE_QUERY_FAIL);
} catch (SLException e) {
throw e;
} catch (Exception e) {
log.error("查询交易单数据异常:{}", ExceptionUtil.stacktraceToString(e));
throw new SLException(TradingEnum.NATIVE_QUERY_FAIL);
} finally {
lock.unlock();
}
}
5.2.3、支付宝实现
@Override
public Boolean refundTrading(RefundRecordEntity refundRecord) throws SLException {
//查询配置
Config config = AlipayConfig.getConfig(refundRecord.getEnterpriseId());
//Factory使用配置
Factory.setOptions(config);
//调用支付宝API:通用查询支付情况
AlipayTradeRefundResponse refundResponse;
try {
// 支付宝easy sdk
refundResponse = Factory
.Payment
.Common()
//扩展参数:退款单号
.optional("out_request_no", refundRecord.getRefundNo())
.refund(Convert.toStr(refundRecord.getTradingOrderNo()),
Convert.toStr(refundRecord.getRefundAmount()));
} catch (Exception e) {
String msg = StrUtil.format("调用支付宝退款接口出错!refundRecord = {}", refundRecord);
log.error(msg, e);
throw new SLException(msg, TradingEnum.NATIVE_REFUND_FAIL.getCode(), TradingEnum.NATIVE_REFUND_FAIL.getStatus());
}
refundRecord.setRefundCode(refundResponse.getSubCode());
refundRecord.setRefundMsg(JSONUtil.toJsonStr(refundResponse));
boolean success = ResponseChecker.success(refundResponse);
if (success) {
refundRecord.setRefundStatus(RefundStatusEnum.SUCCESS);
return true;
}
throw new SLException(refundRecord.getRefundMsg(), TradingEnum.NATIVE_REFUND_FAIL.getCode(), TradingEnum.NATIVE_REFUND_FAIL.getStatus());
}
5.2.4、微信实现
@Override
public Boolean refundTrading(RefundRecordEntity refundRecord) throws SLException {
// 获取微信支付的client对象
WechatPayHttpClient client = WechatPayHttpClient.get(refundRecord.getEnterpriseId());
//请求地址
String apiPath = "/v3/refund/domestic/refunds";
//请求参数
Map<String, Object> params = MapUtil.<String, Object>builder()
.put("out_refund_no", Convert.toStr(refundRecord.getRefundNo()))
.put("out_trade_no", Convert.toStr(refundRecord.getTradingOrderNo()))
.put("amount", MapUtil.<String, Object>builder()
.put("refund", NumberUtil.mul(refundRecord.getRefundAmount(), 100)) //本次退款金额
.put("total", NumberUtil.mul(refundRecord.getTotal(), 100)) //原订单金额
.put("currency", "CNY") //币种
.build())
.build();
WeChatResponse response;
try {
response = client.doPost(apiPath, params);
} catch (Exception e) {
log.error("调用微信接口出错!apiPath = {}, params = {}", apiPath, JSONUtil.toJsonStr(params), e);
throw new SLException(NATIVE_REFUND_FAIL, e);
}
refundRecord.setRefundCode(Convert.toStr(response.getStatus()));
refundRecord.setRefundMsg(response.getBody());
if (response.isOk()) {
JSONObject jsonObject = JSONUtil.parseObj(response.getBody());
// SUCCESS:退款成功
// CLOSED:退款关闭
// PROCESSING:退款处理中
// ABNORMAL:退款异常
String status = jsonObject.getStr("status");
if (StrUtil.equals(status, TradingConstant.WECHAT_REFUND_PROCESSING)) {
refundRecord.setRefundStatus(RefundStatusEnum.SENDING);
} else if (StrUtil.equals(status, TradingConstant.WECHAT_REFUND_SUCCESS)) {
refundRecord.setRefundStatus(RefundStatusEnum.SUCCESS);
} else {
refundRecord.setRefundStatus(RefundStatusEnum.FAIL);
}
return true;
}
throw new SLException(refundRecord.getRefundMsg(), NATIVE_REFUND_FAIL.getCode(), NATIVE_REFUND_FAIL.getStatus());
}
5.3、查询退款
5.3.1、Controller
/***
* 统一收单交易退款查询接口
* @param refundNo 退款交易单号
* @return
*/
@PostMapping("refund/{refundNo}")
@ApiOperation(value = "查询统一收单交易退款", notes = "查询统一收单交易退款")
@ApiImplicitParam(name = "refundNo", value = "退款交易单", required = true)
public RefundRecordDTO queryRefundDownLineTrading(@PathVariable("refundNo") Long refundNo) {
return this.basicPayService.queryRefundTrading(refundNo);
}
5.3.2、Service
@Override
public RefundRecordDTO queryRefundTrading(Long refundNo) throws SLException {
//通过单号查询交易单数据
RefundRecordEntity refundRecord = this.refundRecordService.findByRefundNo(refundNo);
//查询前置处理
this.beforePayHandler.checkQueryRefundTrading(refundRecord);
String key = TradingCacheConstant.REFUND_QUERY_PAY + refundNo;
RLock lock = redissonClient.getFairLock(key);
try {
//获取锁
if (lock.tryLock(TradingCacheConstant.REDIS_WAIT_TIME, TimeUnit.SECONDS)) {
//选取不同的支付渠道实现
BasicPayHandler handler = HandlerFactory.get(refundRecord.getTradingChannel(), BasicPayHandler.class);
Boolean result = handler.queryRefundTrading(refundRecord);
if (result) {
//更新数据
this.refundRecordService.saveOrUpdate(refundRecord);
}
return BeanUtil.toBean(refundRecord, RefundRecordDTO.class);
}
throw new SLException(TradingEnum.REFUND_FAIL);
} catch (SLException e) {
throw e;
} catch (Exception e) {
log.error("查询退款交易单数据异常: refundRecord = {}", refundRecord, e);
throw new SLException(TradingEnum.REFUND_FAIL);
} finally {
lock.unlock();
}
}
5.3.3、支付宝实现
@Override
public Boolean queryRefundTrading(RefundRecordEntity refundRecord) throws SLException {
//查询配置
Config config = AlipayConfig.getConfig(refundRecord.getEnterpriseId());
//Factory使用配置
Factory.setOptions(config);
AlipayTradeFastpayRefundQueryResponse response;
try {
response = Factory.Payment.Common().queryRefund(
Convert.toStr(refundRecord.getTradingOrderNo()),
Convert.toStr(refundRecord.getRefundNo()));
} catch (Exception e) {
log.error("调用支付宝查询退款接口出错!refundRecord = {}", refundRecord, e);
throw new SLException(TradingEnum.NATIVE_REFUND_FAIL, e);
}
refundRecord.setRefundCode(response.getSubCode());
refundRecord.setRefundMsg(JSONUtil.toJsonStr(response));
boolean success = ResponseChecker.success(response);
if (success) {
refundRecord.setRefundStatus(RefundStatusEnum.SUCCESS);
return true;
}
throw new SLException(refundRecord.getRefundMsg(), TradingEnum.NATIVE_REFUND_FAIL.getCode(), TradingEnum.NATIVE_REFUND_FAIL.getStatus());
}
5.3.4、微信支付实现
@Override
public Boolean queryRefundTrading(RefundRecordEntity refundRecord) throws SLException {
// 获取微信支付的client对象
WechatPayHttpClient client = WechatPayHttpClient.get(refundRecord.getEnterpriseId());
//请求地址
String apiPath = StrUtil.format("/v3/refund/domestic/refunds/{}", refundRecord.getRefundNo());
WeChatResponse response;
try {
response = client.doGet(apiPath);
} catch (Exception e) {
log.error("调用微信接口出错!apiPath = {}", apiPath, e);
throw new SLException(NATIVE_QUERY_REFUND_FAIL, e);
}
refundRecord.setRefundCode(Convert.toStr(response.getStatus()));
refundRecord.setRefundMsg(response.getBody());
if (response.isOk()) {
JSONObject jsonObject = JSONUtil.parseObj(response.getBody());
// SUCCESS:退款成功
// CLOSED:退款关闭
// PROCESSING:退款处理中
// ABNORMAL:退款异常
String status = jsonObject.getStr("status");
if (StrUtil.equals(status, TradingConstant.WECHAT_REFUND_PROCESSING)) {
refundRecord.setRefundStatus(RefundStatusEnum.SENDING);
} else if (StrUtil.equals(status, TradingConstant.WECHAT_REFUND_SUCCESS)) {
refundRecord.setRefundStatus(RefundStatusEnum.SUCCESS);
} else {
refundRecord.setRefundStatus(RefundStatusEnum.FAIL);
}
return true;
}
throw new SLException(response.getBody(), NATIVE_QUERY_REFUND_FAIL.getCode(), NATIVE_QUERY_REFUND_FAIL.getStatus());
}
6、同步支付状态【阅读代码】
在支付平台创建交易单后,如果用户支付成功,我们怎么知道支付成功了呢?一般的做法有两种,分别是【异步通知】和【主动查询】,基本的流程如下:
说明:
- 在用户支付成功后,【步骤4】支付平台会通知【支付微服务】,这个就是异步通知,需要在【支付微服务】中对外暴露接口
- 由于网络的不确定性,异步通知可能出现故障【步骤6】
- 支付微服务中需要有定时任务,查询正在支付中的订单的状态
- 可以看出【异步通知】与【主动定时查询】这两种方式是互不的,缺一不可。
6.1、异步通知
支付宝和微信都提供了异步通知功能,具体参考官方文档:
6.1.1、内网穿透
异步通知的是需要通过外网的域名地址请求到的,由于我们还没有真正上线,那支付平台如何请求到我们本地服务的呢?
这里可以使用【内网穿透】技术来实现,通过【内网穿透软件】将内网与外网通过隧道打通,外网可以读取内网中的数据。
在这里推荐2个免费的内网穿透服务,分别是:
这里以【cpolar】为例,介绍使用方法:
第一步,安装cpolar:
Windows的安装包在资料目录中,101机器的已经按照完成,在 /usr/local/src/cpolar
目录下。
第二步,注册账号并且登录。
第三步,设置token:
请求 https://dashboard.cpolar.com/get-started 页面,查看命令./cpolar authtoken xxxx
后面的【xxxx】就是你自己的token,每个人是不一样的。token只需要设置一次。
第四步,设置端口映射:
例如:./cpolar http 18096
端口改成你自己的端口。
在线查看:
将https
协议的url写入到sl_pay_channel
表的notify_url
字段中,例如:[https://39808c89.vip.cpolar.cn/trade/notify/wx/{enterpriseId}](https://39808c89.vip.cpolar.cn/trade/notify/wx/{enterpriseId})
。
:::danger
注意:cpolar的域名每次启动服务都不一样,每个人的也都不一样,需要改成你自己的那个域名。
:::
6.1.2、NotifyController
package com.sl.ms.trade.controller;
import cn.hutool.core.map.MapUtil;
import com.sl.ms.trade.service.NotifyService;
import com.sl.transport.common.exception.SLException;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import io.swagger.annotations.Api;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* 支付结果的通知
*/
@RestController
@Api(tags = "支付通知")
@RequestMapping("notify")
public class NotifyController {
@Resource
private NotifyService notifyService;
/**
* 微信支付成功回调(成功后无需响应内容)
*
* @param httpEntity 微信请求信息
* @param enterpriseId 商户id
* @return 正常响应200,否则响应500
*/
@PostMapping("wx/{enterpriseId}")
public ResponseEntity<Object> wxPayNotify(HttpEntity<String> httpEntity, @PathVariable("enterpriseId") Long enterpriseId) {
try {
//获取请求头
HttpHeaders headers = httpEntity.getHeaders();
//构建微信请求数据对象
NotificationRequest request = new NotificationRequest.Builder()
.withSerialNumber(headers.getFirst("Wechatpay-Serial")) //证书序列号(微信平台)
.withNonce(headers.getFirst("Wechatpay-Nonce")) //随机串
.withTimestamp(headers.getFirst("Wechatpay-Timestamp")) //时间戳
.withSignature(headers.getFirst("Wechatpay-Signature")) //签名字符串
.withBody(httpEntity.getBody())
.build();
//微信通知的业务处理
this.notifyService.wxPayNotify(request, enterpriseId);
} catch (SLException e) {
Map<String, Object> result = MapUtil.<String, Object>builder()
.put("code", "FAIL")
.put("message", e.getMsg())
.build();
//响应500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
}
return ResponseEntity.ok(null);
}
/**
* 支付宝支付成功回调(成功后需要响应success)
*
* @param enterpriseId 商户id
* @return 正常响应200,否则响应500
*/
@PostMapping("alipay/{enterpriseId}")
public ResponseEntity<String> aliPayNotify(HttpServletRequest request,
@PathVariable("enterpriseId") Long enterpriseId) {
try {
//支付宝通知的业务处理
this.notifyService.aliPayNotify(request, enterpriseId);
} catch (SLException e) {
//响应500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
return ResponseEntity.ok("success");
}
}
:::danger
异步通知debug测试时,三方支付平台会发起多个重试请求,会导致debug无法拦截每个请求,需要将debug模式设置成单线程模式,如下:(断点红球上点右键进行设置)
:::
6.1.3、NotifyService
package com.sl.ms.trade.service;
import com.sl.transport.common.exception.SLException;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import javax.servlet.http.HttpServletRequest;
/**
* 支付通知
*/
public interface NotifyService {
/**
* 微信支付通知,官方文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_5.shtml
*
* @param request 微信请求对象
* @param enterpriseId 商户id
* @throws SLException 抛出SL异常,通过异常决定是否响应200
*/
void wxPayNotify(NotificationRequest request, Long enterpriseId) throws SLException;
/**
* 支付宝支付通知,官方文档:https://opendocs.alipay.com/open/194/103296?ref=api
*
* @param request 请求对象
* @param enterpriseId 商户id
* @throws SLException 抛出SL异常,通过异常决定是否响应200
*/
void aliPayNotify(HttpServletRequest request, Long enterpriseId) throws SLException;
}
6.1.4、NotifyServiceImpl
:::info
注意:
- 支付成功的通知请求,一定要确保是真正来自支付平台,防止伪造请求造成数据错误,导致财产损失
- 对于响应会数据需要进行解密处理
:::
package com.sl.ms.trade.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.sl.ms.base.api.common.MQFeign;
import com.sl.ms.trade.constant.TradingCacheConstant;
import com.sl.ms.trade.constant.TradingConstant;
import com.sl.ms.trade.entity.TradingEntity;
import com.sl.ms.trade.enums.TradingStateEnum;
import com.sl.ms.trade.handler.alipay.AlipayConfig;
import com.sl.ms.trade.handler.wechat.WechatPayHttpClient;
import com.sl.ms.trade.service.NotifyService;
import com.sl.ms.trade.service.TradingService;
import com.sl.transport.common.constant.Constants;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.vo.TradeStatusMsg;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
import com.wechat.pay.contrib.apache.httpclient.notification.Notification;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationHandler;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 支付成功的通知处理
*/
@Slf4j
@Service
public class NotifyServiceImpl implements NotifyService {
@Resource
private TradingService tradingService;
@Resource
private RedissonClient redissonClient;
@Resource
private MQFeign mqFeign;
@Override
public void wxPayNotify(NotificationRequest request, Long enterpriseId) throws SLException {
// 查询配置
WechatPayHttpClient client = WechatPayHttpClient.get(enterpriseId);
JSONObject jsonData;
//验证签名,确保请求来自微信
try {
//确保在管理器中存在自动更新的商户证书
client.createHttpClient();
CertificatesManager certificatesManager = CertificatesManager.getInstance();
Verifier verifier = certificatesManager.getVerifier(client.getMchId());
//验签和解析请求数据
NotificationHandler notificationHandler = new NotificationHandler(verifier, client.getApiV3Key().getBytes(StandardCharsets.UTF_8));
Notification notification = notificationHandler.parse(request);
if (!StrUtil.equals("TRANSACTION.SUCCESS", notification.getEventType())) {
//非成功请求直接返回,理论上都是成功的请求
return;
}
//获取解密后的数据
jsonData = JSONUtil.parseObj(notification.getDecryptData());
} catch (Exception e) {
throw new SLException("验签失败");
}
if (!StrUtil.equals(jsonData.getStr("trade_state"), TradingConstant.WECHAT_TRADE_SUCCESS)) {
return;
}
//交易单号
Long tradingOrderNo = jsonData.getLong("out_trade_no");
log.info("微信支付通知:tradingOrderNo = {}, data = {}", tradingOrderNo, jsonData);
//更新交易单
this.updateTrading(tradingOrderNo, jsonData.getStr("trade_state_desc"), jsonData.toString());
}
private void updateTrading(Long tradingOrderNo, String resultMsg, String resultJson) {
String key = TradingCacheConstant.CREATE_PAY + tradingOrderNo;
RLock lock = redissonClient.getFairLock(key);
try {
//获取锁
if (lock.tryLock(TradingCacheConstant.REDIS_WAIT_TIME, TimeUnit.SECONDS)) {
TradingEntity trading = this.tradingService.findTradByTradingOrderNo(tradingOrderNo);
if (trading.getTradingState() == TradingStateEnum.YJS) {
// 已付款
return;
}
//设置成付款成功
trading.setTradingState(TradingStateEnum.YJS);
//清空二维码数据
trading.setQrCode("");
trading.setResultMsg(resultMsg);
trading.setResultJson(resultJson);
this.tradingService.saveOrUpdate(trading);
// 发消息通知其他系统支付成功
TradeStatusMsg tradeStatusMsg = TradeStatusMsg.builder()
.tradingOrderNo(trading.getTradingOrderNo())
.productOrderNo(trading.getProductOrderNo())
.statusCode(TradingStateEnum.YJS.getCode())
.statusName(TradingStateEnum.YJS.name())
.build();
String msg = JSONUtil.toJsonStr(Collections.singletonList(tradeStatusMsg));
this.mqFeign.sendMsg(Constants.MQ.Exchanges.TRADE, Constants.MQ.RoutingKeys.TRADE_UPDATE_STATUS, msg);
return;
}
} catch (Exception e) {
throw new SLException("处理业务失败");
} finally {
lock.unlock();
}
throw new SLException("处理业务失败");
}
@Override
public void aliPayNotify(HttpServletRequest request, Long enterpriseId) throws SLException {
//获取参数
Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, String> param = new HashMap<>();
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
param.put(entry.getKey(), StrUtil.join(",", entry.getValue()));
}
String tradeStatus = param.get("trade_status");
if (!StrUtil.equals(tradeStatus, TradingConstant.ALI_TRADE_SUCCESS)) {
return;
}
//查询配置
Config config = AlipayConfig.getConfig(enterpriseId);
Factory.setOptions(config);
try {
Boolean result = Factory
.Payment
.Common().verifyNotify(param);
if (!result) {
throw new SLException("验签失败");
}
} catch (Exception e) {
throw new SLException("验签失败");
}
//获取交易单号
Long tradingOrderNo = Convert.toLong(param.get("out_trade_no"));
//更新交易单
this.updateTrading(tradingOrderNo, "支付成功", JSONUtil.toJsonStr(param));
}
}
6.1.5、网关对外暴露接口
bootsarp-{profile}.yml文件中增加如下内容:
- id: sl-express-ms-trade
uri: lb://sl-express-ms-trade
predicates:
- Path=/trade/notify/**
filters:
- StripPrefix=1
- AddRequestHeader=X-Request-From, sl-express-gateway
:::danger
说明:对于支付系统在网关中的暴露仅仅暴露通知接口,其他接口不暴露。
:::
6.2、定时任务
一般在项目中实现定时任务主要是两种技术方案,一种是Spring Task,另一种是xxl-job,其中Spring Task是适合单体项目中使用,而xxl-job是分布式任务调度框架,更适合在分布式项目中使用,所以在支付微服务中我们将采用xxl-job来实现。
6.2.1、分布式任务调度
在微服务架构体系中,服务之间通过网络交互来完成业务处理的,在分布式架构下,一个服务往往会部署多个实例来运行我们的业务,如果在这种分布式系统环境下运行任务调度,我们称之为分布式任务调度。
分布式系统的特点,并且提高任务的调度处理能力:
- 并行任务调度
- 集群部署单个服务,这样就可以多台计算机共同去完成任务调度,我们可以将任务分割为若干个分片,由不同的实例并行执行,来提高任务调度的处理效率。
- 高可用
- 若某一个实例宕机,不影响其他实例来执行任务。
- 弹性扩容
- 当集群中增加实例就可以提高并执行任务的处理效率。
- 任务管理与监测
- 对系统中存在的所有定时任务进行统一的管理及监测。
- 让开发人员及运维人员能够时刻了解任务执行情况,从而做出快速的应急处理响应。
6.2.2、xxl-Job简介
XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅速、学习简单、轻量级、易扩展。现已开放源代码并接入多家公司线上产品线,开箱即用。
官网地址:
xxl-job架构图(官图):
7.2.3、部署安装
我们采用docker进行部署安装xxl-job的调度中心,目前已经安装完成,直接访问即可:http://xxl-job.sl-express.com/xxl-job-admin/
安装命令:
docker run \
-e PARAMS="--spring.datasource.url=jdbc:mysql://192.168.150.101:3306/xxl_job?Unicode=true&characterEncoding=UTF-8 \
--spring.datasource.username=root \
--spring.datasource.password=123" \
--restart=always \
-p 28080:8080 \
-v xxl-job-admin-applogs:/data/applogs \
--name xxl-job-admin \
-d \
xuxueli/xxl-job-admin:2.3.0
:::tips
-
默认端口映射到28080
-
日志挂载到/var/lib/docker/volumes/xxl-job-admin-applogs
-
通过PARAMS环境变量设置数据库链接参数
-
数据库脚本:https://gitee.com/xuxueli0323/xxl-job/blob/2.3.0/doc/db/tables_xxl_job.sql
:::
xxl-job共用到8张表,如下:
:::tips -
xxl_job_lock:任务调度锁表;
-
xxl_job_group:执行器信息表,维护任务执行器信息;
-
xxl_job_info:调度扩展信息表: 用于保存XXL-JOB调度任务的扩展信息,如任务分组、任务名、机器地址、执行器、执行入参和报警邮件等等;
-
xxl_job_log:调度日志表: 用于保存XXL-JOB任务调度的历史信息,如调度结果、执行结果、调度入参、调度机器和执行器等等;
-
xxl_job_log_report:调度日志报表:用户存储XXL-JOB任务调度日志的报表,调度中心报表功能页面会用到;
-
xxl_job_logglue:任务GLUE日志:用于保存GLUE更新历史,用于支持GLUE的版本回溯功能;
-
xxl_job_registry:执行器注册表,维护在线的执行器和调度中心机器地址信息;
-
xxl_job_user:系统用户表;
:::
6.2.4、编写任务代码
拉取编写任务的示例代码进行学习:http://git.sl-express.com/sl/sl-express-xxl-job
运行之前,首先需要创建执行管理器:
创建任务:
:::info
xxl-job支持的路由策略非常丰富:
- FIRST(第一个):固定选择第一个机器;
- LAST(最后一个):固定选择最后一个机器;
- ROUND(轮询):在线的机器按照顺序一次执行一个
- RANDOM(随机):随机选择在线的机器;
- CONSISTENT_HASH(一致性HASH):每个任务按照Hash算法固定选择某一台机器,且所有任务均匀散列在不同机器上。
- LEAST_FREQUENTLY_USED(最不经常使用):使用频率最低的机器优先被选举;
- LEAST_RECENTLY_USED(最近最久未使用):最久未使用的机器优先被选举;
- FAILOVER(故障转移):按照顺序依次进行心跳检测,第一个心跳检测成功的机器选定为目标执行器并发起调度;
- BUSYOVER(忙碌转移):按照顺序依次进行空闲检测,第一个空闲检测成功的机器选定为目标执行器并发起调度;
- SHARDING_BROADCAST(分片广播):广播触发对应集群中所有机器执行一次任务,同时系统自动传递分片参数;可根据分片参数开发分片任务;
:::
xxl-job配置:
package com.sl.xxljob.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* xxl-job config
*/
@Configuration
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken:}")
private String accessToken;
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address:}")
private String address;
@Value("${xxl.job.executor.ip:}")
private String ip;
@Value("${xxl.job.executor.port:0}")
private int port;
@Value("${xxl.job.executor.logpath:}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays:}")
private int logRetentionDays;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
任务代码:
package com.sl.xxljob.job;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
/**
* 任务处理器
*/
@Component
public class JobHandler {
private List<Integer> dataList = Arrays.asList(1, 2, 3, 4, 5);
/**
* 普通任务
*/
@XxlJob("firstJob")
public void firstJob() throws Exception {
System.out.println("firstJob执行了.... " + LocalDateTime.now());
for (Integer data : dataList) {
XxlJobHelper.log("data= {}", data);
Thread.sleep(RandomUtil.randomInt(100, 500));
}
System.out.println("firstJob执行结束了.... " + LocalDateTime.now());
}
/**
* 分片式任务
*/
@XxlJob("shardingJob")
public void shardingJob() throws Exception {
// 分片参数
// 分片节点总数
int shardTotal = XxlJobHelper.getShardTotal();
// 当前节点下标,从0开始
int shardIndex = XxlJobHelper.getShardIndex();
System.out.println("shardingJob执行了.... " + LocalDateTime.now());
for (Integer data : dataList) {
if (data % shardTotal == shardIndex) {
XxlJobHelper.log("data= {}", data);
Thread.sleep(RandomUtil.randomInt(100, 500));
}
}
System.out.println("shardingJob执行结束了.... " + LocalDateTime.now());
}
}
分片式任务的测试:
2022-08-17 19:32:45 [com.xxl.job.core.thread.JobThread#run]-[130]-[Thread-10]
----------- xxl-job job execute start -----------
----------- Param:
2022-08-17 19:32:45 [com.sl.xxljob.job.JobHandler#shardingJob]-[40]-[Thread-10] data= 1
2022-08-17 19:32:45 [com.sl.xxljob.job.JobHandler#shardingJob]-[40]-[Thread-10] data= 3
2022-08-17 19:32:45 [com.sl.xxljob.job.JobHandler#shardingJob]-[40]-[Thread-10] data= 5
2022-08-17 19:32:46 [com.xxl.job.core.thread.JobThread#run]-[176]-[Thread-10]
----------- xxl-job job execute end(finish) -----------
----------- Result: handleCode=200, handleMsg = null
2022-08-17 19:32:46 [com.xxl.job.core.thread.TriggerCallbackThread#callbackLog]-[197]-[xxl-job, executor TriggerCallbackThread]
----------- xxl-job job callback finish.
[Load Log Finish]
2022-08-17 19:32:45 [com.xxl.job.core.thread.JobThread#run]-[130]-[Thread-10]
----------- xxl-job job execute start -----------
----------- Param:
2022-08-17 19:32:45 [com.sl.xxljob.job.JobHandler#shardingJob]-[40]-[Thread-10] data= 2
2022-08-17 19:32:45 [com.sl.xxljob.job.JobHandler#shardingJob]-[40]-[Thread-10] data= 4
2022-08-17 19:32:45 [com.xxl.job.core.thread.JobThread#run]-[176]-[Thread-10]
----------- xxl-job job execute end(finish) -----------
----------- Result: handleCode=200, handleMsg = null
2022-08-17 19:32:45 [com.xxl.job.core.thread.TriggerCallbackThread#callbackLog]-[197]-[xxl-job, executor TriggerCallbackThread]
----------- xxl-job job callback finish.
[Load Log Finish]
可以看出,2个节点共同完成的任务处理,并且没有重复,这样提高了任务处理能力。
6.2.5、调度流程
## 6.3、TradeJob
在此任务中包含两个任务,一个是查询支付状态,另一个是查询退款状态。
package com.sl.ms.trade.job;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil;
import com.sl.ms.base.api.common.MQFeign;
import com.sl.ms.trade.domain.RefundRecordDTO;
import com.sl.ms.trade.domain.TradingDTO;
import com.sl.ms.trade.entity.RefundRecordEntity;
import com.sl.ms.trade.entity.TradingEntity;
import com.sl.ms.trade.enums.RefundStatusEnum;
import com.sl.ms.trade.enums.TradingStateEnum;
import com.sl.ms.trade.service.BasicPayService;
import com.sl.ms.trade.service.RefundRecordService;
import com.sl.ms.trade.service.TradingService;
import com.sl.transport.common.constant.Constants;
import com.sl.transport.common.vo.TradeStatusMsg;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 交易任务,主要是查询订单的支付状态 和 退款的成功状态
*/
@Slf4j
@Component
public class TradeJob {
@Value("${sl.job.trading.count:100}")
private Integer tradingCount;
@Value("${sl.job.refund.count:100}")
private Integer refundCount;
@Resource
private TradingService tradingService;
@Resource
private RefundRecordService refundRecordService;
@Resource
private BasicPayService basicPayService;
@Resource
private MQFeign mqFeign;
/**
* 分片广播方式查询支付状态
* 逻辑:每次最多查询{tradingCount}个未完成的交易单,交易单id与shardTotal取模,值等于shardIndex进行处理
*/
@XxlJob("tradingJob")
public void tradingJob() {
// 分片参数
int shardIndex = NumberUtil.max(XxlJobHelper.getShardIndex(), 0);
int shardTotal = NumberUtil.max(XxlJobHelper.getShardTotal(), 1);
List<TradingEntity> list = this.tradingService.findListByTradingState(TradingStateEnum.FKZ, tradingCount);
if (CollUtil.isEmpty(list)) {
XxlJobHelper.log("查询到交易单列表为空!shardIndex = {}, shardTotal = {}", shardIndex, shardTotal);
return;
}
//定义消息通知列表,只要是状态不为【付款中】就需要通知其他系统
List<TradeStatusMsg> tradeMsgList = new ArrayList<>();
for (TradingEntity trading : list) {
if (trading.getTradingOrderNo() % shardTotal != shardIndex) {
continue;
}
try {
//查询交易单
TradingDTO tradingDTO = this.basicPayService.queryTrading(trading.getTradingOrderNo());
if (TradingStateEnum.FKZ != tradingDTO.getTradingState()) {
TradeStatusMsg tradeStatusMsg = TradeStatusMsg.builder()
.tradingOrderNo(trading.getTradingOrderNo())
.productOrderNo(trading.getProductOrderNo())
.statusCode(tradingDTO.getTradingState().getCode())
.statusName(tradingDTO.getTradingState().name())
.build();
tradeMsgList.add(tradeStatusMsg);
}
} catch (Exception e) {
XxlJobHelper.log("查询交易单出错!shardIndex = {}, shardTotal = {}, trading = {}", shardIndex, shardTotal, trading, e);
}
}
if (CollUtil.isEmpty(tradeMsgList)) {
return;
}
//发送消息通知其他系统
String msg = JSONUtil.toJsonStr(tradeMsgList);
this.mqFeign.sendMsg(Constants.MQ.Exchanges.TRADE, Constants.MQ.RoutingKeys.TRADE_UPDATE_STATUS, msg);
}
/**
* 分片广播方式查询退款状态
*/
@XxlJob("refundJob")
public void refundJob() {
// 分片参数
int shardIndex = NumberUtil.max(XxlJobHelper.getShardIndex(), 0);
int shardTotal = NumberUtil.max(XxlJobHelper.getShardTotal(), 1);
List<RefundRecordEntity> list = this.refundRecordService.findListByRefundStatus(RefundStatusEnum.SENDING, refundCount);
if (CollUtil.isEmpty(list)) {
XxlJobHelper.log("查询到退款单列表为空!shardIndex = {}, shardTotal = {}", shardIndex, shardTotal);
return;
}
//定义消息通知列表,只要是状态不为【退款中】就需要通知其他系统
List<TradeStatusMsg> tradeMsgList = new ArrayList<>();
for (RefundRecordEntity refundRecord : list) {
if (refundRecord.getRefundNo() % shardTotal != shardIndex) {
continue;
}
try {
//查询退款单
RefundRecordDTO refundRecordDTO = this.basicPayService.queryRefundTrading(refundRecord.getRefundNo());
if (RefundStatusEnum.SENDING != refundRecordDTO.getRefundStatus()) {
TradeStatusMsg tradeStatusMsg = TradeStatusMsg.builder()
.tradingOrderNo(refundRecord.getTradingOrderNo())
.productOrderNo(refundRecord.getProductOrderNo())
.refundNo(refundRecord.getRefundNo())
.statusCode(refundRecord.getRefundStatus().getCode())
.statusName(refundRecord.getRefundStatus().name())
.build();
tradeMsgList.add(tradeStatusMsg);
}
} catch (Exception e) {
XxlJobHelper.log("查询退款单出错!shardIndex = {}, shardTotal = {}, refundRecord = {}", shardIndex, shardTotal, refundRecord, e);
}
}
if (CollUtil.isEmpty(tradeMsgList)) {
return;
}
//发送消息通知其他系统
String msg = JSONUtil.toJsonStr(tradeMsgList);
this.mqFeign.sendMsg(Constants.MQ.Exchanges.TRADE, Constants.MQ.RoutingKeys.REFUND_UPDATE_STATUS, msg);
}
}
6.4、xxl-job任务
创建xxl-job的任务,首先创建执行器(AppName在nacos中的sl-express-ms-trade.properties
配置文件中指定):
创建【查询支付状态】任务:
创建【查询退款状态】任务:
本地启动服务后会看到注册的ip地址,可能是在101机器无法访问的,如下:
如果出现此情况,需要在配置文件中设置参数指定ip地址,如下:
配置可参考官方文档:https://www.xuxueli.com/xxl-job/
xxl:
job:
executor:
ip: 192.168.150.1
重新启动,效果如下:
7、面试连环问
:::info
面试官问:
- 支付二维码的生成你们是在服务端还是在客户端?为什么不在服务端?在客户端生成有什么好处?
- 用户在选择支付渠道后,可能会反复的切换支付渠道,这块你们是怎么处理的?
- 用户在申请支付后,发现并没有展示出二维码,这时用户可能会不断的重试,你们有考虑这种情况吗?具体是怎么处理的?
- 支付渠道可能是多样的,你们的代码是怎么设计的?如果需要停用某个渠道,但是不重启服务,怎么能做到?
- 支付成功的通知你们是怎处理的?有考虑幂等性吗?如何确保请求是真正来源支付平台的?如果通知没有接收到,你们怎么处理的?
- xxl-job的分片式广播用过吗?他是如何确保任务节点处理不重复数据的?
:::
更多推荐
所有评论(0)