微信付款码支付, 扫码枪支付 v3版实现记录

一  登录微信商户号, 账户中心, API 安全,开通相关证书  保存好相关文件和密钥

二  产品中心,开通付款码支付,  APPID账号管理中管理一个公众号或小程序, 这样才有 appid

三  开发文档

https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1

https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_4

这个最重要:

付款码支付 - 付款码支付 | 微信支付商户文档中心 

四 下载demo

SDK

我们也提供多种编程语言的开发库,开发者可以根据自己的需要,选择对应的库。

 

五 修改  QuickStart

package weixin.shpay;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.model.*;

 
public class QuickStart {
    public static String appId = "wxc03 fe77";
    /**
     * 商户号
     */
    public static String merchantId = "17 66";
    /**
     * 商户API私钥路径
     */
    public static String privateKeyPath = "/.../微信商户支付证书/apiclient_key.pem";
    /**
     * 商户证书序列号
     */
    public static String merchantSerialNumber = "22038F  5F8FD4C66F9";
    /**
     * 商户APIV3密钥
     */
    public static String apiV3Key = "xxx";
 

    //商户号该产品权限未开通,请前往商户平台>产品中心检查后重试
    //需要先在 商户平台  产品中心开通 付款码支付
    public static void main(String[] args) {
        // 使用自动更新平台证书的RSA配置
        // 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        JsapiService service = new JsapiService.Builder().config(config).build();
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();

        amount.setTotal(10);
        request.setAmount(amount);
        request.setAppid(appId);
        request.setMchid(merchantId);
        request.setDescription("企业信息化资料下载");

        //info
        SceneInfo info= new SceneInfo();
        info.setDeviceId("linyi");
        StoreInfo store=new StoreInfo();
        store.setId("1"); //不要有多余的参数
        info.setStoreInfo(store);

        request.setSceneInfo(info);
        //request.setNotifyUrl("https://。。。/pay_notify");  //这个一定不要有
        request.setOutTradeNo("zzy_trade_002");

        //付款码
        Payer payer = new Payer();
        payer.setAuth_code("扫描器扫进来的字符串,即 用户的付款码" );
        request.setPayer(payer);


        PrepayResponse response = service.prepay(request);
        System.out.println(response.getPrepayId());
    }
}
Payer 修改一下
// Copyright 2021 Tencent Inc. All rights reserved.
//
// JSAPI支付
//
// JSAPI支付API
//
// API version: 1.2.3

// Code generated by WechatPay APIv3 Generator based on [OpenAPI
// Generator](https://openapi-generator.tech); DO NOT EDIT.

package com.wechat.pay.java.service.payments.jsapi.model;

import static com.wechat.pay.java.core.util.StringUtil.toIndentedString;

import com.google.gson.annotations.SerializedName;

/** Payer */
public class Payer {
  /** 用户标识 说明:用户在商户appid下的唯一标识。 */
  //@SerializedName("openid")
  //private String openid;
  @SerializedName("auth_code")
  private String auth_code;

  //public String getOpenid() {
  //  return openid;
  //}
  //
  //public void setOpenid(String openid) {
  //  this.openid = openid;
  //}
  public String getAuth_code() {
    return auth_code;
  }

  public void setAuth_code(String auth_code) {
    this.auth_code = auth_code;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Payer {\n");
    sb.append("    auth_code: ").append(toIndentedString(auth_code)).append("\n");
    sb.append("}");
    return sb.toString();
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值