商户进件
特约商户进件
基础支付
JSAPI支付
APP支付
H5支付
Native支付
小程序支付
合单支付
付款码支付
经营能力
支付即服务
点金计划
行业方案
电商收付通
智慧商圈
微信支付分停车服务
营销工具
代金券
商家券
委托营销
支付有礼
小程序发券插件
H5发券
图片上传(营销专用)
现金红包
资金应用
分账
连锁品牌分账
风险合规
商户开户意愿确认
消费者投诉2.0
其他能力
图片上传
视频上传

开发指引

1. 接口规则

为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考“APIv3接口规则

2. 开发准备

2.1. 搭建和配置开发环境

为了帮助开发者调用开放接口,我们提供了JAVA、PHP、GO三种语言版本的开发库,封装了签名生成、签名验证、敏感信息加/解密、媒体文件上传等基础功能(更多语言版本的开发库将在近期陆续提供

测试步骤

1、根据自身开发语言,选择对应的开发库并构建项目,具体配置请参考下面链接的详细说明:

    • wechatpay-apache-httpclient,适用于使用Apache HttpClient处理HTTP的Java开发者

    • wechatpay-php(推荐)、wechatpay-guzzle-middleware,适用于PHP开发者

    注:当前开发指引接口PHP示例代码采用wechatpay-guzzle-middleware版本

    • wechatpay-go,适用于Go开发者

更多资源可前往微信支付开发者社区搜索查看

2、创建加载商户私钥、加载平台证书、初始化httpClient的通用方法


@Before
public void setup() throws IOException {
    // 加载商户私钥(privateKey:私钥字符串)
    PrivateKey merchantPrivateKey = PemUtil
            .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));
 
    // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3密钥)
    AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
            new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));
 
    // 初始化httpClient
    httpClient = WechatPayHttpClientBuilder.create()
            .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
            .withValidator(new WechatPay2Validator(verifier)).build();
}
 
@After
public void after() throws IOException {
    httpClient.close();
}

use GuzzleHttp\Exception\RequestException;
use WechatPay\GuzzleMiddleware\WechatPayMiddleware;
use WechatPay\GuzzleMiddleware\Util\PemUtil;
use GuzzleHttp\HandlerStack;
 
// 商户相关配置,
$merchantId = '1000100'; // 商户号
$merchantSerialNumber = 'XXXXXXXXXX'; // 商户API证书序列号
$merchantPrivateKey = PemUtil::loadPrivateKey('./path/to/mch/private/key.pem'); // 商户私钥文件路径
 
// 微信支付平台配置
$wechatpayCertificate = PemUtil::loadCertificate('./path/to/wechatpay/cert.pem'); // 微信支付平台证书文件路径
 
// 构造一个WechatPayMiddleware
$wechatpayMiddleware = WechatPayMiddleware::builder()
    ->withMerchant($merchantId, $merchantSerialNumber, $merchantPrivateKey) // 传入商户相关配置
    ->withWechatPay([ $wechatpayCertificate ]) // 可传入多个微信支付平台证书,参数类型为array
    ->build();
 
// 将WechatPayMiddleware添加到Guzzle的HandlerStack中
$stack = GuzzleHttp\HandlerStack::create();
$stack->push($wechatpayMiddleware, 'wechatpay');
 
// 创建Guzzle HTTP Client时,将HandlerStack传入,接下来,正常使用Guzzle发起API请求,WechatPayMiddleware会自动地处理签名和验签
$client = new GuzzleHttp\Client(['handler' => $stack]);

/*
    Package core 微信支付api v3 go http-client 基础库,你可以使用它来创建一个client,并向微信支付发送http请求
    只需要你在初始化客户端的时候,传递credential以及validator
    credential用来生成http header中的authorization信息
    validator则用来校验回包是否被篡改
    如果http请求返回的err为nil,一般response.Body 都不为空,你可以尝试对其进行序列化
    请注意及时关闭response.Body
    注意:使用微信支付apiv3 go库需要引入相关的包,该示例代码必须引入的包名有以下信息

    "context"
    "crypto/x509"
    "fmt"
    "io/ioutil"
    "log"
    "github.com/wechatpay-apiv3/wechatpay-go/core"
    "github.com/wechatpay-apiv3/wechatpay-go/core/option"
    "github.com/wechatpay-apiv3/wechatpay-go/utils"

    */
func SetUp() (opt []option.ClientOption, err error) {
    //商户号
    mchID := ""
    //商户证书序列号
    mchCertSerialNumber := ""
    //商户私钥文件路径
    privateKeyPath := ""
    //平台证书文件路径
    wechatCertificatePath := ""

    // 加载商户私钥
    privateKey, err := utils.LoadPrivateKeyWithPath(privateKeyPath)
    if err != nil {
        log.Printf("load private err:%s", err.Error())
        return nil, err
    }
    // 加载微信支付平台证书
    wechatPayCertificate, err := utils.LoadCertificateWithPath(wechatCertificatePath)
    if err != nil {
        log.Printf("load certificate err:%s",err)
        return nil, err
    }
    //设置header头中authorization信息
    opts := []option.ClientOption{
        option.WithMerchant(mchID, mchCertSerialNumber, privateKey), // 设置商户相关配置
        option.WithWechatPay([]*x509.Certificate{wechatPayCertificate}), // 设置微信支付平台证书,用于校验回包信息用
    }
    return opts, nil
}

3、基于接口的示例代码,替换请求参数后可发起测试

说明:

• 上面的开发库为微信支付官方开发库,其它没有审核或者控制下的第三方工具和库,微信支付不保证它们的安全性和可靠性

通过包管理工具引入SDK后,可根据下面每个接口的示例代码替换相关参数后进行快速测试

开发者如果想详细了解签名生成、签名验证、敏感信息加/解密、媒体文件上传等常用方法的具体代码实现,可阅读下面的详细说明:

    1.签名生成

    2.签名验证

    3.敏感信息加解密

    4.merchantPrivateKey(私钥)

    5.wechatpayCertificates(平台证书)

    6.APIV3Key(V3 key)

如想更详细的了解我们的接口规则,可查看我们的接口规则指引文档

3. 快速接入

3.1. 业务流程图

业务流程时序图:


申请单状态变化如下:


重点步骤说明:

步骤1 获取微信支付商户号:渠道商使用银行或者支付机构提供的API或者后台系统录入商家门店信息,获取商家每个门店在微信支付侧的商户号(上送给微信支付的“商户名称”字段必须与营业执照上商户名称一致,具体规则 点击查看 )。

步骤2 查询微信支付商户号授权状态:渠道商使用《获取商户号开户意愿确认状态接口》查询微信支付商户号是否完成开户意愿确认。

步骤5 提交商家资料给微信支付:渠道商根据商家类型(企业、个体户、小微、事业单位、其他组织等)准备好相关的商家资料,使用微信支付接口《提交开户意愿确认申请单》获取微信支付申请单编号。

步骤8 查询申请单审核结果:渠道商提交商家资料后,建议每隔五分钟调用《查询申请单审核结果接口》查询申请单审核结果。

申请单正常情况下的状态转换如下:

1、提交后申请单状态为“审核中”,微信支付后台会进行审核,审核通过后申请单状态变成“待联系人确认”,同时接口会提供“申请单小程序码” (小程序码的图片)。

2、联系人扫“申请单小程序码”后确认资料无误后,申请单状态变成“待账户验证”。

3、联系人将“法人确认二维码”在微信上发给法人确认后(或打款验证),申请单状态变成“审核通过”。

  •     ● 当审核结果为“审核驳回”时,请根据驳回原因重新提交商家资料,重新提交前请使用《撤销原申请单》,再次提交新的商家资料。
  •     ● 当审核结果为“待联系人确认”或“待账户验证”或“审核通过”时,接口会同时给出“申请单小程序码”。

3.2. API接入(含示例代码)

文档展示了如何使用微信支付服务端 SDK 快速接入商户开户意愿确认产品,完成与微信支付对接的部分。

注意

  • 文档中的代码示例是用来阐述 API 基本使用方法,代码中的示例参数需替换成商户自己账号及请求参数才能跑通
  • 以下接入步骤仅提供参考,请商户结合自身业务需求进行评估、修改。
3.2.1. 【服务端】提交申请单

步骤说明:服务商收集商户资料后,调用提交申请单接口,提交创建入驻申请单。

示例代码


public void Applyment() throws Exception {
  // 加载商户私钥(privateKey:私钥字符串)
  PrivateKey merchantPrivateKey = PemUtil
          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));

  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));

  CloseableHttpClient httpClient = HttpClients.createDefault();
  // 初始化httpClient
  httpClient = WechatPayHttpClientBuilder.create()
          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
          .withValidator(new WechatPay2Validator(verifier)).build();

  //请求URL
  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/apply4subject/applyment");
  // 请求body参数
  String reqdata = "{"
          + "\"business_code\":\"1111111111\","
          + "\"contact_info\": {"
          + "\"name\":\"wRNIsXOvVuTYIhVxZJCD8uJIGmNPGozCe44Ph8rD+QAJEPxw==\","
          + "\"mobile\":\"w+zPKEVNm7IDxPvK55P0OfNd5E5VXoWbRwyyGk37HiB6C/F2lUog==\","
          + "\"id_card_number\":\"rjbq82xBwMixDGA5A4x6/hqZRAYmaeM+yyjn9BU8qUBZga+mKqQ==\""
          + "},"
          + "\"subject_info\": {"
          + "\"subject_type\":\"SUBJECT_TYPE_ENTERPRISE\","
          + "\"business_licence_info\": {"
          + "\"licence_number\":\"914201123033363296\","
          + "\"licence_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\","
          + "\"merchant_name\":\"李四网络有限公司\","
          + "\"legal_person\":\"李四\","
          + "\"company_address\":\"广东省深圳市南山区xx路xx号\","
          + "\"licence_valid_date\":\"["1970-01-01","forever"]\""
          + "},"
          + "\"certificate_info\": {"
          + "\"cert_type\":\"CERTIFICATE_TYPE_2388\","
          + "\"cert_number\":\"111111111111\","
          + "\"cert_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\","
          + "\"merchant_name\":\"xx公益团体\","
          + "\"legal_person\":\"李四\","
          + "\"company_address\":\"广东省深圳市南山区xx路xx号\","
          + "\"cert_valid_date\":\"["1970-01-01","forever"]\""
          + "},"
          + "\"company_prove_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\","
          + "\"assist_prove_info\": {"
          + "\"micro_biz_type\":\"MICRO_TYPE_STORE\","
          + "\"store_name\":\"大郎烧饼\","
          + "\"store_address_code\":\"440305\","
          + "\"store_address\":\"广东省深圳市南山区xx大厦x层xxxx室\","
          + "\"store_header_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\","
          + "\"store_indoor_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\""
          + "}"
          + "},"
          + "\"identification_info\": {"
          + "\"identification_type\":\"IDENTIFICATION_TYPE_IDCARD\","
          + "\"identification_name\":\"MZnwEx6zotwIz6ctW2/iQL5z94odwP9sKiFRL8Aii3L4U74RPCPztcJOScaXsaGs82HJNU3K+46ndk7prENiPDw==\","
          + "\"identification_number\":\"ZTnn5dKGCvP4csw4XTLug/+VLB+4R6nxSPQwqSpmPVZtXmye+/3s9O+y32w==\","
          + "\"identification_valid_date\":\"["1970-01-01","forever"]\","
          + "\"identification_front_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\","
          + "\"identification_back_copy\":\"0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo\""
          + "},"
          + "\"addition_info\": {"
          + "\"confirm_mchid_list\": ["
          + "\"20001113\","
          + "\"20001112\""
          + "]"
          + "}"
          + "}";
  StringEntity entity = new StringEntity(reqdata,"utf-8");
  entity.setContentType("application/json");
  httpPost.setEntity(entity);
  httpPost.setHeader("Accept", "application/json");

  //完成签名并执行请求
  CloseableHttpResponse response = httpClient.execute(httpPost);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //处理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //处理成功,无返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}


try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/apply4subject/applyment', //请求URL
        [
            // JSON请求体
            'json' => [
                "business_code" => "1111111111", 
                "contact_info" => [
                    "name" => "wRNIsXOvVuTYIhVxZJCD8uJIGmNPGozCe44Ph8rD+QAJEPxw==", 
                    "mobile" => "w+zPKEVNm7IDxPvK55P0OfNd5E5VXoWbRwyyGk37HiB6C/F2lUog==", 
                    "id_card_number" => "rjbq82xBwMixDGA5A4x6/hqZRAYmaeM+yyjn9BU8qUBZga+mKqQ==", 
                ],
                "subject_info" => [
                    "subject_type" => "SUBJECT_TYPE_ENTERPRISE", 
                    "business_licence_info" => [
                        "licence_number" => "914201123033363296", 
                        "licence_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                        "merchant_name" => "李四网络有限公司", 
                        "legal_person" => "李四", 
                        "company_address" => "广东省深圳市南山区xx路xx号", 
                        "licence_valid_date" => "["1970-01-01","forever"]", 
                    ],
                    "certificate_info" => [
                        "cert_type" => "CERTIFICATE_TYPE_2388", 
                        "cert_number" => "111111111111", 
                        "cert_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                        "merchant_name" => "xx公益团体", 
                        "legal_person" => "李四", 
                        "company_address" => "广东省深圳市南山区xx路xx号", 
                        "cert_valid_date" => "["1970-01-01","forever"]", 
                    ],
                    "company_prove_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                    "assist_prove_info" => [
                        "micro_biz_type" => "MICRO_TYPE_STORE", 
                        "store_name" => "大郎烧饼", 
                        "store_address_code" => "440305", 
                        "store_address" => "广东省深圳市南山区xx大厦x层xxxx室", 
                        "store_header_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                        "store_indoor_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                    ],
                ],
                "identification_info" => [
                    "identification_type" => "IDENTIFICATION_TYPE_IDCARD", 
                    "identification_name" => "MZnwEx6zotwIz6ctW2/iQL5z94odwP9sKiFRL8Aii3L4U74RPCPztcJOScaXsaGs82HJNU3K+46ndk7prENiPDw==", 
                    "identification_number" => "ZTnn5dKGCvP4csw4XTLug/+VLB+4R6nxSPQwqSpmPVZtXmye+/3s9O+y32w==", 
                    "identification_valid_date" => "["1970-01-01","forever"]", 
                    "identification_front_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                    "identification_back_copy" => "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo", 
                ],
                "addition_info" => [
                    "confirm_mchid_list" => [
                        "0" => "20001113", 
                        "1" => "20001112", 
                    ],
                ]
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //处理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //处理成功,无返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 进行错误处理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
     

 //此处请求头需增加序列号
func Applyment() {
       // 初始化客户端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
//设置请求地址
  URL := "https://api.mch.weixin.qq.com/v3/apply4subject/applyment"
  //设置请求信息,此处也可以使用结构体来进行请求
  mapInfo := map[string]interface{}{
    "business_code": "1111111111",
    "contact_info": map[string]interface{}{
      "name": "wRNIsXOvVuTYIhVxZJCD8uJIGmNPGozCe44Ph8rD+QAJEPxw==",
      "mobile": "w+zPKEVNm7IDxPvK55P0OfNd5E5VXoWbRwyyGk37HiB6C/F2lUog==",
      "id_card_number": "rjbq82xBwMixDGA5A4x6/hqZRAYmaeM+yyjn9BU8qUBZga+mKqQ==",
    },
    "subject_info": map[string]interface{}{
      "subject_type": "SUBJECT_TYPE_ENTERPRISE",
      "business_licence_info": map[string]interface{}{
        "licence_number": "914201123033363296",
        "licence_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
        "merchant_name": "李四网络有限公司",
        "legal_person": "李四",
        "company_address": "广东省深圳市南山区xx路xx号",
        "licence_valid_date": "["1970-01-01","forever"]",
     },
      "certificate_info": map[string]interface{}{
        "cert_type": "CERTIFICATE_TYPE_2388",
        "cert_number": "111111111111",
        "cert_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
        "merchant_name": "xx公益团体",
        "legal_person": "李四",
        "company_address": "广东省深圳市南山区xx路xx号",
        "cert_valid_date": "["1970-01-01","forever"]",
     },
      "company_prove_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
      "assist_prove_info": map[string]interface{}{
        "micro_biz_type": "MICRO_TYPE_STORE",
        "store_name": "大郎烧饼",
        "store_address_code": "440305",
        "store_address": "广东省深圳市南山区xx大厦x层xxxx室",
        "store_header_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
        "store_indoor_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
     },
    },
    "identification_info": map[string]interface{}{
      "identification_type": "IDENTIFICATION_TYPE_IDCARD",
      "identification_name": "MZnwEx6zotwIz6ctW2/iQL5z94odwP9sKiFRL8Aii3L4U74RPCPztcJOScaXsaGs82HJNU3K+46ndk7prENiPDw==",
      "identification_number": "ZTnn5dKGCvP4csw4XTLug/+VLB+4R6nxSPQwqSpmPVZtXmye+/3s9O+y32w==",
      "identification_valid_date": "["1970-01-01","forever"]",
      "identification_front_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV-4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
      "identification_back_copy": "0P3ng6KTIW4-Q_l2FjKLZuhHjBWoMAjmVtCz7ScmhEIThCaV4BBgVwtNkCHO_XXqK5dE5YdOmFJBZR9FwczhJehHhAZN6BKXQPcs-VvdSo",
    },
    "addition_info": map[string]interface{}{
      "confirm_mchid_list": [...]interface{}{
        "20001113",
        "20001112",
     },
    },
  }

  // 发起请求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校验回包内容是否有逻辑错误
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 读取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入参说明

business_code:业务申请编号,服务商自定义的唯一编号,每个编号对应一个申请单。

subject_type:主体类型。枚举值:

SUBJECT_TYPE_ENTERPRISE:企业
SUBJECT_TYPE_INSTITUTIONS_CLONED:事业单位
SUBJECT_TYPE_INDIVIDUAL:个体工商户
SUBJECT_TYPE_OTHERS:其他组织
SUBJECT_TYPE_MICRO:小微商户

licence_number:营业执照注册号。

1、请填写营业执照上的注册号。
2、若主体类型为个体工商户或企业,注册号格式须为15位数字或18位数字|大写字母。

merchant_name:商户名称。

1、个体工商户,不能以“公司”结尾。
2、个体工商户,若营业执照上商户名称为空或为“无”,请填写"个体户+经营者姓名",如“个体户张三”。

legal_person:法人姓名。

1、只能由中文字符、英文字符、可见符号组成。
2、请填写营业执照的经营者/法定代表人姓名。

注意

更多参数、响应详情及错误码请参见提交申请单接口文档

3.2.2. 【服务端】撤销申请单

步骤说明:服务商提交申请单后需要修改信息时,或者申请单审核结果为“已驳回”时服务商要修改申请材料时,均需要先调用撤销申请单接口。

示例代码


public void CancelApplyment() throws Exception{
  // 加载商户私钥(privateKey:私钥字符串)
  PrivateKey merchantPrivateKey = PemUtil
          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));

  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));

  CloseableHttpClient httpClient = HttpClients.createDefault();
  // 初始化httpClient
  httpClient = WechatPayHttpClientBuilder.create()
          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
          .withValidator(new WechatPay2Validator(verifier)).build();

  //请求URL
  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/apply4subject/applyment/20000011111/cancel");
  StringEntity entity = new StringEntity("");
  entity.setContentType("application/json");
  httpPost.setEntity(entity);
  httpPost.setHeader("Accept", "application/json");

  //完成签名并执行请求
  CloseableHttpResponse response = httpClient.execute(httpPost);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //处理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //处理成功,无返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/apply4subject/applyment/123/cancel', //请求URL
        [
            'headers' => [ 
                'Accept' => 'application/json',
                'Content-Type'=>'application/json'

            ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //处理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //处理成功,无返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 进行错误处理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
     

func CancelApplyment() {
       // 初始化客户端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
 //设置请求地址
  URL := "https://api.mch.weixin.qq.com/v3/apply4subject/applyment/20000011111/cancel"
  //设置请求信息,此处也可以使用结构体来进行请求
  mapInfo := map[string]interface{}{}

  // 发起请求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校验回包内容是否有逻辑错误
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 读取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入参说明

applyment_id:申请单编号,微信支付分配的申请单号,申请单编号和业务申请编号至少传一个。

business_code:业务申请编号

1、服务商自定义的唯一编号。
2、每个编号对应一个申请单。

注意

更多参数、响应详情及错误码请参见撤销申请单接口文档

3.2.3. 【服务端】查询申请单审核结果

步骤说明:当服务商提交申请单后,需要定期调用此接口查询申请单的审核状态。

示例代码


public void QueryApplyment() throws Exception{
  // 加载商户私钥(privateKey:私钥字符串)
  PrivateKey merchantPrivateKey = PemUtil
          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));

  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));

  CloseableHttpClient httpClient = HttpClients.createDefault();
  // 初始化httpClient
  httpClient = WechatPayHttpClientBuilder.create()
          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
          .withValidator(new WechatPay2Validator(verifier)).build();

  //请求URL
  HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/apply4subject/applyment?applyment_id=20000011111");
  httpGet.setHeader("Accept", "application/json");

  //完成签名并执行请求
  CloseableHttpResponse response = httpClient.execute(httpGet);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //处理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //处理成功,无返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/apply4subject/applyment?applyment_id=20000011111', //请求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //处理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //处理成功,无返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 进行错误处理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
     

func QueryApplyment() {
       // 初始化客户端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
//设置请求地址
URL := "https://api.mch.weixin.qq.com/v3/apply4subject/applyment?applyment_id=20000011111"
  // 发起请求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校验回包内容是否有逻辑错误
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 读取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
} 
}
    

重要入参说明

applyment_id:申请单编号,微信支付分配的申请单号,申请单编号和业务申请编号至少传一个。

business_code:业务申请编号

1、服务商自定义的唯一编号。
2、每个编号对应一个申请单。

注意

更多参数、响应详情及错误码请参见撤销申请单接口文档

3.2.4. 【服务端】获取商户开户意愿确认状态

步骤说明:当服务商需要确认微信支付子商户号是否完成确认时,如果调用此接口提到“已授权”状态,则说明该商户号已完成开户意愿确认。

示例代码


public void QueryMerchantsState() throws Exception{
  // 加载商户私钥(privateKey:私钥字符串)
  PrivateKey merchantPrivateKey = PemUtil
          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));

  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));

  CloseableHttpClient httpClient = HttpClients.createDefault();
  // 初始化httpClient
  httpClient = WechatPayHttpClientBuilder.create()
          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
          .withValidator(new WechatPay2Validator(verifier)).build();

  //请求URL
  HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/apply4subject/applyment/merchants/20000011111/state");
  httpGet.setHeader("Accept", "application/json");

  //完成签名并执行请求
  CloseableHttpResponse response = httpClient.execute(httpGet);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //处理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //处理成功,无返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/apply4subject/applyment/merchants/20000011111/state', //请求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //处理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //处理成功,无返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 进行错误处理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
     

func QueryMerchantsState() {
       // 初始化客户端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
//设置请求地址
URL := "https://api.mch.weixin.qq.com/v3/apply4subject/applyment/merchants/20000011111/state"
  // 发起请求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校验回包内容是否有逻辑错误
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 读取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入参说明

sub_mchid:特约商户号,微信支付分配的特约商户的唯一标识。

注意

更多参数、响应详情及错误码请参见获取商户开户意愿确认状态接口文档

4. 常见问题

Q1:商户开户意愿调用“提交申请单”返回:暂未查询到该营业执照注册号,请检查营业执照注册号是否填写正确

A1:请求参数“营业执照注册号(licence_number)”填写错误,请填写营业执照上的注册号,若主体类型为个体工商户或企业,注册号格式须为15位数字或18位数字|大写字母

Q2:商户开户意愿调用“提交申请单”返回:系统繁忙,请稍后重试

A2:请按照以下几点检查:

1. 系统异常,请使用相同参数稍后重新调用

2. 请求参数错误,请确认参数的大小写、参数名、格式是否与接口文档一致

3. 请求头里面的参数mchid错误,也会报这个错误,请检查确认

Q3:商户开户意愿调用“撤消申请单”返回:查询申请单不存在,请检查申请单号是否正确

A3:请求参数申请单编号(applyment_id)填写错误或没有填写,请填写微信支付分配的申请单号,申请单编号和业务申请编号至少传一个

Q4:商户开户意愿调用“获取特约商户授权状态”返回:Authorization不合法

A4:请按照以下几点检查:

1. Authorization头认证类型或签名信息错误,请严格按照文档要求填写参数

    a. Authorization头认证类型目前为WECHATPAY2-SHA256-RSA2048

    b. Authorization头签名信息包括发起请求的商户(渠道商)的商户号mchid

        商户API证书序列号serial_no,用于声明所使用的证书
        请求随机串nonce_str
        时间戳timestamp
        签名值signature

2. Authorization头参数存在换行,实际数据应在一行

Q5:商户开户意愿调用“提交申请单”返回:商户未申请过证书,请到商户平台上申请证书授权机构颁发的证书

A5:请按照错误提示,到商户平台上申请下载API证书并正确使用,请参考以下几点:

Q6:商户开户意愿调用“撤销申请单”返回:无法将传入参数“申请单编号”转换为uint64类型

A6:请求参数类型填写错误,正确的参数类型是uint64



技术咨询

文档反馈