栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

微信支付(p11-p20)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

微信支付(p11-p20)

微信支付(p11-p20)

文章目录
  • 微信支付(p11-p20)
    • 11.Https协议
    • 12.总结
    • 13.微信APIv3证书
    • 14.创建案例项目
    • 15.创建SpringBoot项目
    • 16.引入Swagger
    • 17.统一返回结果
    • 18.数据库
    • 19.集成Mybatis-plus
    • 20.Mybatis-plus补充

11.Https协议

12.总结 13.微信APIv3证书

商户证书:之前已经下载过

  • apiclient_cert.p12
  • apiclient_cert.pem
  • apiclient_key.pem
  • 证书使用说明.txt

平台证书:微信支付平台证书是指由微信支付负责申请的,包含微信支付平台标识,公钥信息的证书。商户可以使用平台证书中的公钥进行验签

1.登录网址:https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay3_0.shtml
2.文档中心--接口规则--证书密钥使用说明--API接口下载
14.创建案例项目

步骤:

  1. 创建SpringBoot项目(Java、SpringBoot、SpringMVC、RESTful、json)
  2. 引入Swagger(接口文档和测试页面生成工具)
  3. 定义统一结果
  4. 创建和连接数据库
  5. 集成Mybatis-Plus
  6. 搭建前端环境
  7. 认识Vue.js
15.创建SpringBoot项目

application.yml

server:
  port: 8090

spring:
  application:
    name: pay-system
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

ProductController

package com.hengke.controller;

@RestController
@RequestMapping("/api/product")
public class ProductController {
    @GetMapping("/test")
    public String test(){
        return "hello";
    }
}
16.引入Swagger

pom.xml

    
        
        
            io.springfox
            springfox-swagger2
            2.7.0
        
        
        
            io.springfox
            springfox-swagger-ui
            2.7.0
        
    

Swagger2Config

package com.hengke.config;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder().title("微信支付案例接口文档").build());
    }
}
package com.hengke.controller;

@Api(tags = "商品管理")
@RestController
@RequestMapping("/api/product")
public class ProductController {
   
   @ApiOperation("测试接口")
   @GetMapping("/test")
   public String test(){
       return "hello";
   }
}
17.统一返回结果

引入lombok


	org.projectlombok
	lombok
	1.18.8

R

package com.hengke.vo;

@Data
public class R implements Serializable {
    
    @ApiModelProperty("接口调用是否成功")
    private Boolean success;
    
    @ApiModelProperty("状态码")
    private Integer code;
    
    @ApiModelProperty("响应结果")
    private T data;
    
    @ApiModelProperty("状态信息")
    private String message;

    // 构造器开始
    
    public R() {
        this.code = 200;
        this.success = true;
    }
    
    public R(T obj) {
        this.code = 200;
        this.data = obj;
        this.success = true;
    }

    
    public R(RCode resultCode) {
        this.success = false;
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }
    // 构造器结束

    
    public static R success(){
        return new R();
    }

    
    public static R success(T data){
        return new R(data);
    }

    
    public static R failure(RCode resultCode){
        return  new R(resultCode);
    }
}
18.数据库
USE `payment_demo`;



CREATE TABLE `t_order_info` (
  `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单id',
  `title` varchar(256) DEFAULT NULL COMMENT '订单标题',
  `order_no` varchar(50) DEFAULT NULL COMMENT '商户订单编号',
  `user_id` bigint(20) DEFAULT NULL COMMENT '用户id',
  `product_id` bigint(20) DEFAULT NULL COMMENT '支付产品id',
  `total_fee` int(11) DEFAULT NULL COMMENT '订单金额(分)',
  `code_url` varchar(50) DEFAULT NULL COMMENT '订单二维码连接',
  `order_status` varchar(10) DEFAULT NULL COMMENT '订单状态',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;




CREATE TABLE `t_payment_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '支付记录id',
  `order_no` varchar(50) DEFAULT NULL COMMENT '商户订单编号',
  `transaction_id` varchar(50) DEFAULT NULL COMMENT '支付系统交易编号',
  `payment_type` varchar(20) DEFAULT NULL COMMENT '支付类型',
  `trade_type` varchar(20) DEFAULT NULL COMMENT '交易类型',
  `trade_state` varchar(50) DEFAULT NULL COMMENT '交易状态',
  `payer_total` int(11) DEFAULT NULL COMMENT '支付金额(分)',
  `content` text COMMENT '通知参数',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;




CREATE TABLE `t_product` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '商品id',
  `title` varchar(20) DEFAULT NULL COMMENT '商品名称',
  `price` int(11) DEFAULT NULL COMMENT '价格(分)',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;



insert  into `t_product`(`title`,`price`) values ('Java课程',1);
insert  into `t_product`(`title`,`price`) values ('大数据课程',1);
insert  into `t_product`(`title`,`price`) values ('前端课程',1);
insert  into `t_product`(`title`,`price`) values ('UI课程',1);



CREATE TABLE `t_refund_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '退款单id',
  `order_no` varchar(50) DEFAULT NULL COMMENT '商户订单编号',
  `refund_no` varchar(50) DEFAULT NULL COMMENT '商户退款单编号',
  `refund_id` varchar(50) DEFAULT NULL COMMENT '支付系统退款单号',
  `total_fee` int(11) DEFAULT NULL COMMENT '原订单金额(分)',
  `refund` int(11) DEFAULT NULL COMMENT '退款金额(分)',
  `reason` varchar(50) DEFAULT NULL COMMENT '退款原因',
  `refund_status` varchar(10) DEFAULT NULL COMMENT '退款状态',
  `content_return` text COMMENT '申请退款返回参数',
  `content_notify` text COMMENT '退款结果通知参数',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

19.集成Mybatis-plus

    mysql
    mysql-connector-java
    runtime


    com.baomidou
    mybatis-plus-boot-starter
    3.5.0

  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql:192.168.0.102:3306/pay?serverTimezone=GMT%2B8&characterEncoding=utf-8
    username: root
    password: root
package com.hengke.entity;

@Data
public class BaseEntity {

    
    @TableId(value = "id",type = IdType.AUTO)
    private String id;

    
    private Date createTime;

    
    private Date updateTime;
}
package com.hengke.config;

@Configuration
@MapperScan("com.hengke.dao") //持久层扫描
@EnableTransactionManagement //启动事务管理
public class MybatisPlusConfig {
}
20.Mybatis-plus补充

    
        
            src/main/java
            
            	**/*.xml
            
            false
        
    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/857808.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号