<?php
namespace wechatpay;
class WechatRefund extends WechatPay
{
// protected $SSLCERT_PATH = '/cert/apiclient_cert.pem';//证书路径
//
// protected $SSLKEY_PATH = '/cert/apiclient_key.pem';//证书路径
protected $outRefundNo; //商户退款单号
protected $outTradeNo; //商户订单号(退款时:商户订单号和微信流水号二选一,32位)
protected $transaction_id; //微信流水号(退款时:商户订单号和微信流水号二选一,32位)
protected $refundFee; //退款金额
protected $apiclient_key;
protected $apiclient_cert;
public function __construct($openid, $transaction_id, $outRefundNo, $totalFee, $refundFee)
{
$this->openid = $openid;
$this->transaction_id = $transaction_id;
$this->outRefundNo = $outRefundNo;
$this->totalFee = $totalFee;
$this->refundFee = $refundFee;
$this->apiclient_cert = ROOT_PATH . 'public' . DS . $this->SSLCERT_PATH;
$this->apiclient_key = ROOT_PATH . 'public' . DS . $this->SSLKEY_PATH;
}
public function refund()
{
echo $this->apiclient_key;die;
//对外暴露的退款接口
$result = $this->wxrefundapi();
return $result;
}
public function wxrefundapi()
{
//通过微信api进行退款流程
$parma = array(
'appid' => $this->APPID,
'mch_id' => $this->MCHID,
'nonce_str' => $this->createNoncestr(),
'out_refund_no' => $this->outRefundNo,
// 'out_trade_no' => $this->outTradeNo,
'transaction_id' => $this->transaction_id,
'total_fee' => $this->totalFee,
'refund_fee' => $this->refundFee,
);
$parma['sign'] = $this->getSign($parma);
$xmldata = $this->arrayToXml($parma);
$xmlresult = $this->postData('https://api.mch.weixin.qq.com/secapi/pay/refund',$xmldata);
$result = $this->xmlToArray($xmlresult);
return $result;
}
//发送数据
protected function postData($url,$xml,$second = 30)
{
$ch = curl_init();
//超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//设置证书
//使用证书:cert 与 key 分别属于两个.pem文件
//默认格式为PEM,可以注释
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, $this->apiclient_cert);
//默认格式为PEM,可以注释
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEY, $this->apiclient_key);
//post提交方式
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$data = curl_exec($ch);
//返回结果
if ($data) {
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
echo "curl出错,错误码:$error" . "<br>";
curl_close($ch);
return false;
}
}
}
微信退款
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一、 微信退款结果回调通知URL作用 客户在微信里购买产品后,有可能因为某种原因,客户会要求退款,当你设置了退款结...
- 金额的格式限制 微信支付、微信退款的金额的限制(下文仅仅说微信支付),以前只知道,微信的支付金额的是按照分为单位的...