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×tamp=$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×tamp=$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 |1 Answer
Reset to default 0Unfortunately 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
版权声明:本文标题:php - Get all coins information from lBank api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304483a1932251.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$parameters = "api_key=" . "&echostr=
- are you actually using an emptyapi_key
value at this point? – C3roe Commented Nov 22, 2024 at 10:50