### Download Bill Request Example Source: https://pay.weixin.qq.com/doc/v3/partner/4014314390 This example demonstrates how to make a GET request to download the bill file data stream after signing the download URL. ```shell $ curl https://api.mch.weixin.qq.com/v3/billdownload/file?token=xxx -H ' Authorization: WECHATPAY2-SHA256-RSA2048 mchid="1900009191", nonce_str="593BEC0C930BF1AFEB40B4A08C8FB242", signature="uOVRnA4qG/MNnYzdQxJanN+zU+lTgIcnU9BxGw5dKjK+VdEUz2FeIoC+D5sB/LN+nGzX3hfZg6r5 wT1pl2ZobmIc6p0ldN7J6yDgUzbX8Uk3sD4a4eZVPTBvqNDoUqcYMlZ9uuDdCvNv4TM3c1WzsXUrExwVkI 1XO5jCNbgDJ25nkT/c1gIFvqoogl7MdSFGc4W4xZsqCItnqbypR3RuGIlR9h9vlRsy7zJR9PBI83X8al LDIfR1ukt1P7tMnmogZ0cuDY8cZsd8ZlCgLadmvej58SLsIkVxFJ8XyUgx9FmutKSYTmYtWBZ0+tNvfGmbXU7cob8H/ 4nLBiCwIUFluw==",timestamp="1554208460",serial_no="1DDE55AD98ED71D6EDD4A4A16996DE7B47773A8C"' ``` -------------------------------- ### Example Invoice Download Request URL Source: https://pay.weixin.qq.com/doc/v3/partner/4015792569 This is an example of a GET request URL used to download an invoice file. It includes parameters like token, merchant ID, sub-merchant ID, and invoice details. ```http https://pay.wechatpay.cn/invoicing/fapiao/fapiao-file?token=xxxxxx&mchid=1462377&OpenID=o3v4BuMFNejs-gAOfXgS&invoice_code=14403220&invoice_no=0923&fapiao_id=fapiao-id-14&file_format=PDF ``` -------------------------------- ### GET Request Signature Verification Example Source: https://pay.weixin.qq.com/doc/v3/partner/4012365880 Example demonstrating signature verification for a GET request, specifically for querying order status by merchant order number. ```APIDOC ## GET /v3/pay/transactions/out-trade-no/{out_trade_no}?mchid={mchid} ### Description This endpoint is used to query the status of an order using the merchant's order number. ### Method GET ### Endpoint https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}?mchid={mchid} ### Parameters #### Path Parameters - **out_trade_no** (string) - Required - The merchant's unique order number. - **mchid** (string) - Required - The merchant ID. #### Query Parameters (None explicitly documented for this example, but mchid is part of the URL) ### Request Example ``` GET https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/Tencentwechatpay0000457?mchid=1900006891 ``` ### Signature Information (for verification) - **HTTP Method**: GET - **Canonical URL**: /v3/pay/transactions/out-trade-no/Tencentwechatpay0000457?mchid=1900006891 - **Timestamp**: 1723789635 - **Nonce String**: 614275b63d789bd3a7a472c63d809552 - **Plaintext for Signature**: ``` GET /v3/pay/transactions/out-trade-no/Tencentwechatpay0000457?mchid=1900006891 1723793954 614275b63d789bd3a7a472c63d809552 ``` - **Signature**: mm/2CMGxo5qDKNk1i7Szn0IiwAUPlfrpeCE1udNzEvUmohKYO8e40+3hNUTZVXwXUO4qOik/gqrPmXmppF37xa9aIe/oPzPLHaIpSCnDL1VBjl60ztc66kVkFQc/1LvYFwDzpsbnxq1B/DeMTTB6oXekfEDuZATI/erJ+B63BY+Cm6hKMDoPyaHn5hoFSTyfuLacxei+a0sPbFGGklDzr/vxh0Pta3Gp4vCvtnt7cmT+72h5Z7cijiYfw7JHzWt9VcK8Z1r9f6hMuYx6y2BIaEIcczZxq9fLxwRXZRYC2pRwUdrhADFHAUExm5oglZLgZ5QFc1dWijBGzVWzA40O7w== ``` -------------------------------- ### GET Request Signature Verification Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365352 This example demonstrates how to construct and verify the signature for a GET request to the WeChat Pay API v3, specifically for querying order status by merchant order number. ```APIDOC ## GET /v3/pay/transactions/out-trade-no/{out_trade_no}?mchid={mchid} ### Description This endpoint is used to query the status of an order using the merchant's order number. Signature verification is crucial for this request. ### Method GET ### Endpoint `https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}?mchid={mchid}` ### Parameters #### Path Parameters - **out_trade_no** (string) - Required - The merchant's order number. - **mchid** (string) - Required - The merchant ID. #### Query Parameters (None explicitly documented for signature, but `mchid` is part of the URL) #### Request Body (Not applicable for GET requests) ### Signature Information - **HTTP Method**: `GET` - **Signed URL**: `/v3/pay/transactions/out-trade-no/Tencentwechatpay0000457?mchid=1900006891` - **Timestamp**: `1723789635` (Used in signature calculation) - **Nonce String**: `614275b63d789bd3a7a472c63d809552` (Used in signature calculation) ### Plaintext for Verification ``` GET /v3/pay/transactions/out-trade-no/Tencentwechatpay0000457?mchid=1900006891 1723789635 614275b63d789bd3a7a472c63d809552 ``` ### Signature `mm/2CMGxo5qDKNk1i7Szn0IiwAUPlfrpeCE1udNzEvUmohKYO8e40+3hNUTZVXwXUO4qOik/gqrPmXmppF37xa9aIe/oPzPLHaIpSCnDL1VBjl60ztc66kVkFQc/1LvYFwDzpsbnxq1B/DeMTTB6oXekfEDuZATI/erJ+B63BY+Cm6hKMDoPyaHn5hoFSTyfuLacxei+a0sPbFGGklDzr/vxh0Pta3Gp4vCvtnt7cmT+72h5Z7cijiYfw7JHzWt9VcK8Z1r9f6hMuYx6y2BIaEIcczZxq9fLxwRXZRYC2pRwUdrhADFHAUExm5oglZLgZ5QFc1dWijBGzVWzA40O7w==` ### Notes - Ensure the `apiclient_cert.pem` is used for verification. - The timestamp and nonce string in the signature must match those in the `Authorization` header. - For GET requests, the request body is empty. ``` -------------------------------- ### JSAPI Order Creation Request Example Source: https://pay.weixin.qq.com/doc/v3/partner/4012088031 Demonstrates how to initiate a pre-pay transaction for JSAPI/mini-program scenarios. Ensure to replace placeholder parameters with your actual account and request details. ```java JAVA ``` -------------------------------- ### Query Coupon and Batch Information Demo Source: https://pay.weixin.qq.com/doc/v3/merchant/4015894256 Main entry point for demonstrating coupon and batch query operations. Initializes necessary parameters and calls various query methods. ```java package com.java.coupon; import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831 // 使用商户平台条件查询批次列表接口,参考:https://pay.weixin.qq.com/doc/v3/merchant/4012460489 import com.java.demo.ListStocks; import static com.java.demo.ListStocks.*; // 使用商户平台查询批次详细接口,参考:https://pay.weixin.qq.com/doc/v3/merchant/4012460564 import com.java.demo.QueryStock; import static com.java.demo.QueryStock.*; // 使用商户平台查询代金券可用商户接口,参考:https://pay.weixin.qq.com/doc/v3/merchant/4012463358 import com.java.demo.ListAvailableMerchants; import static com.java.demo.ListAvailableMerchants.*; // 使用商户平台查询代金券可用单品接口,参考:https://pay.weixin.qq.com/doc/v3/merchant/4012463442 import com.java.demo.ListAvailableSingleitems; import static com.java.demo.ListAvailableSingleitems.*; // 使用商户平台 根据商户号查用户的券 接口,参考:https://pay.weixin.qq.com/doc/v3/merchant/4012534690 import com.java.demo.ListCouponsByFilter; import static com.java.demo.ListCouponsByFilter.*; // 使用商户平台查询代金券详情接口。参考:https://pay.weixin.qq.com/doc/v3/merchant/4012486942 import com.java.demo.QueryCoupon; import static com.java.demo.QueryCoupon.*; public class QueryCouponAndStockDemo { // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 // https://pay.weixin.qq.com/doc/v3/merchant/4013070756 private static String mchid = "19xxxxxxxx"; // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 private static String certificateSerialNo = "1DDE55AD98Exxxxxxxxxx"; // 商户API证书私钥文件路径,本地文件路径 private static String privateKeyFilePath = "/path/to/apiclient_key.pem"; // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 private static String wechatPayPublicKeyId = "PUB_KEY_ID_xxxxxxxxxxxxx"; // 微信支付公钥文件路径,本地文件路径 private static String wechatPayPublicKeyFilePath = "/path/to/wxp_pub.pem"; public static void main(String[] args) { QueryCouponAndStockDemo demo = new QueryCouponAndStockDemo(); String stockId = "example_stockId"; // 需要查询的批次号 String creatorMchid = mchid; // 创建批次的商户号 String couponId = "example_couponId"; // 需要查询的优惠券券号 String appid = "example_appid"; // 微信为发券方商户分配的公众账号ID String openid = "example_openid"; // 用户在该 appid 下对应的 openid,用于标识需要查询的用户 // 1. 查询代金券批次的相关操作 // 1.1 条件查询代金券批次列表 // 可以根据批次创建商户号、创建的时间区间和当前状态查询商户批次列表 ListStocks.StockCollection stockCollection = demo.listStocks(); // 1.2 查询批次详情 QueryStock.Stock stock = demo.queryStock(creatorMchid, stockId); // 1.3 查询代金券批次可用商户 // 查询特定批次的可用商户集合 AvailableMerchantCollection merchantCollection = demo.listAvailableMerchants(creatorMchid, stockId); // 1.4 查询代金券批次可用单品 // 查询特定批次的可用单品集合 AvailableSingleitemCollection singleitemCollection = demo.listAvailableSingleItems(creatorMchid, stockId); // 2. 查询代金券的相关操作 // 2.1 根据商户号查用户的券 // 可以根据商户号、批次号、券状态等条件查询指定用户符合条件的代金券 ListCouponsByFilter.CouponCollection couponCollection = demo.listCouponByFilter(); // 2.2 查询代金券详情 // 查询指定用户指定券号的代金券详情 QueryCoupon.Coupon coupon = demo.queryCoupon(couponId, appid, openid); } // 查询满足条件的批次列表 // 返回所有满足条件的批次集合 public ListStocks.StockCollection listStocks() { ListStocks client = new ListStocks( mchid, certificateSerialNo, privateKeyFilePath, wechatPayPublicKeyId, wechatPayPublicKeyFilePath ); ListStocksRequest request = new ListStocksRequest(); // 请参阅实际文档进行传参 https://pay.weixin.qq.com/doc/v3/merchant/4012460489 // 分页信息 request.offset = 0L; // 分页页码,页码从0开始 request.limit = 8L; // 分页大小,目前最大为 10 // 批次信息 // 时间格式遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE request.stockCreatorMchid = "merchant_id"; // 批次创建商户号 request.createStartTime = "2025-05-20T13:29:35.120+08:00"; // 查询的起始创建时间 request.createEndTime = "2025-08-25T13:29:35.120+08:00"; // 查询的终止创建时间 // 批次状态,具体状态描述请参阅 https://pay.weixin.qq.com/doc/v3/merchant/4012460489 request.status = "running"; try { StockCollection response = client.run(request); // 请求成功,返回 StockCollection 类的实例 response 储存查到的所有优惠券的集合, // 这个类的定义详见 https://pay.weixin.qq.com/doc/v3/merchant/4012460489 的代码描述 return response; ``` -------------------------------- ### Get Invoice Application Details Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012531753 Example of how to retrieve details of an invoice application using the WeChat Pay API v3. ```APIDOC ## GET /v3/new-tax-control-fapiao/fapiao-applications/{application_id} ### Description Retrieves the details of a specific invoice application. ### Method GET ### Endpoint ``` https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/{application_id} ``` ### Query Parameters - **fapiao_id** (string) - Required - The ID of the invoice application. ### Request Example ```bash curl -X GET \ https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/4200000444201910177461284488?fapiao_id=20200701123456 \ -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ -H "Accept: application/json" ``` ### Response #### Success Response (200 OK) - **total_count** (integer) - The total number of invoice information entries. - **fapiao_information** (array) - An array of invoice information objects. - **fapiao_id** (string) - The ID of the invoice. - **status** (string) - The status of the invoice (e.g., ISSUE_ACCEPTED). - **blue_fapiao** (object) - Details of the blue invoice. - **fapiao_code** (string) - Invoice code. - **fapiao_number** (string) - Invoice number. - **check_code** (string) - Check code. - **password** (string) - Invoice password. - **fapiao_time** (string) - Time when the invoice was issued. - **red_fapiao** (object) - Details of the red invoice (if applicable). - (Same fields as blue_fapiao) - **card_information** (object) - Card information related to the invoice. - **card_appid** (string) - App ID of the card. - **card_openid** (string) - OpenID of the cardholder. - **card_id** (string) - ID of the card. - **card_code** (string) - Code of the card. - **card_status** (string) - Status of the card. - **total_amount** (integer) - Total amount of the invoice. - **tax_amount** (integer) - Tax amount. - **amount** (integer) - Amount before tax. - **seller_information** (object) - Information about the seller. - **name** (string) - Seller's name. - **taxpayer_id** (string) - Seller's taxpayer ID. - **address** (string) - Seller's address. - **telephone** (string) - Seller's telephone number. - **bank_name** (string) - Seller's bank name. - **bank_account** (string) - Seller's bank account number. - **buyer_information** (object) - Information about the buyer. - **type** (string) - Type of buyer (e.g., INDIVIDUAL, ENTERPRISE). - **name** (string) - Buyer's name. - **taxpayer_id** (string) - Buyer's taxpayer ID. - **address** (string) - Buyer's address. - **telephone** (string) - Buyer's telephone number. - **bank_name** (string) - Buyer's bank name. - **bank_account** (string) - Buyer's bank account number. - **phone** (string) - Buyer's phone number. - **email** (string) - Buyer's email address. - **extra_information** (object) - Additional information. - **payee** (string) - Payee name. - **reviewer** (string) - Reviewer name. - **drawer** (string) - Drawer name. - **items** (array) - An array of item details. - **tax_code** (string) - Tax code for the item. - **goods_name** (string) - Name of the goods or service. - **specification** (string) - Specification of the item. - **unit** (string) - Unit of measurement. - **quantity** (integer) - Quantity of the item. - **unit_price** (integer) - Unit price. - **amount** (integer) - Amount for the item. - **tax_amount** (integer) - Tax amount for the item. - **total_amount** (integer) - Total amount for the item. - **tax_rate** (integer) - Tax rate. - **tax_prefer_mark** (string) - Tax preference mark. - **discount** (boolean) - Indicates if discount applies. - **remark** (string) - Remark for the invoice. #### Response Example ```json { "total_count" : 5, "fapiao_information" : [ { "fapiao_id" : "20200701123456", "status" : "ISSUE_ACCEPTED", "blue_fapiao" : { "fapiao_code" : "044001911211", "fapiao_number" : "12897794", "check_code" : "69001808340631374774", "password" : "006>299-375/326>2+7/*0-+<351059<80<4*/5>+<11631+*3030/5*37+/-243159658+013>3409*044>4-/1+/9->*>69501*6++1997--21", "fapiao_time" : "2020-07-01T12:00:00+08:00" }, "red_fapiao" : { "fapiao_code" : "044001911211", "fapiao_number" : "12897794", "check_code" : "69001808340631374774", "password" : "006>299-375/326>2+7/*0-+<351059<80<4*/5>+<11631+*3030/5*37+/-243159658+013>3409*044>4-/1+/9->*>69501*6++1997--21", "fapiao_time" : "2020-07-01T12:00:00+08:00" }, "card_information" : { "card_appid" : "wxb1170446a4c0a5a2", "card_openid" : "plN5twRbHym_j-QcqCzstl0HmwEs", "card_id" : "p4gLgvlAYSEOpeXGFVJRFxgop6iY", "card_code" : "379550244162", "card_status" : "INSERT_ACCEPTED" }, "total_amount" : 382895, "tax_amount" : 44050, "amount" : 338845, "seller_information" : { "name" : "深圳市南山区测试公司", "taxpayer_id" : "202003261233701778", "address" : "深圳市南山区深南大道10000号", "telephone" : "075512345678", "bank_name" : "测试银行", "bank_account" : "62001234567890" }, "buyer_information" : { "type" : "INDIVIDUAL", "name" : "深圳市南山区测试企业", "taxpayer_id" : "202003261233701778", "address" : "深圳市南山区深南大道10000号", "telephone" : "075512345678", "bank_name" : "测试银行", "bank_account" : "62001234567890", "phone" : "18507550000", "email" : "123110@qq.com" }, "extra_information" : { "payee" : "张三", "reviewer" : "李四", "drawer" : "王五" }, "items" : [ { "tax_code" : "3010101020203000000", "goods_name" : "出租汽车客运服务", "specification" : "A4", "unit" : "次", "quantity" : 100000000, "unit_price" : 380442000000, "amount" : 380442, "tax_amount" : 49458, "total_amount" : 429900, "tax_rate" : 1300, "tax_prefer_mark" : "NO_FAVORABLE", "discount" : false } ], "remark" : "备注" } ] } ``` ``` -------------------------------- ### Upload Video - Java Example Source: https://pay.weixin.qq.com/doc/v3/partner/4012761084 Demonstrates how to upload a video file using Java. It calculates the SHA256 hash of the file and then sends a POST request with the file and its metadata. ```Java String filePath = "/your/home/hellokitty.avi"; URI uri = new URI("https://api.mch.weixin.qq.com/v3/merchant/media/video_upload"); File file = new File(filePath); try (FileInputStream ins1 = new FileInputStream(file)) { String sha256 = DigestUtils.sha256Hex(ins1); try (InputStream ins2 = new FileInputStream(file)) { HttpPost request = new WechatPayUploadHttpPost.Builder(uri) .withImage(file.getName(), sha256, ins2) .build(); CloseableHttpResponse response1 = httpClient.execute(request); } } ``` -------------------------------- ### Get Current Timestamp Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365340 An example of the current timestamp value obtained from the 'date +%s' command. ```plaintext 1554208460 ``` -------------------------------- ### Query Electronic Receipt Status (Finished Example) Source: https://pay.weixin.qq.com/doc/v3/merchant/4012716436 This example shows a successful response when an electronic receipt has been generated and is ready for download. It includes the state, creation and update times, hash type and value for verification, and a download URL. ```json { "state" : "FINISHED", "create_time" : "2015-05-20T13:29:35.120+08:00", "update_time" : "2015-05-20T13:29:35.120+08:00", "hash_type" : "SHA256", "hash_value" : "DE731F35146A0BEFADE5DB9D1E468D96C01CA8898119C674FEE9F11F4DBE5529", "download_url" : "https://api.mch.weixin.qq.com/v3/transferbilldownload/file?token=xxx" } ``` -------------------------------- ### Query Authorization Result (Go Example) Source: https://pay.weixin.qq.com/doc/v3/merchant/4014399423 This Go code provides an example of how to query the user no-confirmation collection authorization result. It shows the basic structure for making the GET request. ```go package main import ( "fmt" "io/ioutil" "net/http" "strings" ) func main() { outAuthorizationNo := "plfk2020042013" url := "https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/user-confirm-authorization/out-authorization-no/" + outAuthorizationNo client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } // Set headers, including Authorization req.Header.Set("Authorization", "WECHATPAY2-SHA256-RSA2048 mch_id=\"1900000109\",nonce_str=\"5K8264IL81234567\",timestamp=\"1614077730\",serial_no=\"374C83012D1B37472A3A3A4A3048374C\",signature=\"xxxx\"") req.Header.Set("Accept", "application/json") resp, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Printf("Response Status: %s\n", resp.Status) fmt.Printf("Response Body: %s\n", string(body)) } ``` -------------------------------- ### Example Query Parameters Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365337 These are the query parameters used in the example for constructing the signature. ```text limit=5 offset=10 authorized_data={"business_type":"FAVOR_STOCK","stock_id":"2433405"} partner={"type":"APPID","appid":"wx4e1916a585d1f4e9","merchant_id":"2480029552"} ``` -------------------------------- ### Close Transaction Request Example (Java) Source: https://pay.weixin.qq.com/doc/v3/partner/4012739019 Java code example for closing a transaction using the WeChat Pay Partner API. This snippet demonstrates the necessary HTTP request setup. ```java String url = "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/TRADE_NO_1234567890"; // TODO: Construct the request body and headers as per API documentation. // Example: // String requestBody = "{\"sp_mchid\": \"YOUR_SP_MCH_ID\", \"sub_mchid\": \"YOUR_SUB_MCH_ID\"}"; // Map headers = new HashMap<>(); // headers.put("Authorization", "WECHATPAY2-SHA256-RSA2048 mch_id=\"YOUR_MCH_ID\",nonce_str=\"\",timestamp=\"\",serial_no=\"\",signature=\"\"); // headers.put("Accept", "application/json"); // headers.put("Content-Type", "application/json"); // Execute the POST request using an HTTP client library (e.g., Apache HttpClient, OkHttp). // Handle the response, which is expected to be 204 No Content on success. ``` -------------------------------- ### Java Example: Responding to a Complaint with Images Source: https://pay.weixin.qq.com/doc/v3/partner/4015933338 This Java code demonstrates how to use the `ResponseComplaintV2` client to respond to a user complaint. It includes attaching up to four images using their media IDs. Ensure images are uploaded first and their media IDs are obtained. ```java package com.java.complaint; import java.util.ArrayList; // 使用合作伙伴平台通用投诉接口:https://pay.weixin.qq.com/doc/v3/partner/4012467213 import com.java.demo.ResponseComplaintV2; import com.java.demo.ResponseComplaintV2.MiniProgramJumpInfo; import com.java.demo.ResponseComplaintV2.ResponseComplaintV2Request; import com.java.utils.WXPayUtility; public class ResponseComplaintExample { public static void main(String[] args) { // 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 ResponseComplaintV2 client = new ResponseComplaintV2( "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 ); ResponseComplaintV2Request request = new ResponseComplaintV2Request(); // 投诉单号,商户号,回复内容,回复图片(已上传好的media_id,最多四张) request.complaintId = "200201xxxxxxxxxxxxxxxxxxxx"; request.complaintedMchid = "1900xxxxx1"; request.responseContent = "已与用户沟通解决"; request.responseImages = new ArrayList<>(); { request.responseImages.add("aabbccdd"); // 在传入图片前应当先上传图片,请参考:https://pay.weixin.qq.com/doc/v3/partner/4012467222 } // 注意,这里仅对部分商户开放,如有需要请联系对接的行业运营进行咨询 // 商户可以在下述内容中二选一填入请求: // 1. 跳转链接 + 文案(缺一不可) request.jumpUrl = "https://www.xxx.com/notify"; request.jumpUrlText = "查看订单详情"; // 2. 小程序信息 request.miniProgramJumpInfo = new MiniProgramJumpInfo(); request.miniProgramJumpInfo.appid = "example_appid"; request.miniProgramJumpInfo.path = "example_path"; request.miniProgramJumpInfo.text = "example_text"; try { client.run(request); // 请求成功,继续业务逻辑 } catch (WXPayUtility.ApiException e) { // 请求失败,根据状态码执行不同的逻辑 if (e.getErrorCode().equals("PARAM_ERROR")) { // 错误:参数错误 // 解决方式:按照报错返回的message,需要根据接口文档对参数进行校对和修正,然后重新发起请求 } else if (e.getErrorCode().equals("INVALID_REQUEST")) { // 错误:请求非法,请求参数正确,但是不符合业务规则 // 解决方式:请参阅 https://pay.weixin.qq.com/doc/v3/partner/4012081726,如果可以修改参数达到符合业务规则的修改请求符合业务规则之后再原单重试 } else if (e.getErrorCode().equals("SIGN_ERROR")) { // 错误:签名错误 // 解决方式:检查平台商户公钥ID,公钥文件,同时确认下签名过程是不是按照微信支付的签名方式 } else if (e.getErrorCode().equals("SYSTEM_ERROR")) { // 错误:系统错误 // 解决方式:稍后原单重试 } else if (e.getErrorCode().equals("NO_AUTH")) { // 错误:商户信息不合法,或无权访问投诉单 // 解决方式:登录合作伙伴平台核对,传入正确信息 } else if (e.getErrorCode().equals("FREQUENCY_LIMITED")) { // 错误:频率超限 //解决方式:请求量不要超过接口调用频率限制 }else { //其他错误,稍等一会重试 } } } } ``` -------------------------------- ### Get Invoice Title URL - Go Example Source: https://pay.weixin.qq.com/doc/v3/partner/4015770776 This Go code snippet illustrates how to make the API call to get the invoice title URL, including setting up the request body and headers. ```go package main import ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" "time" ) func main() { url := "https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/user-title/title-url" // 1. Construct request body requestBody := map[string]interface{}{ "sub_mchid": "7777777777777777", "fapiao_apply_id": "20230101000000000000000000000000", "source": "WEB", "appid": "wxd678efh567890ab", "openid": "oUpF8uMuAJO7KKld8l_...", "total_amount": 10000, "seller_name": "腾讯科技(深圳)有限公司", "show_phone_cell": true, "must_input_phone": true, "show_email_cell": true, "must_input_email": true, } jsonBody, err := json.Marshal(requestBody) if err != nil { fmt.Println("Error marshaling JSON:", err) return } // 2. Construct the signature and Authorization header // Please refer to the signature generation method in the official documentation authorization := "WECHATPAY2-SHA256-RSA2048 mchid=\"7777777777777777\",nonce=\"...\",timestamp=\"1678886400\",serial_no=\"...\",signature=\"...\"" // 3. Send the request req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Authorization", authorization) req.Header.Set("Accept", "application/json") rereq.Header.Set("Content-Type", "application/json") client := &http.Client{ Timeout: time.Second * 10, } res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() bodyBytes, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } // 4. Process the response if res.StatusCode == http.StatusOK { var responseBody map[string]interface{} err := json.Unmarshal(bodyBytes, &responseBody) if err != nil { fmt.Println("Error unmarshaling response JSON:", err) return } fmt.Println("Response:", responseBody) // Access fields like: responseBody["miniprogram_appid"] } else { fmt.Printf("Error response: Status Code %d, Body: %s\n", res.StatusCode, string(bodyBytes)) // Handle error response } } ``` -------------------------------- ### Upload Media Image - PHP Example Source: https://pay.weixin.qq.com/doc/v3/partner/4012759802 Provides a PHP example for uploading media files using the `MediaUtil` class with Guzzle. Ensure the file extension is supported and the `MediaUtil` is correctly initialized. The `content-type` header is automatically set by `MediaUtil`. ```php // 参考上述指引说明,并引入 `MediaUtil` 正常初始化,无额外条件 use WechatPay\GuzzleMiddleware\Util\MediaUtil; // 实例化一个媒体文件流,注意文件后缀名需符合接口要求 $media = new MediaUtil('/your/file/path/with.extension'); // 正常使用Guzzle发起API请求 try { $resp = $client->request('POST', 'https://api.mch.weixin.qq.com/v3/marketing/favor/media/image-upload', [ 'body' => $media->getStream(), 'headers' => [ 'Accept' => 'application/json', 'content-type' => $media->getContentType(), ] ]); // POST 语法糖 $resp = $client->post('merchant/media/upload', [ 'body' => $media->getStream(), 'headers' => [ 'Accept' => 'application/json', 'content-type' => $media->getContentType(), ] ]); echo $resp->getStatusCode().' '.$resp->getReasonPhrase()."\n"; echo $resp->getBody()."\n"; } catch (Exception $e) { echo $e->getMessage()."\n"; if ($e->hasResponse()) { echo $e->getResponse()->getStatusCode().' '.$e->getResponse()->getReasonPhrase()."\n"; echo $e->getResponse()->getBody(); } return; } ``` -------------------------------- ### Example GET Request for Transfer Batch Details Source: https://pay.weixin.qq.com/doc/v3/merchant/4012458877 This snippet shows how to make a GET request to retrieve details of a transfer batch. It includes parameters for querying details, offset, limit, and detail status. ```curl curl -X GET \ https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/plfk2020042013?need_query_detail=true&offset=0&limit=20&detail_status=FAIL \ -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ -H "Accept: application/json" ```