接口名称:统一收单交易退款查询
英文名称:alipay.trade.fastpay.refund.query
主要用于查询退款交易详情信息
一、文档地址
官方文档地址:[url]https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query[/url]
二、开发前准备工作
调用步骤:[url]https://openclub.alipay.com/read.php?tid=12194&fid=69[/url]
注意事项:1、支持沙箱测试;2、需签约并添加功能;3、支持第三方调用。
如何签约以及签约无法成功等相关签约问题:[url]https://openclub.alipay.com/read.php?tid=276&fid=72[/url]
注:该接口为辅助接口,只要签约当面付、手机网站支付、电脑网站支付和APP支付,四个支付接口中其中一个就可以调用。
三、接口集成代码示例
1、参数说明
(1)out_trade_no:商户订单号,该参数值为退款接口中设置的out_trade_no参数值;
(2)trade_no:支付宝交易号,该参数值为支付接口订单创建后,退款接口设置的trade_no参数值;
注:out_trade_no和trade_no至少必传其中一个参数,两者同时设置优先取值trade_no。
(3)out_request_no:退款请求标识,该参数值设置为退款接口中设置的out_request_no参数值;
2、JAVA版请求示例
public static void main(String[] args) throws AlipayApiException { AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type); AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); AlipayTradeFastpayRefundQueryModel model = new AlipayTradeFastpayRefundQueryModel(); //外部订单号,与tradeNo二选一 model.setOutTradeNo("sao201881610515614516"); // model.setTradeNo("2019031922001494891000002604"); //OutTradeNo:标识一次退款请求,同一笔交易多次退款需要保证唯一,如退款接口设置,则此参数必传。 model.setOutRequestNo("HZ01RF001"); request.setBizModel(model); AlipayTradeFastpayRefundQueryResponse response = alipayClient.execute(request); if(response.isSuccess()){ System.out.println("调用成功"); } else { System.out.println("调用失败"); } System.out.println(response.getBody()); }
响应参数返回示例
{"alipay_trade_fastpay_refund_query_response":{"code":"10000","msg":"Success","out_request_no":"HZ01RF001","out_trade_no":"sao201881610515614516","refund_amount":"3.00","total_amount":"10.00","trade_no":"2019031922001494891000002604"},"sign":"QK8YhF+957fHlMxIVqwmas3ePOlNnOiN8ywjOBToKtxuewg1ocvoDAygIVwciyWc3DUDiO/zCmVyzHA7T7+ok8KB2SzO0kLCoCej8zPJEDc3Ncr4Pio8adz4+1BI4O7fLm5ePAoBON9CpCrnVSsT3Mo/b5PWafVNhkpGV2c1BnM1COEeQDdVDSV3n2GkZYNwNSFEoMag1OhkLMQ78r1fMyhVK4rPBZbsI+p6bUguIp3f+PGTKJHa9DWNrbuWce4cpVbe/QmdDx4v0l0gZ7pF56+VAG8+Cj/r6T4hLJi7yMu05d9aIfH/hWS6V5IuVV6Na2pSxUnAcBrkn54MsY1eJw=="}
3、PHP版请求示例
<?php require_once 'AopSdk.php'; $aop = new AopClient (); $aop->appId = '填写您的appid'; $aop->rsaPrivateKey = '填写您的私钥'; $aop->alipayrsaPublicKey='填写您的支付宝公钥'; $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $aop->apiVersion = '1.0'; $aop->signType = 'RSA2'; $aop->postCharset='utf-8'; $aop->format='json'; $date=date("YmdHis"); $arr=range(1000,9999); shuffle($arr); $request = new AlipayTradeFastpayRefundQueryRequest (); $request->setBizContent("{" . ""out_trade_no":"sao201881610515614516"," . ""out_request_no":"HZ01RF002"" . " }"); $result = $aop->execute($request); //第三方调用 //$result = $aop->execute($request,"","app_auth_token"); echo json_encode($result);
响应参数返回示例
{"alipay_trade_fastpay_refund_query_response":{"code":"10000","msg":"Success","out_request_no":"HZ01RF002","out_trade_no":"sao201881610515614516","refund_amount":"7.00","total_amount":"10.00","trade_no":"2019031922001494891000002604"},"sign":"WsCls80gJFN3oGWXRZxYwoagt9D1myPC3B1AKOvZKDb+uOuXqrT7eQs2UnMKSEgqPnpCXXUdQPxeXWYSrNrvPSGgJGfLy0+cpoootGkAwg3O4QFLvttAEduw0NG1kQQBPbf1VN7PLb6a3cc/JLmghNoS6YpW79ABHdHKCYXD6wQvXpOZUMPA2gpYBt/E+LaIJtx1evCHC+M3+HN0GyaokOG8WHsu5MW3oBD3kmAwEkDXssE+cPneZuqVB824jjIzJkaPmyBb6NRHF9UtELqfov1iFFP4WG4Wy+rDFt6Ys2/UzMAx7aDyNObYaiJvF3riAyyoSUP++0pVdDIk0RGCgg=="}
4、.NET版请求示例
IAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", "RSA2", config.alipay_public_key, config.charset, false); AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); request.BizContent="{" + // ""trade_no":"2019032222001481940568519359"," + ""out_trade_no":"20190321ygyg45447000001"," + ""out_request_no":"20190321ygyg45447000001"" + "}"; AlipayTradeFastpayRefundQueryResponse response = client.Execute(request);
响应参数返回示例
{"alipay_trade_fastpay_refund_query_response":{"code":"10000","msg":"Success","out_request_no":"20190321ygyg45447000001","out_trade_no":"20190321ygyg45447000001","refund_amount":"0.03","total_amount":"0.03","trade_no":"2019032222001481940568519359"},"sign":"i5B/cVIg6IjvbEaR6h1d7tl5wBV9s/RrNb4nV4LpWa1SGIumnHP3BUgjiAUFRL2gyMuEisbjd5SUdCyDiPl9jq9v3rQ+gNIu+jd7Az7+5jARx2wILCXTVN3PCkY0oGs64AwImQGuKvGxxbiCasVELQNZm1y3bUtOmRBuZR3Vmir+nHoJ46MmNb+7IvCOVLK/KJNcUhAikbOzKccEg5lSFk3qFsTBgXWAjOQ9T3iM6IsNqCAJvhIlZzUN9IRoeUWq3nbUnEnQAouL4g2F6Y9NDwhpdP8p5TBTrAYKXbc9gOYDbhBE5RW0+At5CXBCBM/LRkudIzWlBNrs8wOw8ENGug=="}
四、注意事项
1、接口如何判断交易退款成功
该接口返回1000只表示接口调用成功,返回具体详细的退款参数值表示退款成功。
2、接口调用成功,但无详细数据
退款查询接口out_trade_no,trade_no和out_request_no参数值必须设置为退款接口设置信息,若out_trade_no,trade_no相同,out_request_no参数值不同,接口调用成功,但无法查询该笔退款信息,因为无详细退款数据返回。
如果还是报错,请按如下方式进行提问:
正确提问方式:使用环境(沙箱还是正式环境)+接口名称(中文+英文)+ 请求参数 + 报错信息详情