qc.ifish7.com/Application/Admin/Model/ShopOrderModel.class.php

41 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}
}