Php 设置plimusapi以获取身份验证令牌

Php 设置plimusapi以获取身份验证令牌,php,xml,curl,libcurl,bluesnap,Php,Xml,Curl,Libcurl,Bluesnap,我需要设置plimus API以获取身份验证令牌,然后使用它将客户登录到plimus平台 我使用以下代码: $URL = "https://sandbox.plimus.com/services/2/tools/auth-token?shopperId=$shopperId&expirationInMinutes=$expiration"; // use base64 to encode the credentials $authorization = base64_encod

我需要设置plimus API以获取身份验证令牌,然后使用它将客户登录到plimus平台

我使用以下代码:

    $URL = "https://sandbox.plimus.com/services/2/tools/auth-token?shopperId=$shopperId&expirationInMinutes=$expiration";

// use base64 to encode the credentials
$authorization = base64_encode($username.':'.$password); 

$ch = curl_init();
// set URL
curl_setopt_array($ch, array(CURLOPT_URL => $URL));
// set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic $authorization", "Content-type: application/xml")); // This line is mandatory for every API call!
// set  HTTP request to GET
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // This service (get token) is implement via RESTful GET, other services might use POST and PUT
// stop output of curl_exec to standard output (don't send output to screen)
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// make HTTP call and read the response into an XML object

$xml = new SimpleXMLElement(curl_exec($ch));

// -------- PART II - Log the customer into Plimus (according to $target) --------

// construct plimus URL
$plimus = "https://sandbox.plimus.com/jsp/entrance.jsp?contractId=$contractId&target=$target&token={$xml->token}";
// redirect
header("Location: $plimus");
我得到以下错误,不知道原因:

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as
XML' in xxx\get_token.php:40 Stack trace: #0 xxx\get_token.php(40): 
SimpleXMLElement->__construct('') #1 {main} thrown in xxx\get_token.php on line 40

谢谢

看起来这是我的代码,摘自文章的第二部分:
:)


使用
var\u dump(curl\u exec($ch))
查看您从服务器得到的确切响应

@user2186504那么,
var_dump(curl_exec($ch))
的输出是什么呢?正如您已经看到的,完全相同的脚本对我来说很好:所以我猜您传递的一个参数(shopperId/construcd/etc)或您的凭据有问题。Firefox有一个很棒的插件叫做Poster,它是调试HTTP调用的好工具!