首页 > 解决方案 > 在 BlueSnap 支付网关中如何创建托管支付字段令牌请求

问题描述

curl -v -X POST https://ws.bluesnap.com/services/2/payment-fields-tokens \ 
-H 'Content-Type: application/json' \ 
-H 'Accept: application/json' \  
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \ 
-d '

在 php 中如何在 curl 发布和显示位置 url 中描述上述代码。

标签: phpjqueryajaxcurl

解决方案


$api_usernam  = bluesnap::$username ;
$api_password = bluesnap::$password ;
$auth_token   = base64_encode(  $api_usernam . ':' . $api_password );
        $header = array("Authorization: Basic ".$auth_token."", "Content-type: application/json");
        $url = "https://sandbox.bluesnap.com/services/2/payment-fields-tokens"; //change the URL on production

        //start request
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

         $resp = curl_exec($ch);

         curl_close($ch);

             list($Headers, $Response)=explode("\r\n\r\n",$resp, 2);
            $Headers=explode("\n", $Headers);
            foreach($Headers as $Header)
            {
            if (stripos($Header, "Location")!==false)
            {
            $Token=trim(str_replace("Location: ", "", $Header));
            }
            }

            $Token = substr(strrchr( $Token, '/' ),1);

        // test if secuss

         return $Token;

    }

推荐阅读