发起异常退款
更新时间:2025.01.16
|
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/refund/domestic/refunds/{refund_id}/apply-abnormal-refund
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
path 路径参数
refund_id 必填 string(32)
【微信支付退款单号】申请退款受理成功时,该笔退款单在微信支付侧生成的唯一标识。申请退款成功后会返回该参数,查询退款或者退款结果通知也会返回该参数。
body 包体参数
sub_mchid 必填 string(32)
【子商户号(也叫特约商户号)】 服务商下单时传入的子商户号sub_mchid。
out_refund_no 必填 string(64)
【商户退款单号】 商户申请退款时传的商户系统内部退款单号。
type 必填 string
【异常退款处理方式】 可选:退款至用户银行卡、退款至交易商户银行账户
可选取值
USER_BANK_CARD
: 退款到用户银行卡MERCHANT_BANK_CARD
: 退款至交易商户银行账户
bank_type 选填 string(16)
【开户银行】 银行类型,采用字符串类型的银行标识,值列表详见银行类型。仅支持招行、交通银行、农行、建行、工商、中行、平安、浦发、中信、光大、民生、兴业、广发、邮储、宁波银行的借记卡。
若退款至用户此字段必填。
bank_account 选填 string(1024)
【收款银行卡号】用户的银行卡账号,该字段需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及如何使用微信支付公钥加密敏感字段,也可以使用微信支付平台证书公钥加密,参考平台证书简介与使用说明、如何使用平台证书加密敏感字段
若退款至用户此字段必填。
real_name 选填 string(1024)
【收款用户姓名】 收款用户姓名,该字段需要使用微信支付公钥加密(推荐),请参考获取微信支付公钥ID说明以及如何使用微信支付公钥加密敏感字段,也可以使用微信支付平台证书公钥加密,参考平台证书简介与使用说明、如何使用平台证书加密敏感字段
若退款至用户此字段必填。
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/refund/domestic/refunds/50000000382019052709732678859/apply-abnormal-refund \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: 5157F09EFDC096DE15EBE81A47057A7232F1B8E1" \ 6 -H "Content-Type: application/json" \ 7 -d '{ 8 "sub_mchid" : "1900000109", 9 "out_refund_no" : "1217752501201407033233368018", 10 "type" : "MERCHANT_BANK_CARD", 11 "bank_type" : "ICBC_DEBIT", 12 "bank_account" : "d+xT+MQCvrLHUVDWv/8MR/dB7TkXLVfSrUxMPZy6jWWYzpRrEEaYQE8ZRGYoeorwC+w==", 13 "real_name" : "UPgQcZSdq3zOayJwZ5XLrHY2dZU1W2Cd" 14 }' 15
需配合微信支付工具库 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 CreateAbnormalRefund { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/refund/domestic/refunds/{refund_id}/apply-abnormal-refund"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CreateAbnormalRefund client = new CreateAbnormalRefund( 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 CreateAbnormalRefundRequest request = new CreateAbnormalRefundRequest(); 41 request.refundId = "50000000382019052709732678859"; 42 request.subMchid = "1900000109"; 43 request.outRefundNo = "1217752501201407033233368018"; 44 request.type = AbnormalReceiveType.MERCHANT_BANK_CARD; 45 request.bankType = "ICBC_DEBIT"; 46 request.bankAccount = client.encrypt("bank_account"); 47 request.realName = client.encrypt("real_name"); 48 try { 49 Refund response = client.run(request); 50 // TODO: 请求成功,继续业务逻辑 51 System.out.println(response); 52 } catch (WXPayUtility.ApiException e) { 53 // TODO: 请求失败,根据状态码执行不同的逻辑 54 e.printStackTrace(); 55 } 56 } 57 58 public Refund run(CreateAbnormalRefundRequest request) { 59 String uri = PATH; 60 uri = uri.replace("{refund_id}", WXPayUtility.urlEncode(request.refundId)); 61 String reqBody = WXPayUtility.toJson(request); 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, reqBody)); 67 reqBuilder.addHeader("Content-Type", "application/json"); 68 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 69 reqBuilder.method(METHOD, requestBody); 70 Request httpRequest = reqBuilder.build(); 71 72 // 发送HTTP请求 73 OkHttpClient client = new OkHttpClient.Builder().build(); 74 try (Response httpResponse = client.newCall(httpRequest).execute()) { 75 String respBody = WXPayUtility.extractBody(httpResponse); 76 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 77 // 2XX 成功,验证应答签名 78 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 79 httpResponse.headers(), respBody); 80 81 // 从HTTP应答报文构建返回数据 82 return WXPayUtility.fromJson(respBody, Refund.class); 83 } else { 84 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 85 } 86 } catch (IOException e) { 87 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 88 } 89 } 90 91 private final String mchid; 92 private final String certificateSerialNo; 93 private final PrivateKey privateKey; 94 private final String wechatPayPublicKeyId; 95 private final PublicKey wechatPayPublicKey; 96 97 public CreateAbnormalRefund(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 98 this.mchid = mchid; 99 this.certificateSerialNo = certificateSerialNo; 100 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 101 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 102 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 103 } 104 105 public String encrypt(String plainText) { 106 return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText); 107 } 108 109 public static class CreateAbnormalRefundRequest { 110 @SerializedName("refund_id") 111 @Expose(serialize = false) 112 public String refundId; 113 114 @SerializedName("sub_mchid") 115 public String subMchid; 116 117 @SerializedName("out_refund_no") 118 public String outRefundNo; 119 120 @SerializedName("type") 121 public AbnormalReceiveType type; 122 123 @SerializedName("bank_type") 124 public String bankType; 125 126 @SerializedName("bank_account") 127 public String bankAccount; 128 129 @SerializedName("real_name") 130 public String realName; 131 } 132 133 public static class Refund { 134 @SerializedName("refund_id") 135 public String refundId; 136 137 @SerializedName("out_refund_no") 138 public String outRefundNo; 139 140 @SerializedName("transaction_id") 141 public String transactionId; 142 143 @SerializedName("out_trade_no") 144 public String outTradeNo; 145 146 @SerializedName("channel") 147 public Channel channel; 148 149 @SerializedName("user_received_account") 150 public String userReceivedAccount; 151 152 @SerializedName("success_time") 153 public String successTime; 154 155 @SerializedName("create_time") 156 public String createTime; 157 158 @SerializedName("status") 159 public Status status; 160 161 @SerializedName("funds_account") 162 public FundsAccount fundsAccount; 163 164 @SerializedName("amount") 165 public Amount amount; 166 167 @SerializedName("promotion_detail") 168 public List<Promotion> promotionDetail; 169 170 @SerializedName("refund_account") 171 public RefundAccount refundAccount; 172 } 173 174 public enum AbnormalReceiveType { 175 @SerializedName("USER_BANK_CARD") 176 USER_BANK_CARD, 177 @SerializedName("MERCHANT_BANK_CARD") 178 MERCHANT_BANK_CARD 179 } 180 181 public enum Channel { 182 @SerializedName("ORIGINAL") 183 ORIGINAL, 184 @SerializedName("BALANCE") 185 BALANCE, 186 @SerializedName("OTHER_BALANCE") 187 OTHER_BALANCE, 188 @SerializedName("OTHER_BANKCARD") 189 OTHER_BANKCARD 190 } 191 192 public enum Status { 193 @SerializedName("SUCCESS") 194 SUCCESS, 195 @SerializedName("CLOSED") 196 CLOSED, 197 @SerializedName("PROCESSING") 198 PROCESSING, 199 @SerializedName("ABNORMAL") 200 ABNORMAL 201 } 202 203 public enum FundsAccount { 204 @SerializedName("UNSETTLED") 205 UNSETTLED, 206 @SerializedName("AVAILABLE") 207 AVAILABLE, 208 @SerializedName("UNAVAILABLE") 209 UNAVAILABLE, 210 @SerializedName("OPERATION") 211 OPERATION, 212 @SerializedName("BASIC") 213 BASIC, 214 @SerializedName("ECNY_BASIC") 215 ECNY_BASIC 216 } 217 218 public static class Amount { 219 @SerializedName("total") 220 public Long total; 221 222 @SerializedName("refund") 223 public Long refund; 224 225 @SerializedName("from") 226 public List<FundsFromItem> from; 227 228 @SerializedName("payer_total") 229 public Long payerTotal; 230 231 @SerializedName("payer_refund") 232 public Long payerRefund; 233 234 @SerializedName("settlement_refund") 235 public Long settlementRefund; 236 237 @SerializedName("settlement_total") 238 public Long settlementTotal; 239 240 @SerializedName("discount_refund") 241 public Long discountRefund; 242 243 @SerializedName("currency") 244 public String currency; 245 246 @SerializedName("refund_fee") 247 public Long refundFee; 248 249 @SerializedName("advance") 250 public Long advance; 251 } 252 253 public static class Promotion { 254 @SerializedName("promotion_id") 255 public String promotionId; 256 257 @SerializedName("scope") 258 public PromotionScope scope; 259 260 @SerializedName("type") 261 public PromotionType type; 262 263 @SerializedName("amount") 264 public Long amount; 265 266 @SerializedName("refund_amount") 267 public Long refundAmount; 268 269 @SerializedName("goods_detail") 270 public List<GoodsDetail> goodsDetail; 271 } 272 273 public enum RefundAccount { 274 @SerializedName("REFUND_SOURCE_PARTNER_ADVANCE") 275 REFUND_SOURCE_PARTNER_ADVANCE, 276 @SerializedName("REFUND_SOURCE_SUB_MERCHANT") 277 REFUND_SOURCE_SUB_MERCHANT, 278 @SerializedName("REFUND_SOURCE_SUB_MERCHANT_ADVANCE") 279 REFUND_SOURCE_SUB_MERCHANT_ADVANCE 280 } 281 282 public static class FundsFromItem { 283 @SerializedName("account") 284 public Account account; 285 286 @SerializedName("amount") 287 public Long amount; 288 } 289 290 public enum PromotionScope { 291 @SerializedName("GLOBAL") 292 GLOBAL, 293 @SerializedName("SINGLE") 294 SINGLE 295 } 296 297 public enum PromotionType { 298 @SerializedName("COUPON") 299 COUPON, 300 @SerializedName("DISCOUNT") 301 DISCOUNT 302 } 303 304 public static class GoodsDetail { 305 @SerializedName("merchant_goods_id") 306 public String merchantGoodsId; 307 308 @SerializedName("wechatpay_goods_id") 309 public String wechatpayGoodsId; 310 311 @SerializedName("goods_name") 312 public String goodsName; 313 314 @SerializedName("unit_price") 315 public Long unitPrice; 316 317 @SerializedName("refund_amount") 318 public Long refundAmount; 319 320 @SerializedName("refund_quantity") 321 public Long refundQuantity; 322 } 323 324 public enum Account { 325 @SerializedName("AVAILABLE") 326 AVAILABLE, 327 @SerializedName("UNAVAILABLE") 328 UNAVAILABLE 329 } 330 331} 332
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "strings" 11 "time" 12) 13 14func main() { 15 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 config, err := wxpay_utility.CreateMchConfig( 17 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 18 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 19 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 20 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 21 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 22 ) 23 if err != nil { 24 fmt.Println(err) 25 return 26 } 27 28 request := &CreateAbnormalRefundRequest{ 29 RefundId: wxpay_utility.String("50000000382019052709732678859"), 30 SubMchid: wxpay_utility.String("1900000109"), 31 OutRefundNo: wxpay_utility.String("1217752501201407033233368018"), 32 Type: ABNORMALRECEIVETYPE_MERCHANT_BANK_CARD.Ptr(), 33 BankType: wxpay_utility.String("ICBC_DEBIT"), 34 BankAccount: wxpay_utility.String("d+xT+MQCvrLHUVDWv/8MR/dB7TkXLVfSrUxMPZy6jWWYzpRrEEaYQE8ZRGYoeorwC+w=="), /*请传入wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/ 35 RealName: wxpay_utility.String("UPgQcZSdq3zOayJwZ5XLrHY2dZU1W2Cd"), /*请传入wxpay_utility.EncryptOAEPWithPublicKey 加密结果*/ 36 } 37 38 response, err := CreateAbnormalRefund(config, request) 39 if err != nil { 40 fmt.Printf("请求失败: %+v\n", err) 41 // TODO: 请求失败,根据状态码执行不同的处理 42 return 43 } 44 45 // TODO: 请求成功,继续业务逻辑 46 fmt.Printf("请求成功: %+v\n", response) 47} 48 49func CreateAbnormalRefund(config *wxpay_utility.MchConfig, request *CreateAbnormalRefundRequest) (response *Refund, err error) { 50 const ( 51 host = "https://api.mch.weixin.qq.com" 52 method = "POST" 53 path = "/v3/refund/domestic/refunds/{refund_id}/apply-abnormal-refund" 54 ) 55 56 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 57 if err != nil { 58 return nil, err 59 } 60 reqUrl.Path = strings.Replace(reqUrl.Path, "{refund_id}", url.PathEscape(*request.RefundId), -1) 61 reqBody, err := json.Marshal(request) 62 if err != nil { 63 return nil, err 64 } 65 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 66 if err != nil { 67 return nil, err 68 } 69 httpRequest.Header.Set("Accept", "application/json") 70 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 71 httpRequest.Header.Set("Content-Type", "application/json") 72 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 73 if err != nil { 74 return nil, err 75 } 76 httpRequest.Header.Set("Authorization", authorization) 77 78 client := &http.Client{} 79 httpResponse, err := client.Do(httpRequest) 80 if err != nil { 81 return nil, err 82 } 83 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 84 if err != nil { 85 return nil, err 86 } 87 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 88 // 2XX 成功,验证应答签名 89 err = wxpay_utility.ValidateResponse( 90 config.WechatPayPublicKeyId(), 91 config.WechatPayPublicKey(), 92 &httpResponse.Header, 93 respBody, 94 ) 95 if err != nil { 96 return nil, err 97 } 98 response := &Refund{} 99 if err := json.Unmarshal(respBody, response); err != nil { 100 return nil, err 101 } 102 103 return response, nil 104 } else { 105 return nil, wxpay_utility.NewApiException( 106 httpResponse.StatusCode, 107 httpResponse.Header, 108 respBody, 109 ) 110 } 111} 112 113type CreateAbnormalRefundRequest struct { 114 RefundId *string `json:"refund_id,omitempty"` 115 SubMchid *string `json:"sub_mchid,omitempty"` 116 OutRefundNo *string `json:"out_refund_no,omitempty"` 117 Type *AbnormalReceiveType `json:"type,omitempty"` 118 BankType *string `json:"bank_type,omitempty"` 119 BankAccount *string `json:"bank_account,omitempty"` 120 RealName *string `json:"real_name,omitempty"` 121} 122 123func (o *CreateAbnormalRefundRequest) MarshalJSON() ([]byte, error) { 124 type Alias CreateAbnormalRefundRequest 125 a := &struct { 126 RefundId *string `json:"refund_id,omitempty"` 127 *Alias 128 }{ 129 // 序列化时移除非 Body 字段 130 RefundId: nil, 131 Alias: (*Alias)(o), 132 } 133 return json.Marshal(a) 134} 135 136type Refund struct { 137 RefundId *string `json:"refund_id,omitempty"` 138 OutRefundNo *string `json:"out_refund_no,omitempty"` 139 TransactionId *string `json:"transaction_id,omitempty"` 140 OutTradeNo *string `json:"out_trade_no,omitempty"` 141 Channel *Channel `json:"channel,omitempty"` 142 UserReceivedAccount *string `json:"user_received_account,omitempty"` 143 SuccessTime *time.Time `json:"success_time,omitempty"` 144 CreateTime *time.Time `json:"create_time,omitempty"` 145 Status *Status `json:"status,omitempty"` 146 FundsAccount *FundsAccount `json:"funds_account,omitempty"` 147 Amount *Amount `json:"amount,omitempty"` 148 PromotionDetail []Promotion `json:"promotion_detail,omitempty"` 149 RefundAccount *RefundAccount `json:"refund_account,omitempty"` 150} 151 152type AbnormalReceiveType string 153 154func (e AbnormalReceiveType) Ptr() *AbnormalReceiveType { 155 return &e 156} 157 158const ( 159 ABNORMALRECEIVETYPE_USER_BANK_CARD AbnormalReceiveType = "USER_BANK_CARD" 160 ABNORMALRECEIVETYPE_MERCHANT_BANK_CARD AbnormalReceiveType = "MERCHANT_BANK_CARD" 161) 162 163type Channel string 164 165func (e Channel) Ptr() *Channel { 166 return &e 167} 168 169const ( 170 CHANNEL_ORIGINAL Channel = "ORIGINAL" 171 CHANNEL_BALANCE Channel = "BALANCE" 172 CHANNEL_OTHER_BALANCE Channel = "OTHER_BALANCE" 173 CHANNEL_OTHER_BANKCARD Channel = "OTHER_BANKCARD" 174) 175 176type Status string 177 178func (e Status) Ptr() *Status { 179 return &e 180} 181 182const ( 183 STATUS_SUCCESS Status = "SUCCESS" 184 STATUS_CLOSED Status = "CLOSED" 185 STATUS_PROCESSING Status = "PROCESSING" 186 STATUS_ABNORMAL Status = "ABNORMAL" 187) 188 189type FundsAccount string 190 191func (e FundsAccount) Ptr() *FundsAccount { 192 return &e 193} 194 195const ( 196 FUNDSACCOUNT_UNSETTLED FundsAccount = "UNSETTLED" 197 FUNDSACCOUNT_AVAILABLE FundsAccount = "AVAILABLE" 198 FUNDSACCOUNT_UNAVAILABLE FundsAccount = "UNAVAILABLE" 199 FUNDSACCOUNT_OPERATION FundsAccount = "OPERATION" 200 FUNDSACCOUNT_BASIC FundsAccount = "BASIC" 201 FUNDSACCOUNT_ECNY_BASIC FundsAccount = "ECNY_BASIC" 202) 203 204type Amount struct { 205 Total *int64 `json:"total,omitempty"` 206 Refund *int64 `json:"refund,omitempty"` 207 From []FundsFromItem `json:"from,omitempty"` 208 PayerTotal *int64 `json:"payer_total,omitempty"` 209 PayerRefund *int64 `json:"payer_refund,omitempty"` 210 SettlementRefund *int64 `json:"settlement_refund,omitempty"` 211 SettlementTotal *int64 `json:"settlement_total,omitempty"` 212 DiscountRefund *int64 `json:"discount_refund,omitempty"` 213 Currency *string `json:"currency,omitempty"` 214 RefundFee *int64 `json:"refund_fee,omitempty"` 215 Advance *int64 `json:"advance,omitempty"` 216} 217 218type Promotion struct { 219 PromotionId *string `json:"promotion_id,omitempty"` 220 Scope *PromotionScope `json:"scope,omitempty"` 221 Type *PromotionType `json:"type,omitempty"` 222 Amount *int64 `json:"amount,omitempty"` 223 RefundAmount *int64 `json:"refund_amount,omitempty"` 224 GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"` 225} 226 227type RefundAccount string 228 229func (e RefundAccount) Ptr() *RefundAccount { 230 return &e 231} 232 233const ( 234 REFUNDACCOUNT_REFUND_SOURCE_PARTNER_ADVANCE RefundAccount = "REFUND_SOURCE_PARTNER_ADVANCE" 235 REFUNDACCOUNT_REFUND_SOURCE_SUB_MERCHANT RefundAccount = "REFUND_SOURCE_SUB_MERCHANT" 236 REFUNDACCOUNT_REFUND_SOURCE_SUB_MERCHANT_ADVANCE RefundAccount = "REFUND_SOURCE_SUB_MERCHANT_ADVANCE" 237) 238 239type FundsFromItem struct { 240 Account *Account `json:"account,omitempty"` 241 Amount *int64 `json:"amount,omitempty"` 242} 243 244type PromotionScope string 245 246func (e PromotionScope) Ptr() *PromotionScope { 247 return &e 248} 249 250const ( 251 PROMOTIONSCOPE_GLOBAL PromotionScope = "GLOBAL" 252 PROMOTIONSCOPE_SINGLE PromotionScope = "SINGLE" 253) 254 255type PromotionType string 256 257func (e PromotionType) Ptr() *PromotionType { 258 return &e 259} 260 261const ( 262 PROMOTIONTYPE_COUPON PromotionType = "COUPON" 263 PROMOTIONTYPE_DISCOUNT PromotionType = "DISCOUNT" 264) 265 266type GoodsDetail struct { 267 MerchantGoodsId *string `json:"merchant_goods_id,omitempty"` 268 WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"` 269 GoodsName *string `json:"goods_name,omitempty"` 270 UnitPrice *int64 `json:"unit_price,omitempty"` 271 RefundAmount *int64 `json:"refund_amount,omitempty"` 272 RefundQuantity *int64 `json:"refund_quantity,omitempty"` 273} 274 275type Account string 276 277func (e Account) Ptr() *Account { 278 return &e 279} 280 281const ( 282 ACCOUNT_AVAILABLE Account = "AVAILABLE" 283 ACCOUNT_UNAVAILABLE Account = "UNAVAILABLE" 284) 285
应答参数
|
refund_id 必填 string(32)
【微信支付退款单号】申请退款受理成功时,该笔退款单在微信支付侧生成的唯一标识。
out_refund_no 必填 string(64)
【商户退款单号】 服务商申请退款时传入的商户系统内部退款单号。
transaction_id 必填 string(32)
【微信支付订单号】微信支付侧订单的唯一标识。
out_trade_no 必填 string(32)
【商户订单号】 服务商下单时传入的服务商系统内部订单号。
channel 必填 string
【退款渠道】 订单退款渠道
以下枚举:
ORIGINAL
: 原路退款BALANCE
: 退回到余额OTHER_BALANCE
: 原账户异常退到其他余额账户OTHER_BANKCARD
: 原银行卡异常退到其他银行卡(发起异常退款成功后返回)
user_received_account 必填 string(64)
【退款入账账户】 取当前退款单的退款入账方,有以下几种情况:
1)退回银行卡:{银行名称}{卡类型}{卡尾号}
2)退回支付用户零钱:支付用户零钱
3)退还商户:商户基本账户商户结算银行账户
4)退回支付用户零钱通:支付用户零钱通
5)退回支付用户银行电子账户:支付用户银行电子账户
6)退回支付用户零花钱:支付用户零花钱
7)退回用户经营账户:用户经营账户
8)退回支付用户来华零钱包:支付用户来华零钱包
9)退回企业支付商户:企业支付商户
10)退回支付用户小金罐:支付用户小金罐
success_time 选填 string(64)
【退款成功时间】
1、定义:退款成功的时间,该字段在退款状态status为SUCCESS(退款成功)时返回。
2、格式:遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE
。yyyy-MM-DD
表示年月日;T
字符用于分隔日期和时间部分;HH:mm:ss
表示具体的时分秒;TIMEZONE
表示时区(例如,+08:00
对应东八区时间,即北京时间)。
示例:2015-05-20T13:29:35+08:00
表示北京时间2015年5月20日13点29分35秒。
create_time 必填 string(64)
【退款创建时间】
1、定义:提交退款申请成功,微信受理退款申请单的时间。
2、格式:遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE
。yyyy-MM-DD
表示年月日;T
字符用于分隔日期和时间部分;HH:mm:ss
表示具体的时分秒;TIMEZONE
表示时区(例如,+08:00
对应东八区时间,即北京时间)。
示例:2015-05-20T13:29:35+08:00
表示北京时间2015年5月20日13点29分35秒。
status 必填 string
【退款状态】退款单的退款处理状态。
SUCCESS
: 退款成功CLOSED
: 退款关闭PROCESSING
: 退款处理中ABNORMAL
: 退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往服务商平台-交易中心,手动处理此笔退款,可参考: 退款异常的处理,或者通过发起异常退款接口进行处理。
注:状态流转说明请参考状态流转图
funds_account 必填 string
【资金账户】 退款所使用资金对应的资金账户类型
UNSETTLED
: 未结算资金AVAILABLE
: 可用余额UNAVAILABLE
: 不可用余额OPERATION
: 运营账户BASIC
: 基本账户(含可用余额和不可用余额)ECNY_BASIC
: 数字人民币基本账户
amount 必填 object
【金额信息】订单退款金额信息
属性 | |||||
total 必填 integer 【订单金额】 订单总金额,单位为分 refund 必填 integer 【退款金额】退款金额,单位为分,只能为整数,可以做部分退款,不能超过原订单支付金额。 from 选填 array[object] 【退款出资账户及金额】 退款出资的账户类型及金额信息,若此接口请求时未传该参数,则不会返回。
payer_total 必填 integer 【用户实际支付金额】用户现金支付金额,整型,单位为分,例如10元订单用户使用了2元全场代金券,则该金额为用户实际支付的8元。 payer_refund 必填 integer 【用户退款金额】 指用户实际收到的现金退款金额,数据类型为整型,单位为分。例如在一个10元的订单中,用户使用了2元的全场代金券,若商户申请退款5元,则用户将收到4元的现金退款(即该字段所示金额)和1元的代金券退款。 settlement_refund 必填 integer 【应结退款金额】 去掉免充值代金券退款金额后的退款金额,整型,单位为分,例如10元订单用户使用了2元全场代金券(一张免充值1元 + 一张预充值1元),商户申请退款5元,则该金额为 退款金额5元 - 0.5元免充值代金券退款金额 = 4.5元。 settlement_total 必填 integer 【应结订单金额】去除免充值代金券金额后的订单金额,整型,单位为分,例如10元订单用户使用了2元全场代金券(一张免充值1元 + 一张预充值1元),则该金额为 订单金额10元 - 免充值代金券金额1元 = 9元。 discount_refund 必填 integer 【优惠退款金额】 申请退款后用户收到的代金券退款金额,整型,单位为分,例如10元订单用户使用了2元全场代金券,商户申请退款5元,用户收到的是4元现金 + 1元代金券退款金额(该字段) 。 currency 必填 string(16) 【退款币种】 固定返回:CNY,代表人民币。 refund_fee 选填 integer 【手续费退款金额】 订单退款时退还的手续费金额,整型,单位为分,例如一笔100元的订单收了0.6元手续费,商户申请退款50元,该金额为等比退还的0.3元手续费。 |
promotion_detail 选填 array[object]
【优惠退款详情】 订单各个代金券的退款详情,订单使用了代金券且代金券发生退款时返回。
属性 | |||||
promotion_id 必填 string(32) 【券ID】代金券id,单张代金券的编号 scope 必填 string 【优惠范围】优惠活动中代金券的适用范围,分为两种类型: type 必填 string 【优惠类型】代金券资金类型,优惠活动中代金券的结算资金类型,分为两种类型: amount 必填 integer 【代金券面额】 代金券优惠的金额 refund_amount 必填 integer 【优惠退款金额】 代金券退款的金额 goods_detail 选填 array[object] 【退款商品】 指定商品退款时传的退款商品信息。
|
应答示例
200 OK
1{ 2 "refund_id" : "50000000382019052709732678859", 3 "out_refund_no" : "1217752501201407033233368018", 4 "transaction_id" : "1217752501201407033233368018", 5 "out_trade_no" : "1217752501201407033233368018", 6 "channel" : "ORIGINAL", 7 "user_received_account" : "招商银行信用卡0403", 8 "success_time" : "2020-12-01T16:18:12+08:00", 9 "create_time" : "2020-12-01T16:18:12+08:00", 10 "status" : "SUCCESS", 11 "funds_account" : "UNSETTLED", 12 "amount" : { 13 "total" : 100, 14 "refund" : 100, 15 "from" : [ 16 { 17 "account" : "AVAILABLE", 18 "amount" : 444 19 } 20 ], 21 "payer_total" : 90, 22 "payer_refund" : 90, 23 "settlement_refund" : 100, 24 "settlement_total" : 100, 25 "discount_refund" : 10, 26 "currency" : "CNY", 27 "refund_fee" : 100, 28 "advance" : 888 29 }, 30 "promotion_detail" : [ 31 { 32 "promotion_id" : "109519", 33 "scope" : "SINGLE", 34 "type" : "DISCOUNT", 35 "amount" : 5, 36 "refund_amount" : 100, 37 "goods_detail" : [ 38 { 39 "merchant_goods_id" : "1217752501201407033233368018", 40 "wechatpay_goods_id" : "1001", 41 "goods_name" : "iPhone6s 16G", 42 "unit_price" : 528800, 43 "refund_amount" : 528800, 44 "refund_quantity" : 1 45 } 46 ] 47 } 48 ], 49 "refund_account" : "REFUND_SOURCE_SUB_MERCHANT" 50} 51
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 此状态代表本次请求的退款申请失败,请根据具体的错误提示做相应处理。 |
401 | SIGN_ERROR | 签名错误 | 请检查签名参数和方法是否都符合签名算法要求,参考:如何生成签名 |
404 | RESOURCE_NOT_EXISTS | 退款单不存在 | 请检查退款单号是否有误 |
429 | FREQUENCY_LIMITED | 频率限制 | 该笔退款为受理中,请调用查单接口确认或降低频率原单重试,重试请勿更换单号 |
500 | SYSTEM_ERROR | 系统超时等 | 请不要更换商户退款单号,请使用相同参数再次调用API。 |