|
|
@@ -33,6 +33,7 @@ use Tron\TRX;
|
|
|
class WalletService extends BaseService
|
|
|
{
|
|
|
protected $apiUrl = '';
|
|
|
+ protected $bianUrl = 'https://p2p.binance.com/bapi/c2c/v2/public/c2c/adv/quoted-price';
|
|
|
protected $config = [];
|
|
|
// 静态对象
|
|
|
protected static $instance = null;
|
|
|
@@ -785,6 +786,29 @@ class WalletService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * USDT 币安汇率
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getBianRatePrice()
|
|
|
+ {
|
|
|
+ // 币安买价
|
|
|
+ $cacheKey ="caches:wallet:usdt_rate";
|
|
|
+ $price = RedisService::get($cacheKey);
|
|
|
+ if($price){
|
|
|
+ return $price;
|
|
|
+ }
|
|
|
|
|
|
+ $headers = ["Content-Type: application/json; charset=utf-8"];
|
|
|
+ $result = httpRequest(self::$bianUrl, json_encode(['fromUserRole'=>'USER','assets'=>['USDT'],'fiatCurrency'=>'CNY','tradeType'=>'BUY']), 'post', '',5,$headers);
|
|
|
+ $datas = isset($result['data']) ? $result['data'] : [];
|
|
|
+ $data = isset($datas[0]) ? $datas[0] : [];
|
|
|
+ $price = isset($data['referencePrice']) ? moneyFormat($data['referencePrice'],2) : '0.00';
|
|
|
+ RedisService::set("caches:wallet:usdt_buy_result", ['result' => $result,'rates'=>$price,'data'=>$data], 7200);
|
|
|
+ if($price){
|
|
|
+ RedisService::set($cacheKey, $price, rand(5,10));
|
|
|
+ }
|
|
|
+ return $price>0? $price : 0;
|
|
|
+ }
|
|
|
|
|
|
}
|