资讯详情

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

image-20220501171013394

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>         <!-- Swagger -->         <dependency>             <groupId>io.springfox</groupId>             <artifactId>springfox-swagger2</artifactId>             <version>2.7.0</version>         </dependency>         <!--Swagger-ui-->         <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </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.projectlombok</groupId>
	<artifactId>lombok</artifactId>
	<version>1.18.8</version>
</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 <T> * @return */
    public static<T> R<T> success(){ 
        
        return new R();
    }

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

    /** * 通用返回失败 * @param resultCode * @param <T> * @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>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.0</version>
</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/java</directory>
            <includes>
            	<include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

标签: p20j3m密封连接器p20k2apjg连接器p20j9aqjg连接器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台