Files
qa-ifish7/web/Application/Admin/Model/ShopOrderModel.class.php
2021-03-13 18:42:01 +08:00

41 lines
1.7 KiB
PHP

<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class ShopOrderModel extends \Shop\Model\ShopOrderModel{
//支付宝原路退款
public function alipayRefund($payment){
$detail= json_decode($payment["detail"]);//这里detail字段,保存了当时的交易详情
//
Vendor('AlipaySdk.aop.AopClient');
Vendor('AlipaySdk.aop.SignData');
Vendor('AlipaySdk.aop.request.AlipayTradeRefundRequest');
$aop = new \AopClient();
$config_load=load_config("./Application/Shop/Conf/config.php");//这里因为需要调用shop模块下的config配置文件,所以要用到load_config函数
$config = $config_load["alipay"];
$aop->gatewayUrl = $config['gatewayUrl'];
$aop->appId = $config['app_id'];
$aop->rsaPrivateKey = $config['merchant_private_key'];
$aop->alipayrsaPublicKey=$config['alipay_public_key'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset="UTF-8";
$aop->format='json';
$request = new \AlipayTradeRefundRequest ();
$request->setBizContent(json_encode(array(
"out_trade_no"=>$detail->out_trade_no,
"trade_no"=>$detail->trade_no,
"refund_amount"=>$detail->total_amount,
"refund_reason"=>"正常退款",
)));
$result = $aop->execute ( $request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
return true;
}else {
$this->error = $result->$responseNode->sub_msg;
return false;
}
}
}