版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1446304
多少提一下:毕竟我的前提操作是 App支付快速接入,虽然理论上不会影响
> ThinkPHP 框架: ThinkPHP5.1.2
> PHP 版本: php-5.6.32(>= 及以上)
> 服务器 : Nginx
> 线上系统: CentOS7.1
namespace
空间,以保证顺利访问 /**
* 统一收单交易退款接口
* @param string $out_trade_no 订单支付时传入的商户订单号
* @param string $refund_fee 需要退款的金额
* @return array
*/
public function payRefundAli($out_trade_no = "", $refund_fee = "0.00")
{
$aop = new AopClient ();
$aop->gatewayUrl = $this->gatewayUrl;
$aop->appId = $this->appID;
$aop->rsaPrivateKey = $this->rsaPrivateKey;
$aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new AlipayTradeRefundRequest ();
//TODO 方便多次退款的设置
$out_request_no = $out_trade_no.rand(1000,9999);
$request->setBizContent("{" .
//订单支付时传入的商户订单号,不能和 trade_no同时为空。
"\"out_trade_no\":\"$out_trade_no\"," .
//支付宝交易号,和商户订单号不能同时为空
//"\"trade_no\":\"2019060622001445431042039169\"," .
//需要退款的金额,该金额不能大于订单金额,单位为元,支持两位小数 c
"\"refund_amount\":$refund_fee," .
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
"\"out_request_no\":\"$out_request_no\"" .
" }");
$result = $aop->execute($request);
//var_dump($result);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
$status = 1;
$message = "退款成功";
} else {
$status = 0;
$message = $result->alipay_trade_refund_response->sub_msg;
}
//echo $message;
return showMsg($status,$message); //这是我自己的封装方法,可忽略...
}
appID、rsaPrivateKey、alipayrsaPublicKey
等请求参数的集合 biz_content
的参数补充,切记最后一个参数后面 不要有 逗号!!!
40004: ACQ.INVALID_PARAMETER "参数无效"
out_request_no
参数,不然会提示:
ACQ.REFUND_AMT_NOT_EQUAL_TOTAL “撤销或退款金额与订单金额不一致”