微信支付

微信支付,第1张

微信支付(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

    <dependencies>
        
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger2artifactId>
            <version>2.7.0version>
        dependency>
        
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger-uiartifactId>
            <version>2.7.0version>
        dependency>
    dependencies>

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

<dependency>
	<groupId>org.projectlombokgroupId>
	<artifactId>lombokartifactId>
	<version>1.18.8version>
dependency>

R

package com.hengke.vo;

@Data
public class R<T> 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;
    }
    /**
     * 有参构造器
     * @param obj
     */
    public R(T obj) {
        this.code = 200;
        this.data = obj;
        this.success = true;
    }

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

    /**
     * 通用返回成功(没有返回结果)
     * @param 
     * @return
     */
    public static<T> R<T> success(){
        return new R();
    }

    /**
     * 返回成功(有返回结果)
     * @param data
     * @param 
     * @return
     */
    public static<T> R<T> success(T data){
        return new R<T>(data);
    }

    /**
     * 通用返回失败
     * @param resultCode
     * @param 
     * @return
     */
    public static<T> R<T> failure(RCode resultCode){
        return  new R<T>(resultCode);
    }
}
18.数据库
USE `payment_demo`;

/*Table structure for table `t_order_info` */

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;


/*Table structure for table `t_payment_info` */

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;


/*Table structure for table `t_product` */

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;

/*Data for the table `t_product` */

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);

/*Table structure for table `t_refund_info` */

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
<dependency>
    <groupId>mysqlgroupId>
    <artifactId>mysql-connector-javaartifactId>
    <scope>runtimescope>
dependency>
<dependency>
    <groupId>com.baomidougroupId>
    <artifactId>mybatis-plus-boot-starterartifactId>
    <version>3.5.0version>
dependency>
  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补充
<build>
    <resources>
        <resource>
            <directory>src/main/javadirectory>
            <includes>
            	<include>**/*.xmlinclude>
            includes>
            <filtering>falsefiltering>
        resource>
    resources>
build>

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/868747.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存