HuobiService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/23
  6. */
  7. namespace crmeb\services;
  8. class HuobiService
  9. {
  10. const API_URL = 'https://sapi.ztpay.org/api/v2';//接口地址
  11. private static $app_id = '84cef8cf-ghxertfvbf-13a8a0ca-997b0';
  12. private static $app_secret = '739a0682-163aad52-b6c3ad63-40431';
  13. /**
  14. * 实例化
  15. * @return HuobiService
  16. */
  17. public static function instance()
  18. {
  19. $instance = new self();
  20. $instance::$app_id = sys_config('huobi_Access_Key', '');
  21. $instance::$app_secret = sys_config('huobi_Secret_Key', '');
  22. return $instance;
  23. }
  24. /**
  25. * 获取签名
  26. * @param $data
  27. * @return string
  28. */
  29. private static function getSign($data)
  30. {
  31. $signPars = "";
  32. ksort($data);
  33. foreach ($data as $k => $v) {
  34. if ("sign" != $k && "" != $v && $v != "0") {
  35. $signPars .= $k . "=" . $v . "&";
  36. }
  37. }
  38. $signPars .= "key=" . self::$app_secret;
  39. return strtoupper(md5($signPars));
  40. }
  41. /**
  42. * 通用请求
  43. * @param $data
  44. * @return bool|false|string
  45. */
  46. private static function request($data)
  47. {
  48. $data['sign'] = self::getSign($data);
  49. return json_decode(do_request(self::API_URL, $data), true);
  50. }
  51. }