2

我需要设置 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

谢谢

4

1 回答 1

1

看起来这是我的代码,取自文章的第二部分:如何使用 API 改善客户体验和转换
:)

使用var_dump(curl_exec($ch))并查看您从服务器获得的确切响应!

于 2013-04-19T14:20:24.680 回答