微信小程序v3支付

本文档介绍了如何实现微信小程序v3支付。首先,按照官方文档申请支付所需内容,包括接入前准备和下单API。然后,配置代码实现,如在application.yml中设置微信支付参数,并引入相关依赖。最后,通过回调域名(HTTPS)完成支付流程,内网穿透工具可用于本地测试。
摘要由CSDN通过智能技术生成

目录

1、按照微信官方文档申请相关内容

2、代码实现


具体详情如下:小程序支付的交互图如下:

1、按照微信官方文档申请相关内容

  • 首先准备支付需要相关的内容,具体可参考官方文档

接入前准备-小程序支付 | 微信支付商户平台文档中心https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_8_1.shtml微信支付-开发者文档https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml

下单APIicon-default.png?t=M666https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1&index=1
wechatpay-apiv3 · GitHubthe official WeChatPay API-Infra team. wechatpay-apiv3 has 7 repositories available. Follow their code on GitHub.https://github.com/wechatpay-apiv3简介-接口规则 | 微信支付商户平台文档中心icon-default.png?t=M666https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay-1.shtml

2、代码实现

  • 然后在配置文件中配置一下微信需要的相关内容

如:application.yml中配置如下内容

# 微信相关--小程序配置
weixinxg:
  # 小程序
  appId: wx1axxxxxxxxxxxxxxxxx
  # 小程序密钥--secret 
  secret: 6d2cxxxxxxxxxxxxxxxxx
  #1、微信支付商户号 
  mchId: 16xxxxxxxxxxxxxxxxx
  #2、微信支付商户密钥 wx1Zxxxxxxxxxxxxxxxxx
  mchKey: wx1Zxxxxxxxxxxxxxxxxx
  #3-1 证书密码默认为您的商户号 apiV3Key:V3密钥
  v3Key: wx1ZF2xxxxxxxxxxxxxxxxx
  #3-2 商户证书序列号-mchSerialNo
  mchSerialNo: 140D24Cxxxxxxxxxxxxxxxxx
  #3-3 商户私钥地址-privateKeyPath
  privateKeyPath: D:\xxx\xx\xx\xx\wx\apiclient_key.pem

#支付回调通知地址 必须为公网可访问的域名地址 且权限放开
routine:
  notify: https://weixin.qq.com/
  • 导入maven依赖
        <dependency>
            <groupId>com.github.wxpay</groupId>
            <artifactId>wxpay-sdk</artifactId>
            <version>0.0.3</version>
        </dependency>

        <!--<dependency>
            <groupId>com.github.wechatpay-apiv3</groupId>
            <artifactId>wechatpay-apache-httpclient</artifactId>
            <version>0.2.2</version>
        </dependency>-->

        <dependency>
            <groupId>com.github.wechatpay-apiv3</groupId>
            <artifactId>wechatpay-apache-httpclient</artifactId>
            <version>0.4.7</version>
        </dependency>

  • 具体实现代码

接收对象的类

public class AppletCoOrderInfoDto extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** id */
    private Long id;

    /** 订单单号 */
    @Excel(name = "订单单号")
    private String orderNo;

    /** 用户id */
    @Excel(name = "用户id")
    private String userId;

    /** 订单状态1、待发货 2、待收货 3、确认收货/已完成 5、已关闭 */
    @Excel(name = "订单状态1、待发货 2、待收货 3、确认收货/已完成 5、已关闭")
    private String orderStatus;

    /** 商品id */
    @Excel(name = "商品id")
    private Long commodityId;

    /** 删除标记(0:显示,1:隐藏) */
    @Excel(name = "删除标记(0:显示,1:隐藏)")
    private String delFag;

    /** 支付方式1、货到付款;2、在线支付 */
    @Excel(name = "支付方式1、货到付款;2、在线支付")
    private String paymentWay;

    /** 是否支付0、未支付 1、已支付 */
    @Excel(name = "是否支付0、未支付 1、已支付")
    private String isPay;

    /**商品名称 */
    @Excel(name = "商品名称")
    private String name;

    /** 运费金额 */
    @Excel(name = "运费金额")
    private BigDecimal freightPrice;

    /** 销售金额 */
    @Excel(name = "销售金额")
    private BigDecimal salesPrice;

    /** 付款时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "付款时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date deliveryTime;

    /** 发货时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "发货时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date receiverTime;

    /** 成交时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "成交时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date closingTime;

    /** 买家留言 */
    @Excel(name = "买家留言")
    private String userMessage;

    /** 支付交易ID */
    @Excel(name = "支付交易ID")
    private String transactionId;

    /** 物流id */
    @Excel(name = "物流id")
    private Long logisticsId;

    /** 支付金额(销售金额+运费金额) */
    @Excel(name = "支付金额", readConverterExp = "销=售金额+运费金额")
    private BigDecimal paymentPrice;

    /** 预留字段1 */
    @Excel(name = "预留字段1")
    private String resOne;

    /** 预留字段2 */
    @Excel(name = "预留字段2")
    private String resTwo;
    
    private String createBy;
	/** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	/** 更新者 */
	private String updateBy;
	
	/** 更新时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date updateTime;
	
	//private List<AppletCoOrderItemDto> listOrderItem;
	//private AppletCoOrderLogisticsDto orderLogistics;
	/** 店铺id */
	private Long merchantId;
	/** 店铺名称 */
	private String shopsName;
	/** 快递公司 */
	private String logistics;
	/** 快递单号 */
    private String logisticsNo;
	
	
	/** Get和Set方法 */
	……
}
Controller
    /**
     * 微信小程序--支付接口
     * api-v3
     */
    @PostMapping(value = "/pay3")
    public AjaxResult unifiedOrderVthird(@RequestBody AppletCoOrderInfoDto coOrderInfo) throws Exception {
        return AjaxResult.success(appletWxPayService.unifiedOrderVthird(coOrderInfo));
    }


    /**
     * 微信小程序--支付接口
     * api-v2
     */
    @PostMapping(value = "/pay2")
    public AjaxResult unifiedOrder(@RequestBody AppletCoOrderInfoDto coOrderInfo) throws Exception {
        return AjaxResult.success(appletWxPayService.unifiedAppletOrder(coOrderInfo));
    }

Service

    /**
     * 统一下单 V3 接口
     * @return
     */
    public JSONObject unifiedOrderVthird(AppletCoOrderInfoDto coOrderInfo) throws Exception;

    /**
     * 统一下单 V3 接口
     * @return
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值