public function refundPay($data){
$url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
$nonce_str = str_random(32);
try {
$dataSign = [
'appid' => $this->appid,
'mch_id' => $this->mch_id,
'nonce_str' => $nonce_str,
'transaction_id' => $data['payment_id'],
'out_trade_no' => $data['order_sn'],
'out_refund_no' => $data['order_refund_sn'],
'total_fee' => $data['price'],
'refund_fee' => $data['price']
];
$sign = $this->getSign($dataSign);
$dataSign['sign'] = $sign;
$dataXml = $this->array2Xml($dataSign);
$result = $this->request_post($dataXml, $url,1);
return $this->xml2Array($result);
}catch (\Exception $e){
Log::info($e);
return false;
}
}
function request_post($data, $url, $is_pem=0){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if($is_pem == 1){
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT,'../key/wxpay/apiclient_cert.pem');
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY,'../key/wxpay/apiclient_key.pem');
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}