2

認証トークンをフェッチし、それを使用して顧客を Plimus プラットフォームにログインさせるために、plimus API をセットアップする必要があります。

私は次のコードを使用しています:

    $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

記事の第2部から取られた私のコードのようです:APIを使用してカスタマーエクスペリエンスとコンバージョンを改善する方法
:)

var_dump(curl_exec($ch))サーバーから得ている正確な応答を使用して確認してください!

于 2013-04-19T14:20:24.680 に答える