Skip to content

Commit 799467d

Browse files
committed
little adjustments
1 parent 75628d9 commit 799467d

7 files changed

+226
-60
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# DONATE PAYPAL
1+
# DISCORD
22
```shell
3-
p4yp4l: wilianmaique@gmail.com
3+
wilianmaique
44
```
55

66
# MEXC-API PHP
77
lib mexc api simple, for detail account, balance spot, withdraw
88
info token, etc...
99

10-
# Installation
10+
***Obs: the time on your machine/server must be updated!***
1111

12+
# Installation
1213
```shell
1314
composer require wilianmaique/php-mexc-api-v3
1415
```
1516

1617
# Use
17-
18-
add to your config
18+
add to your config/autoload
1919
```shell
2020
const MEXC_CONFIG = [
2121
'MEXC_URL_API' => 'https://api.mexc.com/api/v3',

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
},
1616
"require": {
1717
"php": ">=8.1"
18+
},
19+
"require-dev": {
20+
"symfony/var-dumper": "^7.0"
1821
}
19-
}
22+
}

composer.lock

+167-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Mexc/Account.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function get(): array|bool
2323
'X-MEXC-APIKEY: ' . MEXC_CONFIG['MEXC_API_ACCESS_KEY'] . ''
2424
],
2525
CURLOPT_RETURNTRANSFER => true,
26-
CURLOPT_SSL_VERIFYPEER => false,
26+
CURLOPT_SSL_VERIFYPEER => true,
2727
]);
2828

2929
$res = curl_exec($ch);
@@ -33,12 +33,8 @@ public static function get(): array|bool
3333
return false;
3434
}
3535

36-
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
3736
curl_close($ch);
3837

39-
if ($status_code != 200)
40-
return json_decode($res, true);
41-
4238
return json_decode($res, true);
4339
}
4440

src/Mexc/InfoToken.php

+43-30
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static function get(string $tokenCoinName = null): array|bool
2626
'X-MEXC-APIKEY: ' . MEXC_CONFIG['MEXC_API_ACCESS_KEY'] . ''
2727
],
2828
CURLOPT_RETURNTRANSFER => true,
29-
CURLOPT_SSL_VERIFYPEER => false,
29+
CURLOPT_SSL_VERIFYPEER => true,
3030
]);
3131

3232
$res = curl_exec($ch);
@@ -40,41 +40,14 @@ public static function get(string $tokenCoinName = null): array|bool
4040
$resJson = json_decode($res, true);
4141
curl_close($ch);
4242

43-
if ($status_code != 200)
44-
return $resJson;
45-
46-
if (empty($tokenCoinName))
43+
if ($status_code != 200 || empty($tokenCoinName))
4744
return $resJson;
4845

4946
$info = [];
5047

5148
foreach ($resJson as $resJsonValue) {
5249
if ($resJsonValue['coin'] === $tokenCoinName) {
53-
$info['coin'] = $tokenCoinName;
54-
$info['name'] = $resJsonValue['name'];
55-
56-
foreach ($resJsonValue['networkList'] as $key => $value) {
57-
$info['networkList'][$key]['coin'] = $value['coin'];
58-
$info['networkList'][$key]['depositDesc'] = $value['depositDesc'];
59-
$info['networkList'][$key]['depositEnable'] = $value['depositEnable'];
60-
$info['networkList'][$key]['minConfirm'] = $value['minConfirm'];
61-
$info['networkList'][$key]['name'] = $value['name'];
62-
$info['networkList'][$key]['network'] = $value['network'];
63-
$info['networkList'][$key]['withdrawEnable'] = $value['withdrawEnable'];
64-
$info['networkList'][$key]['withdrawFee'] = $value['withdrawFee'];
65-
$info['networkList'][$key]['withdrawIntegerMultiple'] = $value['withdrawIntegerMultiple'];
66-
$info['networkList'][$key]['withdrawMax'] = $value['withdrawMax'];
67-
$info['networkList'][$key]['withdrawMin'] = $value['withdrawMin'];
68-
$info['networkList'][$key]['sameAddress'] = $value['sameAddress'];
69-
$info['networkList'][$key]['contract'] = $value['contract'];
70-
$info['networkList'][$key]['withdrawTips'] = $value['withdrawTips'];
71-
$info['networkList'][$key]['depositTips'] = $value['depositTips'];
72-
}
73-
74-
if (count($resJsonValue['networkList']) <= 0)
75-
reset($info['networkList']);
76-
77-
break;
50+
return self::transformInfo($resJsonValue);
7851
}
7952
}
8053

@@ -83,4 +56,44 @@ public static function get(string $tokenCoinName = null): array|bool
8356

8457
return $info;
8558
}
59+
60+
/*
61+
*
62+
* transform array info
63+
*/
64+
private static function transformInfo(array $resJsonValue): array
65+
{
66+
$info = [
67+
'msg' => 'ok',
68+
'coin' => $resJsonValue['coin'],
69+
'name' => $resJsonValue['name'],
70+
'networkList' => [],
71+
];
72+
73+
foreach ($resJsonValue['networkList'] as $value) {
74+
$info['networkList'][] = [
75+
'coin' => $value['coin'],
76+
'depositDesc' => $value['depositDesc'],
77+
'depositEnable' => $value['depositEnable'],
78+
'minConfirm' => $value['minConfirm'],
79+
'name' => $value['name'],
80+
'network' => $value['network'],
81+
'withdrawEnable' => $value['withdrawEnable'],
82+
'withdrawFee' => $value['withdrawFee'],
83+
'withdrawIntegerMultiple' => $value['withdrawIntegerMultiple'],
84+
'withdrawMax' => $value['withdrawMax'],
85+
'withdrawMin' => $value['withdrawMin'],
86+
'sameAddress' => $value['sameAddress'],
87+
'contract' => $value['contract'],
88+
'withdrawTips' => $value['withdrawTips'],
89+
'depositTips' => $value['depositTips'],
90+
];
91+
}
92+
93+
if (count($resJsonValue['networkList']) <= 0) {
94+
reset($info['networkList']);
95+
}
96+
97+
return $info;
98+
}
8699
}

src/Mexc/PriceTicker.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function get(string $symbolToken = null): array|bool
1919
curl_setopt_array($ch, [
2020
CURLOPT_CUSTOMREQUEST => 'GET',
2121
CURLOPT_RETURNTRANSFER => true,
22-
CURLOPT_SSL_VERIFYPEER => false,
22+
CURLOPT_SSL_VERIFYPEER => true,
2323
]);
2424

2525
$res = curl_exec($ch);
@@ -28,16 +28,14 @@ public static function get(string $symbolToken = null): array|bool
2828

2929
$resJson = json_decode($res, true);
3030

31-
if ($status_code != 200)
32-
return $resJson;
33-
34-
if (empty($symbolToken))
31+
if ($status_code != 200 || empty($symbolToken))
3532
return $resJson;
3633

3734
$info = [];
3835

3936
foreach ($resJson as $key => $resJsonValue) {
4037
if ($resJsonValue['symbol'] === $symbolToken) {
38+
$info['msg'] = 'ok';
4139
$info['symbol'] = $resJsonValue['symbol'];
4240
$info['price'] = $resJsonValue['price'];
4341
break;

0 commit comments

Comments
 (0)