【发布时间】:2016-04-19 09:30:22
【问题描述】:
如何在 PHP 中从 REST API 获取 LENDDO 分数
我的客户 ID = LEDEMO1070168781157742500
对于上面的 client_id,我的 Lenddo 分数是 480,它显示在我的 Lenddo 仪表板上,但没有通过 API 获得这个分数。
不共享我的 API 和密钥。
基本上我需要帮助来生成我在 signRequest() 函数中执行的 AUTHORIZATION HEADER。
参考=https://www.lenddo.com/documentation/rest_api.html
/*
<?php
$method = "GET";
$date = date("D M j G:i:s T Y");
$url = '/ClientScore/LEDEMO1070168781157742500';
function signRequest($method, $body, $date, $url) {
$api = ''; //my api key
$secret = ''; // my secret key
$contentMd5 = NULL;
if( !empty( $body ) ) {
$contentMd5 = md5( $body );
}
$stringToSign = $method . "\n" . $contentMd5 . "\n" . $date . "\n" . $url;
$string = "LENDDO " . $api . ":";
$string .= base64_encode(
hash_hmac( "sha1", $stringToSign, $secret, TRUE )
);
return $string;
}
$val = signRequest('GET', '', $date, $url); // get the access token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://scoreservice.lenddo.com/ClientScore/LEDEMO1070168781157742500");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
$headers = array('Authorization: Bearer ' . $val);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
// the above source code gives me the output => string(141) "{"message": "Signature generated from request data does not match the signature provided in the Authorization Header.", "name": "FORBIDDEN"} "
// i pass my api and secret key into the code above but got this error, help me to find Lenddo Score.
?>
【问题讨论】: