<?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;
}
}
}
微信退款
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 一、 微信退款结果回调通知URL作用 客户在微信里购买产品后,有可能因为某种原因,客户会要求退款,当你设置了退款结...
- 金额的格式限制 微信支付、微信退款的金额的限制(下文仅仅说微信支付),以前只知道,微信的支付金额的是按照分为单位的...