【问题标题】:How to get the LENDDO score from REST API in PHP如何从 PHP 中的 REST API 获取 LENDDO 分数
【发布时间】: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.
?>

【问题讨论】:

    标签: php api rest curl


    【解决方案1】:

    我是 Lenddo 的首席开发人员。看来您正在采取艰难的整合路线。感谢 PHP(5.3+),我们实际上提供了一个 SDK,它应该使集成相当轻松。

    您可以在此处找到 PHP SDK:https://github.com/Lenddo/php-lenddo。在此页面上是自述文件,您可以在其中找到目录,更具体地说是installation instructions

    由于您正在尝试检索分数,您可以使用REST Service Client。在此页面上,您将找到有关检索分数的说明。

    为了帮助您快速入门,我将在此处提供一份说明摘要列表(目前的情况):

    1. Install composer
    2. 执行以下命令:composer require lenddo/sdk
    3. 将以下代码 sn-p 粘贴到一个空的 PHP 文件中:
    <?php
    
    // Fill out the ID & Secret provided to you by your contact at Lenddo.
    $id = '';
    $secret = '';
    
    // Require the Composer autoloader
    require 'vendor/autoload.php';
    
    // Instantiate the Lenddo Service Client
    $client = new Lenddo\ServiceClient( $id, $secret );
    
    // Replace the APPLICATION_ID with your client/application ID
    // Replace the PARTNER_SCRIPT_ID with your partner script id
    $response = $client->applicationScore('APPLICATION_ID', 'PARTNER_SCRIPT_ID');
    
    // Get the Status Code for the response
    $status_code = $response->getStatusCode(); // 200
    
    // Retrieve the body of the response
    $score_results = $response->getBody();
    
    // Return the score value and reason flags.
    $score_value = $score_results->score;
    $score_flags = $score_results->flags;
    
    echo $score_value;
    
    1. 按照提供的代码示例的所有内联 cmets。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多