payssion支付

 public function payssion()
    {
        $url = "http://sandbox.payssion.com/api/v1/payment/create";//沙箱测试
        $msg = implode('|', array('sandbox_184d7001e5ce33a5', 'payssion_test', '1.00', 'USD', '123456789', '08QV4C8m5tTbGPWiJf5lFhklCg22dpze'));
        $api_sig = md5($msg);
        $fields = [
            'api_key'=>"sandbox_184d7001e5ce33a5",
            'api_sig' => $api_sig,
            'pm_id' => "payssion_test",
            'amount'=>"1.00",
            'currency'=>"USD",
            'order_id'=>"123456789",
            'description'=>"Charge for test"
        ];
        $fields_string = http_build_query($fields);

        $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(
            "Cache-Control: no-cache",
        ));
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //execute post
        $result = curl_exec($ch);
        $err = curl_error($ch);

        $result = json_decode($result,true);
dump($result);die();
    }

    /**
     * 异步回调
     */
    public function notify_back()
    {
 
        $file_post['input'] = file_get_contents("php://input");
        file_put_contents('1.txt','1111');
      dump($file_post);  die();

        $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) {
//            echo "cURL Error #:" . $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');//支付失败
//                   self::showJson(array('status'=>0,'msg'=>'支付失败')); exit();
                }
            }
        }
    }

    /**
     * 同步回调
     */
    public function return_back()
    {
        $configmsg_all=D("Api/Getplugmsg")->plug_config_get(25);
        if($configmsg_all['plug_config']['25']['payssion'] !=1){
            return false;
        }
        $api_key = $configmsg_all['plug_config']['25']['api_key'];
        $secret_key = $configmsg_all['plug_config']['25']['secret_key'];
        $transacion_id = self::$postget['transaction_id'];
        $order_id = self::$postget['order_id'];

        $url = "http://sandbox.payssion.com/api/v1/payment/details";//沙箱测试
        $msg = implode('|', array($api_key, $transacion_id, $order_id,$secret_key));
        $api_sig = md5($msg);
        $fields = [
            'api_key'=> $api_key,
            'api_sig' => $api_sig,
            'transaction_id' => $transacion_id,
            'order_id'=>$order_id,
        ];

        $fields_string = http_build_query($fields);
        $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(
            "Cache-Control: no-cache",
        ));
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //execute post
        $response = curl_exec($ch);

        $err = curl_error($ch);
        if ($err) {
            header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-failure');//支付失败跳转
            exit();
        } else {
            $response = json_decode($response, true);
            $paymsg_info = M('order_paymsg_record')->where(array('out_trade_no' => $transacion_id))->find();
            if ($response['result_code'] == '200') {
                $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');//支付失败

                }
            }
        }

    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值