JAVA后端对接支付的全过程(微信,支付宝)
1.微信支付的分类
公众号支付(JSAPI) 不需要关注公众号
H5支付 微信以外的手机浏览器
小程序支付(JSAPI) 类似公众号
Native支付 扫码付 (这里我们主要对接Native支付)
2. 支付宝支付分类
当面付 条码支付
扫码支付
电脑网站支付 (这里我们主要对接电脑网站支付)
3.各种支付名词解释
appid 不是移动app的id 是支付宝或微信创建网页应用或移动应用
一个应用有多个支付产品 (建议小程序支付和app支付独立)
微信各个应用所需的appid
openid(微信独有的)
只有公众号和小程序需要传
appid不同,则获取到的openid就不同
4.同步与异步
同步: 打电话(需要及时响应)
异步 :发微信(不需要立即响应)
转账过程
建行(张三)转账请求(request) ---> 网联 ---> 农行(李四)
建行(张三)<---- 网联 <---- 收到钱了(request)农行(李四)
为什么不采用同步???
因为在实际的支付中,环境很复杂,各种校验签名,网络环境也可能发送延迟
所以目前的支付通知基本都是异步通知
支付结果以异步为准
5.支付系统的开发
支付系统应该是一个独立的系统(专用的数据库/表),提供接口给其它系统使用,起到一个支付与业务系统解耦的作用
一个独立的支付系统可以对接多个业务系统,就不需要在业务系统中添加复杂的支付功能了
6.下面就开始实现我们的项目
1.先用IDEA创建springboot项目(version:2.1.7)(这里我就不多赘述了,可以自行百度)
2.把你的pom文件修改成如下(建议IDEA开启自动maven自动下载)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.imooc</groupId>
<artifactId>pay</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pay</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--集成支付sdk -->
<dependency>
<groupId>cn.springboot</groupId>
<artifactId>best-pay-sdk</artifactId>
<version>1.3.0</version>
</dependency>
<!-- 集成spring aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--集成fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
<!--mysql数据库连接 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<!--集成mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
3.支付核心的依赖就是这个了
<!--集成支付sdk -->
<dependency>
<groupId>cn.springboot</groupId>
<artifactId>best-pay-sdk</artifactId>
<version>1.3.0</version>
</dependency>
我们在做支付功能的时候,会使用到这个sdk的代码,对我们用到一些参数做处理,方便新手去开发支付功能,快速实现需求
4.以下是我的项目目录
5.先在你的数据库中新建这个表 mall_pay_info (由于我们这边只涉及到基础支付模块的开发,只需要这个表记录支付操作就可以了)
DROP TABLE IF EXISTS `mall_pay_info`;
CREATE TABLE `mall_pay_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL COMMENT '用户id',
`order_no` bigint(20) NOT NULL COMMENT '订单号',
`pay_platform` int(10) DEFAULT NULL COMMENT '支付平台:1-支付宝,2-微信',
`platform_number` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '支付流水号',
`platform_status` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '支付状态',
`pay_amount` decimal(20, 2) NOT NULL COMMENT '支付金额',
`create_time` datetime(0) DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime(0) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uqe_order_no`(`order_no`) USING BTREE,
UNIQUE INDEX `uqe_platform_number`(`platform_number`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 119 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
6.使用mybatis-generator插件生成对应pojo,mapper,xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">
<!-- 自动检查关键字,为关键字增加反引号 -->
<property name="autoDelimitKeywords" value="true"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!--覆盖生成XML文件-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- 生成的实体类添加toString()方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/pay_mall?serverTimezone=Asia/Shanghai"
userId="root"
password="123456">
</jdbcConnection>
<!-- domain类的位置 -->
<javaModelGenerator targetProject="src\main\java"
targetPackage="com.imooc.mall.pojo"/>
<!-- mapper xml的位置 -->
<sqlMapGenerator targetProject="src\main\resources"
targetPackage="mapper"/>
<!-- mapper类的位置 -->
<javaClientGenerator targetProject="src\main\java"
targetPackage="com.imooc.mall.mapper"
type="XMLMAPPER"/>
<table tableName="mall_category"/>
<table tableName="mall_order"/>
<table tableName="mall_order_item"/>
<table tableName="mall_pay_info"/>
<table tableName="mall_product"/>
<table tableName="mall_shipping"/>
<table tableName="mall_user"/>
</context>
</generatorConfiguration>
需要在maven中加入这个插件才能使用
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<configurationFile>src/main/resources/generator/generator-config.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
</dependencies>
</plugin>
7.生成好基本的mybatis文件后,把 resources下的application.yml配置改成如下所示
wx支付及支付宝支付所需的参数,我这边就先不贴出来了,需要你们自己去申请,或者找朋友借一下
说明一下 notifyUrl就是支付所用到的回调地址,这里使用了内网穿透的技术 (因为支付是一个异步操作,微信及支付宝支付完成后,会向我们的服务端发送报文,而我们在内网是不可能接收到的,所以要使用内网穿透) 这里推荐一个内网穿透软件natapp,百度一下就可以搜索到,returnUrl 就是你完成支付后的返回地址,在我这个项目中,我自己基于vue3开发了一个支付前端项目,主要是使用的aixos去和后端交互,所以我这边没有用到returnUrl,这个应该是用于前后端没有分离的项目使用的,这边就不再赘述了
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/pay_mall?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true
rabbitmq:
addresses: 127.0.0.1
port: 3306
username: root
password: 123456
mybatis:
configuration:
map-underscore-to-camel-case: true
#控制台日志打印SQL日志
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mapper/*.xml
server:
port: 8088
wx:
appId:
mchId:
mchKey:
notifyUrl: http://imooc-mall123.natapp1.cc/pay/notify
returnUrl: localhost:8080
alipay:
appId:
privateKey:
aliPayPublicKey:
notifyUrl: http://imooc-mall123.natapp1.cc/pay/notify
returnUrl: localhost:8080
8.新建微信和支付宝的配置类,用来读取yml的参数
新建四个config类 AliPayAccountConfig,WxAccountConfig,BestPayConfig,CorsConfig
这里主要就是通过
@ConfigurationProperties(prefix = "alipay")注解 prefix对应的就是yml配置中配置头名称
@Component 就是让配置类让容器扫描到 方便需要使用的地方可以直接@Autowired
说明一下这四个类的作用
AliPayAccountConfig --- 支付宝支付配置
WxAccountConfig --- 微信支付配置
BestPayConfig --- 将微信支付宝的配置聚合起来,方便业务层使用
CorsConfig --- 用于跨域请求
package com.imooc.config;
import com.lly835.bestpay.config.WxPayConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* @Author huqian
* @Date 2021/5/23 21:31
* @Version 1.0
*/
@Component
@ConfigurationProperties(prefix = "wx")
public class WxAccountConfig {
private String appId;
private String mchId;
private String mchKey;
private String notifyUrl;
private String returnUrl;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getMchKey() {
return mchKey;
}
public void setMchKey(String mchKey) {
this.mchKey = mchKey;
}
public String getNotifyUrl() {
return notifyUrl;
}
public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}
public String getReturnUrl() {
return returnUrl;
}
public void setReturnUrl(String returnUrl) {
this.returnUrl = returnUrl;
}
}
package com.imooc.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author huqian
* @Date 2021/5/23 21:48
* @Version 1.0
*/
@Component
@ConfigurationProperties(prefix = "alipay")
public class AliPayAccountConfig {
private String appId;
private String privateKey;
private String publicKey;
private String notifyUrl;
private String returnUrl;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getPrivateKey() {
return privateKey;
}
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public String getPublicKey() {
return publicKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public String getNotifyUrl() {
return notifyUrl;
}
public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}
public String getReturnUrl() {
return returnUrl;
}
public void setReturnUrl(String returnUrl) {
this.returnUrl = returnUrl;
}
}
package com.imooc.config;
import com.lly835.bestpay.config.AliPayConfig;
import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.service.BestPayService;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* @Author huqian
* @Date 2021/5/16 23:19
* @Version 1.0
*/
@Component
public class BestPayConfig {
@Autowired
private WxAccountConfig wxAccountConfig;
@Autowired
private AliPayAccountConfig aliPayAccountConfig;
@Bean
public BestPayService bestPayService(){
WxPayConfig wxPayConfig= wxPayConfig();
AliPayConfig aliPayConfig =new AliPayConfig();
aliPayConfig.setAppId(aliPayAccountConfig.getAppId());
aliPayConfig.setPrivateKey(aliPayAccountConfig.getPrivateKey());
aliPayConfig.setAliPayPublicKey(aliPayAccountConfig.getPublicKey());
aliPayConfig.setNotifyUrl(aliPayAccountConfig.getNotifyUrl());
aliPayConfig.setReturnUrl(aliPayAccountConfig.getReturnUrl());
BestPayServiceImpl bestPayService =new BestPayServiceImpl();
bestPayService.setWxPayConfig(wxPayConfig);
bestPayService.setAliPayConfig(aliPayConfig);
return bestPayService;
}
@Bean
public WxPayConfig wxPayConfig() {
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(wxAccountConfig.getAppId());
wxPayConfig.setMchId(wxAccountConfig.getMchId());
wxPayConfig.setMchKey(wxAccountConfig.getMchKey());
//192.168.50.101 同一局域网可访问
//125.121.56.227 云服务器可行,家庭宽带不行(路由器、光猫)
wxPayConfig.setNotifyUrl(wxAccountConfig.getNotifyUrl());
wxPayConfig.setReturnUrl(wxAccountConfig.getReturnUrl());
return wxPayConfig;
}
}
9.新建支付的接口和实现类
说明一下主要有三个接口
create 创建支付订单并发起支付请求到微信支付宝服务器上
asyncNotify 异步通知接口,支付成功成功后通知服务器
queryByOrderId 查询接口,这个是用于前端轮询使用,用于前端支付状态的改变
package com.imooc.service;
import com.imooc.entity.PayInfo;
import com.imooc.pojo.MallPayInfo;
import com.lly835.bestpay.enums.BestPayTypeEnum;
import com.lly835.bestpay.model.PayResponse;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
/**
* @Author huqian
* @Date 2021/5/14 10:08
* @Version 1.0
*/
@Repository
public interface IPayService {
/**
* 创建发起支付
* @return
*/
PayResponse create(String orderId, BigDecimal amount, BestPayTypeEnum bestPayTypeEnum);
/**
* 异步通知
*/
String asyncNotify(String notifyData);
/**
* 通过订单号查询支付记录 用于前端的轮询
* @param orderId
* @return
*/
MallPayInfo queryByOrderId (String orderId);
}
package com.imooc.service.Impl;
import com.imooc.entity.PayInfo;
import com.imooc.enums.PayPlatformEnum;
import com.imooc.mapper.MallPayInfoMapper;
import com.imooc.pojo.MallPayInfo;
import com.imooc.pojo.MallPayInfoExample;
import com.imooc.service.IPayService;
import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.enums.BestPayPlatformEnum;
import com.lly835.bestpay.enums.BestPayTypeEnum;
import com.lly835.bestpay.enums.OrderStatusEnum;
import com.lly835.bestpay.model.PayRequest;
import com.lly835.bestpay.model.PayResponse;
import com.lly835.bestpay.service.BestPayService;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.List;
/**
* @Author huqian
* @Date 2021/5/14 10:10
* @Version 1.0
*/
@Slf4j
@Service
public class PayServiceImpl implements IPayService {
@Autowired
private BestPayService bestPayService;
@Autowired
private MallPayInfoMapper mallPayInfoMapper;
/**
* 创建发起支付
* @param orderId
* @param amount
* @return
*/
@Override
public PayResponse create(String orderId, BigDecimal amount,BestPayTypeEnum bestPayTypeEnum) {
//发起支付的时候 数据要写入数据库中
MallPayInfo mallPayInfo = new MallPayInfo(Long.valueOf(orderId), PayPlatformEnum.getBestPayPlatTypeEnum(bestPayTypeEnum).getCode(), OrderStatusEnum.NOTPAY.name(),amount);
mallPayInfoMapper.insertSelective(mallPayInfo);
PayRequest request = new PayRequest();
request.setOrderName("2630799-最好的支付sdk");
request.setOrderId(orderId);
request.setOrderAmount(amount.doubleValue());
request.setPayTypeEnum(bestPayTypeEnum);
PayResponse payResponse= bestPayService.pay(request);
log.info("发起支付 response={}",payResponse);
return payResponse;
}
/**
* 异步通知
*/
@Override
public String asyncNotify(String notifyData) {
MallPayInfoExample mallPayInfoExample= new MallPayInfoExample();
MallPayInfoExample.Criteria criteria = mallPayInfoExample.createCriteria();
//1.签名校验
PayResponse payResponse = bestPayService.asyncNotify(notifyData);
log.info("异步通知 payResponse:{}",payResponse);
//2.金额校验(从数据库中查订单)
criteria.andOrderNoEqualTo(Long.valueOf(payResponse.getOrderId()));
List<MallPayInfo> mallPayInfo= mallPayInfoMapper.selectByExample(mallPayInfoExample);
//3.修改订单的支付状态
//如果没有记录说明出了问题 通过短信 或 钉钉 微信等平台告警
if (mallPayInfo == null){
//发起告警
throw new RuntimeException("通过OrderNo查询到的记录为空orderId:"+payResponse.getOrderId());
}
//如果订单状态不是已支付 校验金额
if(!mallPayInfo.get(0).getPlatformStatus().equals(OrderStatusEnum.SUCCESS.name())){
//如果金额相同 修改订单状态
if(mallPayInfo.get(0).getPayAmount().compareTo(BigDecimal.valueOf(payResponse.getOrderAmount()))==0){
MallPayInfo mallPayInfoDB = mallPayInfo.get(0);
mallPayInfoDB .setUpdateTime(null);
mallPayInfoDB .setId(null);
mallPayInfoDB .setPlatformStatus(OrderStatusEnum.SUCCESS.name());
criteria.andOrderNoEqualTo(Long.valueOf(payResponse.getOrderId()));
mallPayInfoMapper.updateByExampleSelective(mallPayInfoDB ,mallPayInfoExample);
}
//如果金额不同,报警
//发起告警
throw new RuntimeException("通过OrderNo发起的支付金额有问题 orderId:"+payResponse.getOrderId());
}
//TODO pay发送MQ消息 mall接受mq消息
//4.告诉支付平台不要再重复通知了
if (payResponse.getPayPlatformEnum()== BestPayPlatformEnum.WX){
return "<xml>\n" +
" <return_code><![CDATA[SUCCESS]]></return_code>\n" +
" <return_msg><![CDATA[OK]]></return_msg>\n" +
"</xml>";
}else if(payResponse.getPayPlatformEnum()== BestPayPlatformEnum.ALIPAY){
return "success";
}
throw new RuntimeException("异步通知中错误的支付平台");
}
/**
* 通过订单号查询支付记录 用于前端的轮询
* @param orderId
* @return
*/
@Override
public MallPayInfo queryByOrderId(String orderId) {
if (!ObjectUtils.isEmpty(orderId)){
MallPayInfoExample mallPayInfoExample= new MallPayInfoExample();
MallPayInfoExample.Criteria criteria = mallPayInfoExample.createCriteria();
criteria.andOrderNoEqualTo(Long.valueOf(orderId));
log.info("查询信息", mallPayInfoMapper.selectByExample(mallPayInfoExample).get(0).toString());
return mallPayInfoMapper.selectByExample(mallPayInfoExample).get(0);
}
return new MallPayInfo();
}
}
10.编写的我们的支付controller,公共响应类
package com.imooc.controller;
import com.imooc.entity.PayInfo;
import com.imooc.pojo.MallPayInfo;
import com.imooc.service.IPayService;
import com.imooc.util.CommonResp;
import com.lly835.bestpay.enums.BestPayTypeEnum;
import com.lly835.bestpay.model.PayResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.math.BigDecimal;
/**
* @Author huqian
* @Date 2021/5/14 10:39
* @Version 1.0
*/
@RestController
@RequestMapping("/pay")
@Slf4j
public class PayController {
@Autowired
private IPayService iPayService;
@PostMapping("/create")
@ResponseBody
public CommonResp create(@Valid @RequestBody PayInfo payInfo){
CommonResp commonResp= new CommonResp();
log.info("PayInfo",payInfo.toString());
PayResponse payResponse= iPayService.create(payInfo.getOrderId(), BigDecimal.valueOf(payInfo.getOrderAmount()),payInfo.getBestPayTypeEnum());
commonResp.setContent(payResponse);
return commonResp;
}
@PostMapping("/notify")
@ResponseBody
public String asyncNotify(@RequestBody String notifyData){
return iPayService.asyncNotify(notifyData);
}
@GetMapping("/hello")
@ResponseBody
public String hello(){
return "hello";
}
@GetMapping("/queryByOrderId/{orderId}")
@ResponseBody
public CommonResp queryByOrderId(@PathVariable String orderId){
log.info("开始查询orderID :OrderId{}的支付记录",orderId);
CommonResp commonResp = new CommonResp();
MallPayInfo mallPayInfo = iPayService.queryByOrderId(orderId);
commonResp.setContent(mallPayInfo);
return commonResp;
}
}
package com.imooc.util;
/**
* @Author huqian
* @Date 2021/3/5 15:15
* @Version 1.0
*/
public class CommonResp<T> {
/**
* 业务上的成功或失败
*/
private boolean success = true;
/**
* 返回信息
*/
private String message;
/**
* 返回泛型数据,自定义类型
*/
private T content;
public boolean getSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getContent() {
return content;
}
public void setContent(T content) {
this.content = content;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("ResponseDto{");
sb.append("success=").append(success);
sb.append(", message='").append(message).append('\'');
sb.append(", content=").append(content);
sb.append('}');
return sb.toString();
}
}
11.给大家看一下运行效果
前端微信发起支付
微信支付成功后,前端状态改变
支付成功后,后端轮询的结果,支付状态已经改变了
支付宝和微信不同,发起支付后会跳转页面
后端的报文
支付成功就是这个页面,然后支付宝会跳转到你设置的returnUrl
这里前端代码的我就不贴出来了,大家想了解的话可以去我的gitee上看吧
支付项目服务端源码
https://gitee.com/hq123456/mall_pay_server
支付项目前端源码
https://gitee.com/hq123456/mall_pay_web.git
创作不易,还请大家支持一下,也感谢各位的阅读