### Activate Coupon Stock Response Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012460137 This is an example of a successful response when activating a coupon stock. It includes the activation start time and the stock ID. ```json { "start_time" : "2015-05-20T13:29:35.120+08:00", "stock_id" : "9865000" } ``` -------------------------------- ### Authorization Header Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365334 This is an example of a complete Authorization header. Note that actual data should be on a single line, even if formatting in the example causes line breaks. ```text Authorization: WECHATPAY2-SHA256-RSA2048 mchid="1900007291",nonce_str="593BEC0C930BF1AFEB40B4A08C8FB242",signature="Lc9VXxmeonkdV8Xk9tmigQFLhl0vRWTerdmoRu01aAnYwIrD/5nsSwE1WlmZGLRlAFTNQ3QsMa0+VRDlJp1Wp5p0nO8EK68b5sJBbjouxaFciIfq1zfDWWz+jqhcMoKXI1A6dPm1AW7D4d30WsMTNzp6g23OXakIsh9LO3lUmwvTuE0BY8ncf6tNGk4wKmvXwERd/ZpoQY3MAVKz+Nakwc+2XBmzT66KcUehU5kr4IvGa/lEU5RZb/q00zP9VLdBhC/jQSX3X1UcJLCtEc4gTmib4tnmAT+bHF/e17ZAuxDNcx6rqT8gNEXqaJGG+1OflMSTU2tpyG65G4dMKdFcoA==",timestamp="1554208460",serial_no="408B07E79B8269FEC3D5D3E6AB8ED163A6A380DB" ``` -------------------------------- ### Example Mini Program AppID Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365341 This is an example of a Mini Program AppID. Replace this with your actual AppID. ```text wx2421b1c4370ec43b ``` -------------------------------- ### Start Coupon Batch in Java Source: https://pay.weixin.qq.com/doc/v3/merchant/4015894256 Demonstrates how to activate a coupon batch using the `StartStock` client. Includes initialization with necessary credentials and handling of potential API exceptions. ```java public void startStock(String stockId, String stockCreatorMchid) { StartStock client = new StartStock( mchid, certificateSerialNo, privateKeyFilePath, wechatPayPublicKeyId, wechatPayPublicKeyFilePath ); StartStockRequest request = new StartStockRequest(); request.stockId = stockId; // 需要激活的优惠券批次号 request.stockCreatorMchid = stockCreatorMchid; // 优惠券制券商户号 try { StartStockResponse response = client.run(request); // 请求成功,系统会返回该批次的激活时间和批次 ID String startTimeResp = response.startTime; String stockIdResp = request.stockId; } catch (WXPayUtility.ApiException e) { // 请求失败,根据状态码执行不同的逻辑 if (e.getErrorCode().equals("PARAM_ERROR")) { // 错误:参数错误 // 解决方式:请根据错误提示正确传入参数 } else if (e.getErrorCode().equals("INVALID_REQUEST")) { // 错误:HTTP 请求不符合微信支付 APIv3 接口规则 // 解决方式:结合给定的提示信息,并参阅 https://pay.weixin.qq.com/doc/v3/merchant/4012081709 解决 } else if (e.getErrorCode().equals("SIGN_ERROR")) { // 错误:验证不通过 // 解决方式:检查平台商户证书序列号,证书私钥文件,公钥ID,公钥文件,同时确认下签名过程是不是按照微信支付的签名方式 // 可以参阅 https://pay.weixin.qq.com/doc/v3/merchant/4012081606 下的 “如何签名” 和 “如何验签” 部分 } else if (e.getErrorCode().equals("SYSTEM_ERROR")) { // 错误:系统异常,请稍后重试 // 解决方式:请稍后原单重试 } else if (e.getErrorCode().equals("APPID_MCHID_NOT_MATCH")) { // 错误:商户号与AppID不匹配 // 解决方式:请绑定调用接口的商户号和AppID后重试 } else if (e.getErrorCode().equals("MCH_NOT_EXISTS")) { // 错误:商户号不合法 // 解决方式:请输入正确的商户号 } else if (e.getErrorCode().equals("NOT_ENOUGH")) { // 错误:批次预算不足 // 解决方式:请补充预算 } else if (e.getErrorCode().equals("REQUEST_BLOCKED")) { // 错误:请求失败 // 解决方式:请根据具体的报错信息修改请求后重试 } else if (e.getErrorCode().equals("RESOURCE_NOT_EXISTS")) { // 错误:批次不存在 // 解决方式:请检查批次ID是否正确 } else if (e.getErrorCode().equals("FREQUENCY_LIMITED")) { // 错误:请求过于频繁 // 解决方式:稍后重试 } else { // 未知错误码 // 解决方式:请查看返回的错误信息 } e.printStackTrace(); } } ``` -------------------------------- ### Get Request URL Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365335 Example of obtaining the request URL, excluding the domain. ```text /v3/marketing/favor/media/image-upload ``` -------------------------------- ### Signature Calculation for Coupon Distribution (Example) Source: https://pay.weixin.qq.com/doc/v3/merchant/4012285674 This example demonstrates how to construct the query string for signature calculation when distributing multiple coupons. It shows the parameter format with indices for multiple items. ```plaintext out_request_no0=abc123&out_request_no1=123abc&send_coupon_merchant=10016226&stock_id0=1234567&stock_id1=2345678&key=xxxxx ``` -------------------------------- ### Close Order Request (Java) Source: https://pay.weixin.qq.com/doc/v3/merchant/4012791860 Java code example for closing a WeChat Pay order. This snippet demonstrates the necessary HTTP request setup and parameters. ```java CloseOrderRequest closeOrderRequest = new CloseOrderRequest(); closeOrderRequest.setMchid("1900000109"); // Construct the request URL with the out_trade_no String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s/close", "1234567890"); // Execute the request using the WeChat Pay SDK or a custom HTTP client // Example using a hypothetical SDK method: // WeChatPayClient client = new WeChatPayClient(merchantId, privateKeyPath, apiV3Key); // CloseOrderResponse response = client.closeOrder(url, closeOrderRequest); // Handle the response (typically a 204 No Content on success) ``` -------------------------------- ### Builder Initialization Compatibility (PHP) Source: https://pay.weixin.qq.com/doc/v3/merchant/4012154180 Configure the `certs` parameter with the file path to your platform certificate or public key. The SDK automatically handles verification. ```php // 从本地文件中加载「微信支付平台证书」或者「微信支付平台公钥」,用来验证微信支付应答的签名 $platformCertificateOrPublicKeyFilePath = 'file:///path/to/wechatpay/certificate_or_publickey.pem'; $platformPublicKeyInstance = Rsa::from($platformCertificateOrPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC); // 「微信支付平台证书」的「证书序列号」或者是「微信支付平台公钥ID」 // 「平台证书序列号」及/或「平台公钥ID」可以从 商户平台 -> 账户中心 -> API安全 直接查询到 $platformCertificateSerialOrPublicKeyId = 'PUB_KEY_ID_00000000000000000000000000000000'; // 构造一个 APIv3 客户端实例 $instance = Builder::factory([ 'mchid' => $merchantId, 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, 'certs' => [ $platformCertificateSerialOrPublicKeyId => $platformPublicKeyInstance, ], ]); ``` -------------------------------- ### Example Query Parameters Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365337 These are example query parameters for constructing a request signature. Ensure that complex parameters like 'authorized_data' and 'partner' are URL-encoded. ```text limit=5 offset=10 authorized_data={"business_type":"FAVOR_STOCK","stock_id":"2433405"} partner={"type":"APPID","appid":"wx4e1916a585d1f4e9","merchant_id":"2480029552"} ``` -------------------------------- ### Java Example: Delete Complaint Notification Callback URL Source: https://pay.weixin.qq.com/doc/v3/merchant/4015821404 This Java code snippet demonstrates how to delete a complaint notification callback URL. It includes setup for the client with necessary merchant and API credentials and handles various API exceptions. ```java package com.java.complaint; // 使用商户平台通用投诉接口:https://pay.weixin.qq.com/doc/v3/merchant/4012460452 import com.java.demo.DeleteComplaintNotifications; import com.java.utils.WXPayUtility; public class DeleteComplaintNotificationsExample { public static void main(String[] args) { // 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 DeleteComplaintNotifications client = new DeleteComplaintNotifications( "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 // https://pay.weixin.qq.com/doc/v3/merchant/4013070756 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 ); try { client.run(); // 请求成功,继续业务逻辑 } 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/merchant/4012081709,如果可以修改参数达到符合业务规则的修改请求符合业务规则之后再原单重试 } 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 if (e.getErrorCode().equals("RESOURCE_NOT_EXISTS")) { // 错误:查询的通知回调不存在 // 解决方式:请检查是否已创建通知回调 } else { // 其他错误,稍等一会重试 } } } } ``` -------------------------------- ### Java Example for Completing Complaint Source: https://pay.weixin.qq.com/doc/v3/merchant/4015821404 This Java code demonstrates how to use the merchant platform's common complaint API to mark a complaint as completed. It includes setup for necessary parameters and error handling for various API response codes. Ensure to replace placeholder values with your actual merchant information and file paths. ```java package com.java.complaint; // 使用商户平台通用投诉接口:https://pay.weixin.qq.com/doc/v3/merchant/4012467255 import com.java.demo.CompleteComplaintV2; import com.java.demo.CompleteComplaintV2.CompleteComplaintV2Request; import com.java.utils.WXPayUtility; public class CompleteComplaintExample { public static void main(String[] args) { // 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 CompleteComplaintV2 client = new CompleteComplaintV2( "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 // https://pay.weixin.qq.com/doc/v3/merchant/4013070756 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 ); CompleteComplaintV2Request request = new CompleteComplaintV2Request(); request.complaintId = "2002018xxxxxxxxxxxxxxxxxxxx"; request.complaintedMchid = "190xxxxxxx"; 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/merchant/4012081709,如果可以修改参数达到符合业务规则的修改请求符合业务规则之后再原单重试 } 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 { // 其他错误,稍等一会重试 } } } } ``` -------------------------------- ### Manual Skill Directory Placement Example (Cursor IDE) Source: https://pay.weixin.qq.com/doc/v3/merchant/4019638116 Illustrates how to manually place the WeChat Pay Skills directory within an AI IDE's configuration. The exact path may vary depending on your IDE. ```bash your-project/ └── .cursor/ └── skills/ └── wechatpay-payment-integration/ ├── SKILL.md ├── references/ └── scripts/ ``` -------------------------------- ### Restart Coupon Batch Example (Java) Source: https://pay.weixin.qq.com/doc/v3/merchant/4015894256 This Java snippet demonstrates how to restart a coupon batch using the WeChat Pay V3 API. It includes detailed error handling for common API exceptions, guiding developers on how to address issues like invalid parameters or signature errors. Ensure the client is properly configured with merchant details. ```java RestartStock client = new RestartStock( mchid, certificateSerialNo, privateKeyFilePath, wechatPayPublicKeyId, wechatPayPublicKeyFilePath ); RestartStockRequest request = new RestartStockRequest(); request.stockId = stockId; // 需要重启的代金券批次ID request.stockCreatorMchid = stockCreatorMchid; // 该代金券的制券商户号 try { RestartStockResponse response = client.run(request); // 请求成功,系统返回重启时间和代金券批次ID String stockIdResp = request.stockId; String restartTimeResp = response.restartTime; } catch (WXPayUtility.ApiException e) { // 请求失败,根据状态码执行不同的逻辑 if (e.getErrorCode().equals("SYSTEM_ERROR")) { // 错误:系统错误 // 解决方式:稍后(建议等 1 分钟后)原单重试 } else if (e.getErrorCode().equals("PARAM_ERROR")) { // 错误:参数错误 // 解决方式:请根据错误提示正确传入参数 } else if (e.getErrorCode().equals("INVALID_REQUEST")) { // 错误:HTTP 请求不符合微信支付 APIv3 接口规则 // 解决方式:结合错误信息并参阅 https://pay.weixin.qq.com/doc/v3/merchant/4012081709,修改参数达到符合业务规则之后再重试 } else if (e.getErrorCode().equals("SIGN_ERROR")) { // 错误:验证不通过 // 解决方式:检查平台商户证书序列号,证书私钥文件,公钥ID,公钥文件,同时确认下签名过程是不是按照微信支付的签名方式 // 可以参阅 https://pay.weixin.qq.com/doc/v3/merchant/4012081606 下的 “如何签名” 和 “如何验签” 部分 } else if (e.getErrorCode().equals("APPID_MCHID_NOT_MATCH")) { // 错误:商户号与AppID不匹配 // 解决方式:请绑定调用接口的商户号和AppID后重试 } else if (e.getErrorCode().equals("MCH_NOT_EXISTS")) { // 错误:商户号不合法 // 解决方式:请输入正确的商户号 } else if (e.getErrorCode().equals("NOT_ENOUGH")) { // 错误:批次预算不足 // 解决方式:请补充预算 } else if (e.getErrorCode().equals("REQUEST_BLOCKED")) { // 错误:请求失败 // 解决方式:请根据具体的错误信息修改请求 } else if (e.getErrorCode().equals("RESOURCE_NOT_EXISTS")) { // 错误:批次不存在 // 解决方式:请检查批次 ID 是否正确 } else if (e.getErrorCode().equals("FREQUENCY_LIMITED")) { // 错误:请求过于频繁 // 解决方式:稍后重试 } else { // 其他错误码 // 解决方式:请查看返回的错误信息 } e.printStackTrace(); } ``` -------------------------------- ### Construct Signature String Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365341 This example shows the correctly formatted signature string, including the Mini Program AppID, timestamp, random string, and prepay_id, each followed by a newline character. ```text wx2421b1c4370ec43b 1554208460 593BEC0C930BF1AFEB40B4A08C8FB242 prepay_id=wx201410272009395522657a690389285100 ``` -------------------------------- ### Signature Calculation with Coupon Codes (Example) Source: https://pay.weixin.qq.com/doc/v3/merchant/4012285674 This example illustrates the query string format for signature calculation when distributing multiple coupons with specific coupon codes. Note the inclusion of 'coupon_code' with indices. ```plaintext coupon_code0=asdsada&coupon_code1=asdsada&out_request_no0=abc123&out_request_no1=123abc&send_coupon_merchant=10016226&stock_id0=1234567&stock_id1=2345678&key=xxxxx ``` -------------------------------- ### Install WeChat Pay PHP SDK with Composer Source: https://pay.weixin.qq.com/doc/v3/merchant/4012076511 Use Composer to install the latest version of the WeChat Pay PHP SDK. Ensure you have Composer installed and configured. ```bash composer require wechatpay/wechatpay ``` -------------------------------- ### Payment Success Notification Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012791836 An example of the JSON payload for a successful payment notification. ```APIDOC ## Payment Success Notification Example ```json { "id": "EV-2018022511223320873", "create_time": "2015-05-20T13:29:35+08:00", "resource_type": "encrypt-resource", "event_type": "TRANSACTION.SUCCESS", "summary": "支付成功", "resource": { "original_type": "transaction", "algorithm": "AEAD_AES_256_GCM", "ciphertext": "", "associated_data": "", "nonce": "" } } ``` ``` -------------------------------- ### Example Signature Value Source: https://pay.weixin.qq.com/doc/v3/merchant/4012365335 An example of a calculated signature value for the marketing image upload API. ```text GKKF+5+eeGuZOZ6MWLn7t7sMRTNbdnCTVqwP+dRx+p+Th+FueUXUVIsY7SOGj3oHWspCrBcZPl+eB/YelgTgImbZV8LvsiJhKt5+wm4P/qssX0ziNJfqLMfp+tgaa75VY89ctNqonRKOGbzvg/TaL3PaG2IlLUHsNtkXTe1GYdeOwsXV25DeI4nU2TsV0Z+ZbryNPtofCNWK35+WG8Cb95ffDAK+4HhJ9A+GCW4FpOLiqFo1DfIV24cINcBhbI7BTD3tThb7PMagFEpFGT8Gd+kLLFNAZYyObcQ1/rmvCFffyv8Ut+Vw+wkiv6mQ0gTorINrgGbf8v1/wU/22em0lg== ``` -------------------------------- ### Java Request Example for Merchant Transfer Source: https://pay.weixin.qq.com/doc/v3/merchant/4012716434 Demonstrates how to initiate a merchant transfer using Java. This example requires the WeChat Pay SDK and proper configuration of API credentials. ```java String url = "https://api.mch.weixin.qq.com/v3/transfer/batches/batch-transfer"; // 1. Construct the request body JSONObject body = new JSONObject(); body.put("appid", "wxd678efh56702d4ce"); body.put("mchid", "1900000109"); body.put("out_batch_no", "plfk2020042013"); body.put("batch_name", "测试"); body.put("batch_description", "来自商户"); body.put("transfer_amount", 10000); body.put("transfer_scene", "PERSONAL_WBAPP"); body.put("notify_url", "https://merchant.com/notify/batch-transfer"); JSONArray transfers = new JSONArray(); JSONObject transfer = new JSONObject(); transfer.put("out_trade_no", "1234567890"); JSONObject recipient = new JSONObject(); recipient.put("account_type", "openid"); recipient.put("account_id", "o6_bIZ2_xxxxxxxxxxxxxxx"); transfer.put("recipient", recipient); transfer.put("amount", 10000); transfer.put("real_name", "张三"); transfer.put("transfer_remark", "转账备注"); transfers.add(transfer); body.put("transfers", transfers); // 2. Send the request using the WeChat Pay SDK // Example using a hypothetical SDK method: // String response = WeChatPayClient.post(url, body.toString()); // System.out.println(response); // Note: Actual implementation requires initializing the WeChatPayClient with your API keys and certificates. ``` -------------------------------- ### Original Notify URL Example Source: https://pay.weixin.qq.com/doc/v3/merchant/4012075393 This is an example of a traditional notify_url using a fixed IP address. ```plaintext http://131.XX.XXX.44:8080/payscope/callback ``` -------------------------------- ### Example Response for Creating Parking Entry Source: https://pay.weixin.qq.com/doc/v3/merchant/4012533937 This is an example of a successful response when creating parking entry information. It includes the assigned parking entry ID, merchant's entry ID, vehicle details, entry time, parking name, free duration, and the current state of the entry. ```json { "id" : "5K8264ILTKCH16CQ250", "out_parking_no" : "212434321", "plate_number" : "粤B888888", "plate_color" : "BLUE", "start_time" : "2017-08-26T10:43:39+08:00", "parking_name" : "欢乐海岸停车场", "free_duration" : 3600, "state" : "NORMAL", "block_reason" : "PAUSE" } ```