paystack支付

 public function paystack()
    {  
        $secrct_key ='66464713****khkkkjll';
        $url = "https://api.paystack.co/transaction/initialize";
        $fields = [
            'key'=>"214*******4646464",
            'email' => "test@email.com",
            'amount' => "1000",
            'metadata'=>"1111",
        ];
        $fields_string = http_build_query($fields);
        //open connection
        $key = 'Bearer'.' '.$secrct_key;

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, true);
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Authorization: $key",
            "Cache-Control: no-cache",
        ));

        //So that curl_exec returns the contents of the cURL; rather than echoing it
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //execute post
        $result = curl_exec($ch);
        $result = json_decode($result,true);
        dump($result);
        $url = $result['data']['authorization_url'];

        if($result === false) {
//            echo 'Curl error: ' . curl_error($ch);
            self::showJson(array('status'=>0,'msg'=>curl_error($ch))); exit();
        }else{
            self::showJson(array('status'=>1,'msg'=>'请求成功','data'=>$url)); exit();
//            Header("Location: $url");
        }
    }

    /**
     * 同步回调
     */
    public function back()
    {

        $config = D('Api/Getplugmsg')->plug_config_get(24);
        $secrct_key = $config['plug_config']['24']['secret_key'];
        $key = 'Bearer' . ' ' . $secrct_key;
        $reference = self::$postget['reference'];
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://api.paystack.co/transaction/verify/$reference",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_HTTPHEADER => array(
                "Authorization: $key",
                "Cache-Control: no-cache",
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {

            header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-failure');//支付失败跳转
            exit();
        } else {
            $response = json_decode($response, true);
//            dump($response);die();
            $paymsg_info = M('order_paymsg_record')->where(array('out_trade_no' => $reference))->find();
            if ($response['message'] == 'Verification successful') {
                $paymsg_info['returndata'] = json_encode($response);
                $paymsg_info['status'] = 2;
                $paymsg_info['paymsg'] = $paymsg_info['paytype'];
                $pay = A('Home/Paypalrun')->deal_pay_msg($paymsg_info);

                if ($pay == 12) {
                    header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-success');//支付成功
                } else {
                    header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-failure');//支付失败

                }
            }
        }
    }
    
    //异步回调
    public function webback()
    {
        $file_post=[];
        $file_post['input'] = file_get_contents("php://input");
        $file_post['event'] = json_decode($file_post);
        $file_post['get'] = $_GET;
        $file_post['post'] = $_POST;
        $file_post['myslef'] = self::$postget;
        file_put_contents('./Public/2222.txt',json_encode($file_post),FILE_APPEND);
        dump('222');
        http_response_code(200);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值