|
@@ -45,7 +45,25 @@ class WxPay extends Controller
|
|
|
//将微信返回的结果xml转成数组
|
|
|
return $this->xmltoarray($response);
|
|
|
}
|
|
|
+ public function wxrefund($out_trade_no,$out_refund_no,$total_fee,$refund_fee)
|
|
|
+ {
|
|
|
+ $param = array(
|
|
|
+ 'appid'=> $this->config["appid"],
|
|
|
+ 'mch_id'=> $this->config['mch_id'],
|
|
|
+ 'nonce_str'=> $this->getRandChar(32),
|
|
|
+ 'out_trade_no'=>$out_trade_no,
|
|
|
+ 'out_refund_no'=>$out_refund_no,//订单号
|
|
|
+ // 'transaction_id'=> $transactionId,//微信订单号
|
|
|
+ 'total_fee'=> $total_fee,
|
|
|
+ 'refund_fee'=>$refund_fee
|
|
|
+ );
|
|
|
|
|
|
+ $param['sign'] = $this->getSign($param, false);
|
|
|
+ $xmldata = $this->arrayToXml($param);
|
|
|
+ $xmlresult = $this->postXmlSSLCurl($xmldata,'https://api.mch.weixin.qq.com/secapi/pay/refund');
|
|
|
+ $result = $this->xmlToArray($xmlresult);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
//小程序*退款
|
|
|
public function getOrder($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$notify_url){
|
|
|
$url = 'https://api.mch.weixin.qq.com/secapi/pay/refund';
|
|
@@ -151,7 +169,7 @@ class WxPay extends Controller
|
|
|
}
|
|
|
}
|
|
|
//需要使用证书的请求 * 退款
|
|
|
- function postXmlSSLCurl($xml,$url,$second=30)
|
|
|
+ private function postXmlSSLCurl($xml,$url,$second=30)
|
|
|
{
|
|
|
$ch = curl_init();
|
|
|
//超时时间
|
|
@@ -170,10 +188,10 @@ class WxPay extends Controller
|
|
|
//使用证书:cert 与 key 分别属于两个.pem文件
|
|
|
//默认格式为PEM,可以注释
|
|
|
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
|
|
|
- curl_setopt($ch,CURLOPT_SSLCERT, $this->SSLCERT_PATH);
|
|
|
+ curl_setopt($ch,CURLOPT_SSLCERT, dirname(__DIR__).'/wxcert/apiclient_cert.pem');
|
|
|
//默认格式为PEM,可以注释
|
|
|
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
|
|
|
- curl_setopt($ch,CURLOPT_SSLKEY, $this->SSLKEY_PATH);
|
|
|
+ curl_setopt($ch,CURLOPT_SSLKEY,dirname(__DIR__).'/wxcert/apiclient_key.pem');
|
|
|
//post提交方式
|
|
|
curl_setopt($ch,CURLOPT_POST, true);
|
|
|
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
|