admin管理员组

文章数量:1122832

i Try interact with LBank Api with Php

According to the instructions at .html#introduction I tried to write the PHP code as follows:

my code :

$num = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_string = generateRandomString($num, 35);
$secret_Key = "A58E2F2E2DE40100274A635859913169";


try {
    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ".do");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 0);
$response = curl_exec($ch);

curl_close($ch);
$ch1 = curl_init();
$response_ts = json_decode($response, true); // true برای تبدیل به آرایه انجمنی
$timestamp = $response_ts['data'];
// حالا $jsonData یک آرایه انجمنی است که می‌توانید با آن کار کنید
// echo $timestamp; // برای دسترسی به مقدار کلید 'name'
$parameters = "api_key=33ecc239-c375-4f9a-ac0c-3f0eb0a35101" . "&echostr=3d47056c3d47056c0bf0429c81afc8c3de7b0f90bf04&signature_method=HmacSHA256&timestamp=$timestamp";
$md5_hash = strtoupper(md5($parameters));
$signature = hash_hmac('sha256', $md5_hash, $secret_Key);
$base64_signature = base64_encode($signature);
echo $signature;
echo "<br>";
echo $base64_signature;
echo "<br>";

curl_setopt($ch1, CURLOPT_URL, ".do");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_POST, 1);
$headers = array(
    "echostr: $random_string",
    "timestamp: $timestamp",
    'signature_method: HmacSHA256',
    "contentType:'application/x-www-form-urlencoded'",
   
    
);
curl_setopt($ch1,CURLOPT_HTTPHEADER,$headers);

$post_data = array(
    'api_key' => '33ecc239-c375-4f9a-ac0c-3f0eb0a35101',
    'echostr' => $random_string,
    'sign' => "$base64_signature",
    'signature_method'=> 'HmacSHA256',
    'timestamp'=> $timestamp,
    'contentType'=> 'application/x-www-form-urlencoded',   
);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($ch1);
curl_close($ch1);
echo $response;

    // کدی که ممکن است خطا ایجاد کند
} catch (Exception $e) {
    // مدیریت خطا
    echo 'خطایی رخ داده است: ' . $e->getMessae();
}

But i Get {"result":"false","msg":"Invalid signature","error_code":10007,"ts":1732090561500} response :(

I do that's code with lbank documentation in .html#system-status

i Try interact with LBank Api with Php

According to the instructions at https://www.lbank.com/docs/index.html#introduction I tried to write the PHP code as follows:

my code :

$num = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_string = generateRandomString($num, 35);
$secret_Key = "A58E2F2E2DE40100274A635859913169";


try {
    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.lbkex.net/v2/timestamp.do");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 0);
$response = curl_exec($ch);

curl_close($ch);
$ch1 = curl_init();
$response_ts = json_decode($response, true); // true برای تبدیل به آرایه انجمنی
$timestamp = $response_ts['data'];
// حالا $jsonData یک آرایه انجمنی است که می‌توانید با آن کار کنید
// echo $timestamp; // برای دسترسی به مقدار کلید 'name'
$parameters = "api_key=33ecc239-c375-4f9a-ac0c-3f0eb0a35101" . "&echostr=3d47056c3d47056c0bf0429c81afc8c3de7b0f90bf04&signature_method=HmacSHA256&timestamp=$timestamp";
$md5_hash = strtoupper(md5($parameters));
$signature = hash_hmac('sha256', $md5_hash, $secret_Key);
$base64_signature = base64_encode($signature);
echo $signature;
echo "<br>";
echo $base64_signature;
echo "<br>";

curl_setopt($ch1, CURLOPT_URL, "https://www.lbkex.net/v2/supplement/user_info.do");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_POST, 1);
$headers = array(
    "echostr: $random_string",
    "timestamp: $timestamp",
    'signature_method: HmacSHA256',
    "contentType:'application/x-www-form-urlencoded'",
   
    
);
curl_setopt($ch1,CURLOPT_HTTPHEADER,$headers);

$post_data = array(
    'api_key' => '33ecc239-c375-4f9a-ac0c-3f0eb0a35101',
    'echostr' => $random_string,
    'sign' => "$base64_signature",
    'signature_method'=> 'HmacSHA256',
    'timestamp'=> $timestamp,
    'contentType'=> 'application/x-www-form-urlencoded',   
);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($ch1);
curl_close($ch1);
echo $response;

    // کدی که ممکن است خطا ایجاد کند
} catch (Exception $e) {
    // مدیریت خطا
    echo 'خطایی رخ داده است: ' . $e->getMessae();
}

But i Get {"result":"false","msg":"Invalid signature","error_code":10007,"ts":1732090561500} response :(

I do that's code with lbank documentation in https://www.lbank.com/docs/index.html#system-status

Share Improve this question edited Nov 25, 2024 at 4:29 Eng.Ali karimifard asked Nov 22, 2024 at 10:37 Eng.Ali karimifardEng.Ali karimifard 292 bronze badges 4
  • $parameters = "api_key=" . "&echostr= - are you actually using an empty api_key value at this point? – C3roe Commented Nov 22, 2024 at 10:50
  • @C3roe no for security I empty in here in my computer that is fill – Eng.Ali karimifard Commented Nov 22, 2024 at 15:01
  • You have no opinion :(( – Eng.Ali karimifard Commented Nov 24, 2024 at 5:15
  • @C3roe i edit this post and insert api key and api secret you can check it – Eng.Ali karimifard Commented Nov 25, 2024 at 4:31
Add a comment  | 

1 Answer 1

Reset to default 0

Unfortunately Lbank doesn't any api help for PHP, but you can check this:

urls' => array (
                'logo' => 'https://user-images.githubusercontent.com/1294454/38063602-9605e28a-3302-11e8-81be-64b1e53c4cfb.jpg',
                'api' => 'https://api.lbank.info',
                'www' => 'https://www.lbank.info',
                'doc' => 'https://github.com/LBank-exchange/lbank-official-api-docs',
                'fees' => 'https://lbankinfo.zendesk.com/hc/zh-cn/articles/115002295114--%E8%B4%B9%E7%8E%87%E8%AF%B4%E6%98%8E',
            ),

本文标签: phpGet all coins information from lBank apiStack Overflow