退款查询

应用场景

提交退款申请后,如果申请退款接口返回的refund_state为wait状态,需要通过调用该接口查询退款状态。

接口链接

请求方式:POST

URL地址:{BASE_URL}/v1/transactions/refundid.html

请求参数

字段名 变量名 必填 类型 示例值 描述
应用ID app_id String app_9ba59abbe56e057f20f 由易码付平台生成的应用ID,全局唯一。
商户退款单号 out_refund_no String 190011178361713

商户退款单号

参数必传,值可以传空

商户退款单号和平台退款单号不能同时为空,out_refund_no,refund_no如果同时存在优先取out_refund_no

平台退款单号 refund_no String TK2108142002121923822

平台退款单号

参数必传,值可以传空

商户退款单号和平台退款单号不能同时为空,out_refund_no,refund_no如果同时存在优先取out_refund_no

签名串 sign String aa4bf6d01803310d4d99c9da59dd1f29 待签名字符串进行MD5加密得出的32位签名值,参考签名规则

举例如下:

{BASE_URL}/v1/transactions/refundid.html?app_id=app_159f7a1756bf8b08&out_refund_no=190009507085358&refund_no=TK20220523123254158963&sign=f74e3b4a9e2bcb971c3a68c80286bc8e

返回结果

字段名 变量名 必填 类型 示例值 描述
业务状态码 resultCode Int 200

200/201/500

此字段是业务标识状态码,200代表业务处理成功,并成功返回

业务状态描述 message String 成功

当resultCode非200时返回信息为错误原因 ,例如

app_id错误或不存在

数据集 Data String -

当resultCode为200时,数据会装入该字段一并返回

out_refund_no String 1217752501035987 退款订单:商户端退款单号
refund_no String TK2108142002121923822 退款订单:平台退款单号
platform_refund_no String 188632571217752501201407 退款订单:第三方退款单号
refund_reason String 缺货 退款订单:退款理由
refund_msg String 退款成功 退款订单:说明
refund_amount Int 100 退款订单:退款金额,单位为分。1元等于100分
refund_state String success

退款订单:退款状态

success:退款成功

failed:退款失败

wait:退款中

close:订单关闭

refund_create_time String 2022-09-07 09:41:47 退款订单:退款创建时间,格式yyyy-MM-dd HH:mm:ss
refund_success_time String 2022-09-07 09:49:47 退款订单:退款成功时间,格式yyyy-MM-dd HH:mm:ss
trade_no String YH2307190011178361713 原交易订单:平台交易单号
out_trade_no String 156354587546455 原交易订单:商户交易单号
pay_type Int 20 原交易订单:支付方式
channel String wx_qr 原交易订单:支付渠道代码
description String 苹果手机 原交易订单:商品描述
amount String 100 原交易订单:订单金额,单位为分
pay_time String 2022-09-05 09:41:47 原交易订单:付款时间,格式yyyy-MM-dd HH:mm:ss

举例如下:

{
    "resultCode":200,
    "message":"成功",
    "Data":{
        "description":"iPhone+13+Pro",
        "channel":"alipay_app",
        "pay_type":30,
        "trade_no":"YH2308251715577476213",
        "out_trade_no":"MER1692954956218",
        "amount":200,
        "pay_time":"2023-08-25 17:15:57",
        "refund_no":"TK2108142002121923822",
        "out_refund_no":"1217752501035987",
        "platform_refund_no":"123175757258019034593871",
        "refund_amount":200,
        "refund_reason":"%E7%BC%BA%E8%B4%A7",
        "refund_msg":"%E9%80%80%E6%AC%BE%E6%88%90%E5%8A%9F",
        "refund_state":"success",
        "refund_create_time":"2022-09-07 09:41:47",
        "refund_success_time":"2022-09-07 09:49:47",
        "app_id":"app_7ca649d7cef5deb2"
    }
}

状态码

状态码 描述
200 成功
201 业务错误,具体错误信息请参照message字段
500 系统错误

代码示例

# 查询单笔退款
curl -X POST "{BASE_URL}/v1/transactions/refundid.html" \
  -d "app_id={YOUR_APP_ID}" \
  -d "out_refund_no=REF20240101001" \
  -d "sign=E10ADC3949BA59ABBE56E057F20F883E"
<?php
$appId  = '{YOUR_APP_ID}';
$apiKey = '{YOUR_API_KEY}';
$params = [
    'app_id'        => $appId,
    'out_refund_no' => 'REF20240101001',
];
ksort($params);
$signStr = urldecode(http_build_query($params)) . '&key=' . $apiKey;
$params['sign'] = strtoupper(md5($signStr));

$ch = curl_init('{BASE_URL}/v1/transactions/refundid.html');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
print_r($response);
import hashlib
import requests

app_id = '{YOUR_APP_ID}'
api_key = '{YOUR_API_KEY}'
params = {
    'app_id': app_id,
    'out_refund_no': 'REF20240101001',
}
sorted_keys = sorted(params.keys())
sign_str = '&'.join(f'{k}={params[k]}' for k in sorted_keys) + '&key=' + api_key
params['sign'] = hashlib.md5(sign_str.encode()).hexdigest().upper()

resp = requests.post('{BASE_URL}/v1/transactions/refundid.html', data=params)
print(resp.json())
import java.io.*;
import java.net.*;
import java.security.MessageDigest;
import java.util.*;

public class QueryRefund {
    public static void main(String[] args) throws Exception {
        String appId = "{YOUR_APP_ID}";
        String apiKey = "{YOUR_API_KEY}";
        Map<String, String> params = new TreeMap<>();
        params.put("app_id", appId);
        params.put("out_refund_no", "REF20240101001");
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> e : params.entrySet())
            sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
        sb.append("key=").append(apiKey);
        String sign = md5(sb.toString()).toUpperCase();
        params.put("sign", sign);
        String result = doPost("{BASE_URL}/v1/transactions/refundid.html", params);
        System.out.println(result);
    }
    static String md5(String s) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(s.getBytes("UTF-8"));
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) sb.append(String.format("%02x", b));
        return sb.toString();
    }
    static String doPost(String url, Map<String, String> params) throws Exception {
        StringBuilder body = new StringBuilder();
        for (Map.Entry<String, String> e : params.entrySet())
            body.append(URLEncoder.encode(e.getKey(), "UTF-8"))
                .append("=").append(URLEncoder.encode(e.getValue(), "UTF-8")).append("&");
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.getOutputStream().write(body.toString().getBytes("UTF-8"));
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        StringBuilder resp = new StringBuilder();
        String line; while ((line = br.readLine()) != null) resp.append(line);
        return resp.toString();
    }
}
const crypto = require('crypto');
const axios = require('axios');
const querystring = require('querystring');

const appId = '{YOUR_APP_ID}';
const apiKey = '{YOUR_API_KEY}';
const params = { app_id: appId, out_refund_no: 'REF20240101001' };
const sortedKeys = Object.keys(params).sort();
const signStr = sortedKeys.map(k => `=`).join('&') + '&key=' + apiKey;
params.sign = crypto.createHash('md5').update(signStr).digest('hex').toUpperCase();

axios.post('{BASE_URL}/v1/transactions/refundid.html', querystring.stringify(params))
    .then(res => console.log(res.data));
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;

var appId = "{YOUR_APP_ID}";
var apiKey = "{YOUR_API_KEY}";
var paramList = new List<KeyValuePair<string, string>> {
    new("app_id", appId),
    new("out_refund_no", "REF20240101001"),
};
paramList.Sort((a, b) => string.Compare(a.Key, b.Key, StringComparison.Ordinal));
var signStr = string.Join("&", paramList.Select(p => $"{p.Key}={p.Value}")) + "&key=" + apiKey;
using var md5 = MD5.Create();
var sign = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(signStr))).Replace("-","").ToUpper();
paramList.Add(new("sign", sign));

using var client = new HttpClient();
var resp = await client.PostAsync("{BASE_URL}/v1/transactions/refundid.html", new FormUrlEncodedContent(paramList));
Console.WriteLine(await resp.Content.ReadAsStringAsync());
package main

import (
    "crypto/md5"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "sort"
    "strings"
)

func main() {
    appId := "{YOUR_APP_ID}"
    apiKey := "{YOUR_API_KEY}"
    params := url.Values{}
    params.Set("app_id", appId)
    params.Set("out_refund_no", "REF20240101001")
    keys := make([]string, 0)
    for k := range params { keys = append(keys, k) }
    sort.Strings(keys)
    var parts []string
    for _, k := range keys { parts = append(parts, k+"="+params.Get(k)) }
    signStr := strings.Join(parts, "&") + "&key=" + apiKey
    sign := fmt.Sprintf("%X", md5.Sum([]byte(signStr)))
    params.Set("sign", sign)

    resp, _ := http.PostForm("{BASE_URL}/v1/transactions/refundid.html", params)
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}