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

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/124340861