为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考“APIv3接口规则”
为了帮助开发者调用开放接口,我们提供了JAVA、PHP、GO三种语言版本的开发库,封装了签名生成、签名验证、敏感信息加/解密、媒体文件上传等基础功能(更多语言版本的开发库将在近期陆续提供)
测试步骤:
1、根据自身开发语言,选择对应的开发库并构建项目,具体配置请参考下面链接的详细说明:
• wechatpay-java(推荐)wechatpay-apache-httpclient,适用于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();
}
3、基于接口的示例代码,替换请求参数后可发起测试
说明:
• 上面的开发库为微信支付官方开发库,其它没有审核或者控制下的第三方工具和库,微信支付不保证它们的安全性和可靠性
通过包管理工具引入SDK后,可根据下面每个接口的示例代码替换相关参数后进行快速测试
• 开发者如果想详细了解签名生成、签名验证、敏感信息加/解密、媒体文件上传等常用方法的具体代码实现,可阅读下面的详细说明:
1.签名生成
2.签名验证
3.敏感信息加解密
• 如想更详细的了解我们的接口规则,可查看我们的接口规则指引文档
1、 平台需确认是否已开通收付通工具箱,详细可前往平台收付通介绍查看。
2、待进件的二级商户是否符合进件要求,相关要求可以前往二级商户入驻介绍查看。
重要步骤说明:
步骤一: 平台通过请求二级商户进件接口帮助二级商户提交商户进件资料。进件参数中包含了敏感信息参数,此类参数要求进行加密,详见 接口规则。
步骤二: 提交进件资料后,平台需通过微信支付返回的“微信支付申请单号”和“业务申请编号”来请求查询申请状态API接口查询二级商户进件状态。
步骤三: 进件成功后,若二级商户需修改结算账号时,平台可通过请求修改商户结算账号API接口来帮助二级商户修改账号信息。
步骤四: 平台通过请求查询商户结算账号API接口来查询修改情况。
本文档展示了如何使用微信支付服务端 SDK 快速接入平台收付通产品,完成与微信支付对接的部分。
注意:
步骤说明:平台可使用该接口,帮助其二级商户进件成为微信支付商户。
示例代码
public void Applyments() throws Exception{
//请求URL
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/ecommerce/applyments/");
// 请求body参数
String reqdata = "{"
+ "\"organization_type\":\"2\","
+ "\"business_license_info\": {"
+ "\"business_license_copy\":\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4\","
+ "\"business_license_number\":\"123456789012345678\","
+ "\"merchant_name\":\"腾讯科技有限公司\","
+ "\"legal_person\":\"张三\""
+ "},"
+ "\"organization_cert_info\": {"
+ "\"organization_copy\":\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4\","
+ "\"organization_time\":\"[\"2014-01-01\","\"长期\"]\","
+ "\"organization_number\":\"12345679-A\""
+ "},"
+ "\"id_card_info\": {"
+ "\"id_card_copy\":\"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ\","
+ "\"id_card_national\":\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4\","
+ "\"id_card_name\":\"pVd1HJ6zyvPedzGaV+X3qtmrq9bb9tPROvwia4ibL+F6mfjbzQIzfb3HHLEjZ4YiR/cJiCrZxnAqi+pjeKIEdkwzXRAI7FUhrfPK3SNjaBTEu9GmsugMIA9r3x887Q+ODuC8HH2nzAn7NGpE/e3yiHgWhk0ps5k5DP/2qIdGdONoDzZelrxCl/NWWNUyB93K9F+C1JX2IMttdY+aQ6zBlw0xnOiNW6Hzy7UtC+xriudjD5APomty7/mYNxLMpRSvWKIjOv/69bDnuC4EL5Kz4jBHLiCyOb+tI0m2qhZ9evAM+Jv1z0NVa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==\","
+ "\"id_card_number\":\"UZFETyabYFFlgvGh6R4vTzDELiPas3jC94/srAbSaPaWSM+1rhGLcsybPLeJdVOpCeDxNBMDK+/N0nOiZZ4ka9+5RgzvA2rJx+NztYUbN209rq0Y/NP50T9yk0m6A4xUoFWgk/8qteRHtP5VHahNhSh8nHo31V33t8edSlN9HJG6diRj7p5JPImDyM1q56+p25edl3+cOtuZtj8TJDl/hB+GaWve9X1WUpkZbKlJgBxp+XhaW707k9XrILvfD+rSGTOeU/ev4/OiEb5W4WPGJ+3iLoQvhnz3+aQZX9+gn9uRzWcHu2Kr17fhsM+MRkgVcwzI2UqhR9iuGTunRPRVFg==\","
+ "\"id_card_valid_time\":\"2026-06-06\""
+ "},"
+ "\"need_account_info\":true,"
+ "\"account_info\": {"
+ "\"bank_account_type\":\"74\","
+ "\"account_name\":\"fTA4TXc8yMOwFCYeGPktOOSbOBei3KA8RAMO9h/5Y0ZMR46viedrDurCbQTC/sCC9BWuG5oeR8flymK/Z4dN0/7XDSDfqT5Nggq9WwTL+OZdMorqTE6Z0G3f3Bi3c+GVvYOCZyVdoinksPEUwyosEtwupM3ufXSZT36DvsS8K9jOBnIXjGaQtP94FFlh58WR0GuEkMt9KT2NuA+fE4KDScRzSZn3TL5Izdt+7anPS6Uh4K7wPnUWHGxCQdZu0G4B4YjP7ync8UeLu4jAkCziq4lngnU3rKfFiqwMtyOA179x15za7+kWmo2hfaC7xumTqXR7/NyRHpFKXURQFcmmw==\","
+ "\"account_bank\":\"工商银行\","
+ "\"bank_address_code\":\"110000\","
+ "\"bank_branch_id\":\"402713354941\","
+ "\"bank_name\":\"施秉县农村信用合作联社城关信用社\","
+ "\"account_number\":\"d+xT+MQCvrLHUVDWv/8MR/dB7TkXM2YYZlokmXzFsWs35NXUot7C0NcxIrUF5FnxqCJHkNgKtxa6RxEYyba1+VBRLnqKG2fSy/Y5qDN08Ej9zHCwJjq52Wg1VG8MRugli9YMI1fI83KGBxhuXyemgS/hqFKsfYGiOkJqjTUpgY5VqjtL2N4l4z11T0ECB/aSyVXUysOFGLVfSrUxMPZy6jWWYGvT1+4P633f+R+ki1gT4WF/2KxZOYmli385ZgVhcR30mr4/G3HBcxi13zp7FnEeOsLlvBmI1PHN4C7Rsu3WL8sPndjXTd75kPkyjqnoMRrEEaYQE8ZRGYoeorwC+w==\""
+ "},"
+ "\"contact_info\": {"
+ "\"contact_type\":\"65\","
+ "\"contact_name\":\"pVd1HJ6zyvPedzGaV+X3qtmrq9bb9tPROvwia4ibL+F6mfjbzQIzfb3HHLEjZ4YiR/cJiCrZxnAqi+pjeKIEdkwzXRAI7FUhrfPK3SNjaBTEu9GmsugMIA9r3x887Q+ODuC8HH2nzAn7NGpE/e3yiHgWhk0ps5k5DP/2qIdGdONoDzZelrxCl/NWWNUyB93K9F+jC1JX2IMttdY+aQ6zBlw0xnOiNW6Hzy7UtC+xriudjD5APomty7/mYNxLMpRSvWKIjOv/69bDnuC4EL5Kz4jBHLiCyOb+tI0m2qhZ9evAM+Jv1z0NVa8MRtelw/wDa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lu5zn6o2uZpBhAsQwd3QAjw==\""
+ "},"
+ "\"sales_scene_info\": {"
+ "\"store_name\":\"爱烧烤\","
+ "\"store_url\":\"http://www.qq.com\","
+ "\"store_qr_code\":\"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ\""
+ "},"
+ "\"merchant_shortname\":\"爱烧烤\","
+ "\"out_request_no\":\"APPLYMENT_00000000001\","
+ "\"qualifications\":\"[\"jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ\","\"47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4"]\","
+ "\"business_addition_pics\":\"["jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAxhBTEO_PvWkfSCJ3zVIn001D8daLC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ","47ZC6GC-vnrbEny__Ie_An5-tCpqxucuxi-vByf3Gjm7KE53JXvGy9tqZm2XAUf-4KGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4"]\","
+ "\"business_addition_desc\":\"特殊情况,说明原因\""
+ "}";
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();
}
}
更多参数、响应详情及错误码请参见二级商户进件申请API接口文档
步骤说明:平台可使用该接口,帮助其二级商户查询进件状态。
示例代码:
public void QueryApplyments() throws Exception{
//请求URL
HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/ecommerce/applyments/out-request-no/APPLYMENT_00000000001");
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();
}
}
更多参数、响应详情及错误码请参见查询进件申请状态API接口文档
步骤说明:二级商户结算账号错误或者变更,平台可通过该接口进行修改。
示例代码:
public void UpdataSettlement() throws Exception{
//请求URL
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/modify-settlement");
// 请求body参数
String reqdata = "{"
+ "\"account_type\":\"ACCOUNT_TYPE_BUSINESS\","
+ "\"account_bank\":\"工商银行\","
+ "\"bank_address_code\":\"110000\","
+ "\"bank_name\":\"施秉县农村信用合作联社城关信用社\","
+ "\"bank_branch_id\":\"402713354941\","
+ "\"account_number\":\"d+xT+MQCvrLHUVDWv/8MR/dB7TkXM2YYZlokmXzFsWs35NXUot7C0NcxIrUF5FnxqCJHkNgtxa6RxEYyba1+VBRLnqKG2fSy/Y5qDN08Ej9zHCwJjq52Wg1VG8MRugli9YMI1fI83KGBxhuXyemgS/hqFKsfYGiOJqjTUpgY5VqjtL2N4l4z11T0ECB/aSyVXUysOFGLVfSrUxMPZy6jWWYGvT1+4P633f+R+ki1gT4WF/2KxZOYmi385ZgVhcR30mr4/G3HBcxi13zp7FnEeOsLlvBmI1PHN4C7Rsu3WL8sPndjXTd75kPkyjqnoMRrEEaQE8ZRGYoeorwC+w==\""
+ "}";
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();
}
}
更多参数、响应详情及错误码请参见修改结算账号API接口文档
步骤说明:平台可使用该接口,帮助其二级商户查询结算账号。
示例代码:
public void GetSettlement() throws Exception{
//请求URL
HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/1900006491/settlement");
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();
}
}
更多参数、响应详情及错误码请参见查询结算账号API接口文档
A:返回这个报错,请求参数中请上传“特殊资质(qualifications)”字段
A:主体类型为“党政、机关及事业单位 /其他组织”时,只能汇款验证,是不会返回法人验证链接的。接入流程说明文档中的第4点也有说明
A:申请状态“已冻结”是审核人员认为有风险时候,会冻结。开户成功后,基本不会出现“已冻结”
A:参数merchant_shortname命中敏感字段,请更换一个新的简称重新提交
A:参数id_card_valid_time错误,请严格按照文档要求传参,这个参数的规则如下:
1)请填写身份证有效期的结束时间,注意参照示例中的格式
2)若证件有效期为长期,请填写:长期
3)证件有效期需大于60天