查询出境退回结果(通过商户出境退回单号)
更新时间:2025.02.24通过商户出境退回单号查询出境退回处理结果。默认接口限频300/s
接口说明
支持商户:【平台商户】
请求方式:【GET】/v3/funds-to-oversea/return/return-orders/out-return-no/{out_return_no}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
out_return_no 必填 string(64)
【商户出境退回单号】 商户在发起资金出境退回请求时生成,要求在同一个商户号下唯一。只能由数字,大小写字母_-组成
query 查询参数
sub_mchid 必填 string(64)
【二级商户号】 申请资金出境退回的二级商户号
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/funds-to-oversea/return/return-orders/out-return-no/R20250220103930?sub_mchid=1900000109 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 查询出境退回结果(通过商户出境退回单号) 24 */ 25public class QueryReturnOrderByOutReturnNo { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/funds-to-oversea/return/return-orders/out-return-no/{out_return_no}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 QueryReturnOrderByOutReturnNo client = new QueryReturnOrderByOutReturnNo( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 QueryReturnOrderByOutReturnNoRequest request = new QueryReturnOrderByOutReturnNoRequest(); 41 request.outReturnNo = "R20250220103930"; 42 request.subMchid = "1900000109"; 43 try { 44 FundsOsReturnOrder response = client.run(request); 45 // TODO: 请求成功,继续业务逻辑 46 System.out.println(response); 47 } catch (WXPayUtility.ApiException e) { 48 // TODO: 请求失败,根据状态码执行不同的逻辑 49 e.printStackTrace(); 50 } 51 } 52 53 public FundsOsReturnOrder run(QueryReturnOrderByOutReturnNoRequest request) { 54 String uri = PATH; 55 uri = uri.replace("{out_return_no}", WXPayUtility.urlEncode(request.outReturnNo)); 56 Map<String, Object> args = new HashMap<>(); 57 args.put("sub_mchid", request.subMchid); 58 String queryString = WXPayUtility.urlEncode(args); 59 if (!queryString.isEmpty()) { 60 uri = uri + "?" + queryString; 61 } 62 63 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 64 reqBuilder.addHeader("Accept", "application/json"); 65 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 66 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 67 reqBuilder.method(METHOD, null); 68 Request httpRequest = reqBuilder.build(); 69 70 // 发送HTTP请求 71 OkHttpClient client = new OkHttpClient.Builder().build(); 72 try (Response httpResponse = client.newCall(httpRequest).execute()) { 73 String respBody = WXPayUtility.extractBody(httpResponse); 74 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 75 // 2XX 成功,验证应答签名 76 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 77 httpResponse.headers(), respBody); 78 79 // 从HTTP应答报文构建返回数据 80 return WXPayUtility.fromJson(respBody, FundsOsReturnOrder.class); 81 } else { 82 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 83 } 84 } catch (IOException e) { 85 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 86 } 87 } 88 89 private final String mchid; 90 private final String certificateSerialNo; 91 private final PrivateKey privateKey; 92 private final String wechatPayPublicKeyId; 93 private final PublicKey wechatPayPublicKey; 94 95 public QueryReturnOrderByOutReturnNo(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 96 this.mchid = mchid; 97 this.certificateSerialNo = certificateSerialNo; 98 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 99 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 100 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 101 } 102 103 public static class QueryReturnOrderByOutReturnNoRequest { 104 @SerializedName("sub_mchid") 105 @Expose(serialize = false) 106 public String subMchid; 107 108 @SerializedName("out_return_no") 109 @Expose(serialize = false) 110 public String outReturnNo; 111 } 112 113 public static class FundsOsReturnOrder { 114 @SerializedName("out_return_no") 115 public String outReturnNo; 116 117 @SerializedName("sub_mchid") 118 public String subMchid; 119 120 @SerializedName("return_id") 121 public String returnId; 122 123 @SerializedName("out_order_id") 124 public String outOrderId; 125 126 @SerializedName("transaction_id") 127 public String transactionId; 128 129 @SerializedName("refund_id") 130 public String refundId; 131 132 @SerializedName("supplement_info") 133 public String supplementInfo; 134 135 @SerializedName("amount") 136 public Long amount; 137 138 @SerializedName("state") 139 public ReturnState state; 140 141 @SerializedName("create_time") 142 public String createTime; 143 144 @SerializedName("success_time") 145 public String successTime; 146 147 @SerializedName("fail_reason") 148 public FailReason failReason; 149 } 150 151 public enum ReturnState { 152 @SerializedName("PROCESSING") 153 PROCESSING, 154 @SerializedName("SUCCESS") 155 SUCCESS, 156 @SerializedName("FAILED") 157 FAILED 158 } 159 160 public enum FailReason { 161 @SerializedName("RETURN_AMOUNT_NOT_ENOUGH") 162 RETURN_AMOUNT_NOT_ENOUGH 163 } 164 165} 166
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &QueryReturnOrderByOutReturnNoRequest{ 27 SubMchid: wxpay_utility.String("1900000109"), 28 OutReturnNo: wxpay_utility.String("R20250220103930"), 29 } 30 31 response, err := QueryReturnOrderByOutReturnNo(config, request) 32 if err != nil { 33 fmt.Printf("请求失败: %+v\n", err) 34 // TODO: 请求失败,根据状态码执行不同的处理 35 return 36 } 37 38 // TODO: 请求成功,继续业务逻辑 39 fmt.Printf("请求成功: %+v\n", response) 40} 41 42func QueryReturnOrderByOutReturnNo(config *wxpay_utility.MchConfig, request *QueryReturnOrderByOutReturnNoRequest) (response *FundsOsReturnOrder, err error) { 43 const ( 44 host = "https://api.mch.weixin.qq.com" 45 method = "GET" 46 path = "/v3/funds-to-oversea/return/return-orders/out-return-no/{out_return_no}" 47 ) 48 49 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 50 if err != nil { 51 return nil, err 52 } 53 reqUrl.Path = strings.Replace(reqUrl.Path, "{out_return_no}", url.PathEscape(*request.OutReturnNo), -1) 54 query := reqUrl.Query() 55 if request.SubMchid != nil { 56 query.Add("sub_mchid", *request.SubMchid) 57 } 58 reqUrl.RawQuery = query.Encode() 59 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest.Header.Set("Accept", "application/json") 64 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 65 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 66 if err != nil { 67 return nil, err 68 } 69 httpRequest.Header.Set("Authorization", authorization) 70 71 client := &http.Client{} 72 httpResponse, err := client.Do(httpRequest) 73 if err != nil { 74 return nil, err 75 } 76 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 77 if err != nil { 78 return nil, err 79 } 80 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 81 // 2XX 成功,验证应答签名 82 err = wxpay_utility.ValidateResponse( 83 config.WechatPayPublicKeyId(), 84 config.WechatPayPublicKey(), 85 &httpResponse.Header, 86 respBody, 87 ) 88 if err != nil { 89 return nil, err 90 } 91 response := &FundsOsReturnOrder{} 92 if err := json.Unmarshal(respBody, response); err != nil { 93 return nil, err 94 } 95 96 return response, nil 97 } else { 98 return nil, wxpay_utility.NewApiException( 99 httpResponse.StatusCode, 100 httpResponse.Header, 101 respBody, 102 ) 103 } 104} 105 106type QueryReturnOrderByOutReturnNoRequest struct { 107 SubMchid *string `json:"sub_mchid,omitempty"` 108 OutReturnNo *string `json:"out_return_no,omitempty"` 109} 110 111func (o *QueryReturnOrderByOutReturnNoRequest) MarshalJSON() ([]byte, error) { 112 type Alias QueryReturnOrderByOutReturnNoRequest 113 a := &struct { 114 SubMchid *string `json:"sub_mchid,omitempty"` 115 OutReturnNo *string `json:"out_return_no,omitempty"` 116 *Alias 117 }{ 118 // 序列化时移除非 Body 字段 119 SubMchid: nil, 120 OutReturnNo: nil, 121 Alias: (*Alias)(o), 122 } 123 return json.Marshal(a) 124} 125 126type FundsOsReturnOrder struct { 127 OutReturnNo *string `json:"out_return_no,omitempty"` 128 SubMchid *string `json:"sub_mchid,omitempty"` 129 ReturnId *string `json:"return_id,omitempty"` 130 OutOrderId *string `json:"out_order_id,omitempty"` 131 TransactionId *string `json:"transaction_id,omitempty"` 132 RefundId *string `json:"refund_id,omitempty"` 133 SupplementInfo *string `json:"supplement_info,omitempty"` 134 Amount *int64 `json:"amount,omitempty"` 135 State *ReturnState `json:"state,omitempty"` 136 CreateTime *string `json:"create_time,omitempty"` 137 SuccessTime *string `json:"success_time,omitempty"` 138 FailReason *FailReason `json:"fail_reason,omitempty"` 139} 140 141type ReturnState string 142 143func (e ReturnState) Ptr() *ReturnState { 144 return &e 145} 146 147const ( 148 RETURNSTATE_PROCESSING ReturnState = "PROCESSING" 149 RETURNSTATE_SUCCESS ReturnState = "SUCCESS" 150 RETURNSTATE_FAILED ReturnState = "FAILED" 151) 152 153type FailReason string 154 155func (e FailReason) Ptr() *FailReason { 156 return &e 157} 158 159const ( 160 FAILREASON_RETURN_AMOUNT_NOT_ENOUGH FailReason = "RETURN_AMOUNT_NOT_ENOUGH" 161) 162
应答参数
200 OK
out_return_no 必填 string(64)
【商户出境退回单号】 只能由数字,大小写字母_-组成。 由商户在发起资金出境退回请求时生成,要求在同一个商户号下唯一
sub_mchid 必填 string(64)
【二级商户号】 申请资金出境退回的二级商户号
return_id 必填 string(64)
【微信出境退回单号】 微信出境退回单号
out_order_id 必填 string(64)
【商户出境单号】 商户出境单号,仅支持已跨境成功的支付单据申报退回
transaction_id 必填 string(64)
【微信订单号】 微信支付订单号
refund_id 选填 string(64)
【微信退款单号】 微信退款单号
supplement_info 选填 string(64)
【退回凭证补充信息】 退回凭证补充信息
amount 必填 integer
【退回金额】 申请资金出境退回的金额,单位:分
state 必填 string
【状态】 出境退回状态
可选取值
PROCESSING: 出境退回处理中SUCCESS: 资金已退回FAILED: 可退回金额不足时,超过一定时间,业务可能自动关闭申请
create_time 必填 string(64)
【创建时间】 遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2025-02-20T10:29:35+08:00表示,北京时间2025年2月20日 10点29分35秒。
success_time 选填 string(64)
【成功时间】 当result为SUCCESS时有这个字段。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2025-02-20T10:29:35+08:00表示,北京时间2025年2月20日 10点29分35秒。
fail_reason 选填 string
【失败原因】 当state为FAILED时,会出现此字段,标明出境退回失败的原因
可选取值
RETURN_AMOUNT_NOT_ENOUGH: 可退回金额不足
应答示例
200 OK
1{ 2 "out_return_no" : "R20250220103930", 3 "sub_mchid" : "1900000109", 4 "return_id" : "2375897293812", 5 "out_order_id" : "merchant_1123123", 6 "transaction_id" : "420000000000000010", 7 "refund_id" : "5017752501201407033233368018", 8 "supplement_info" : "5017752501201407033233368018", 9 "amount" : 100, 10 "state" : "PROCESSING", 11 "create_time" : "2025-02-20T10:29:35+08:00", 12 "success_time" : "2025-02-22T10:29:35+08:00", 13 "fail_reason" : "RETURN_AMOUNT_NOT_ENOUGH" 14} 15
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
404 | NOT_FOUND | 资金出境退回单不存在 | 请检查二级商户号、商户出境退回单号是否正确 |
429 | FREQUENCY_LIMITED | 频率限制 | 请降低频率后重试 |
