Test.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php namespace Im\Src;
  2. use Dever;
  3. class Test
  4. {
  5. private $host = 'http://39.100.131.66:18080/';
  6. private $key = 'hlhuala1999';
  7. private $uid = 1;
  8. # 注册
  9. public function reg()
  10. {
  11. $param['userId'] = $this->uid;
  12. $param['name'] = 'suwibin';
  13. $param['displayName'] = 'rabin';
  14. $result = $this->result('admin/user/create', $param);
  15. return $result;
  16. }
  17. # 获取token
  18. public function token()
  19. {
  20. $param['userId'] = $this->uid;
  21. $param['clientId'] = $this->uid;
  22. $param['platform'] = 5;
  23. $result = $this->result('admin/user/get_token', $param);
  24. return $result;
  25. }
  26. private function result($uri, $param)
  27. {
  28. $url = $this->host . $uri;
  29. $result = Dever::curl($url, $param, 'post', true, $this->sign());
  30. return $result;
  31. }
  32. private function sign()
  33. {
  34. $option['nonce'] = $this->nonce();
  35. $option['timestamp'] = $this->timestamp();
  36. $option['sign'] = sha1($option['nonce'] . '|' . $this->key . '|' . $option['timestamp']);
  37. return $option;
  38. }
  39. private function nonce()
  40. {
  41. return substr(sha1(microtime()), rand(10, 15));
  42. }
  43. private function timestamp()
  44. {
  45. list($msec, $sec) = explode(' ', microtime());
  46. $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
  47. return $msectime;
  48. }
  49. }