php 微信退款证书

function request_post($data, $url, $is_pem=0){
        $ch = curl_init();
        //指定URL
        curl_setopt($ch, CURLOPT_URL, $url);
        //设定请求后返回结果
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //声明使用POST方式来进行发送
        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'); //sslCertType
            curl_setopt($ch,CURLOPT_SSLCERT,'../key/wxpay/apiclient_cert.pem');//证书路径
            curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');  //sslKeyType
            curl_setopt($ch,CURLOPT_SSLKEY,'../key/wxpay/apiclient_key.pem');//证书路径
        }
        //忽略header头信息
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //设置超时时间
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        //发送请求
        $output = curl_exec($ch);
        //关闭curl
        curl_close($ch);
        //返回数据
        return $output;
    }

其中

退款方法

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值