Mt4ManagerApi.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Admin
  5. * Date: 2018/9/3
  6. * Time: 9:34
  7. */
  8. namespace common\lib;
  9. class Mt4ManagerApi
  10. {
  11. /**
  12. * @var string
  13. */
  14. public $url = 'http://43.239.176.170:10002/api';
  15. public $userParams = [
  16. 'group',
  17. 'password',
  18. 'password_investor',
  19. 'name',
  20. 'country',
  21. 'city',
  22. 'state',
  23. 'zipcode',
  24. 'address',
  25. 'lead_source',
  26. 'phone',
  27. 'email',
  28. 'commnet',
  29. 'id',
  30. 'status',
  31. 'regdate',
  32. 'leverage',
  33. 'agent_account',
  34. 'interestrate',
  35. 'taxes',
  36. 'send_reports',
  37. 'enable_read_only',
  38. 'enable'
  39. ];
  40. /**
  41. * 出入金操作
  42. */
  43. public function balance($cmd, $login, $price, $comment='')
  44. {
  45. if (!$cmd || !$login || !$price) {
  46. return false;
  47. }
  48. $params = [
  49. 'cmd' => trim($cmd),
  50. 'login' => trim($login),
  51. 'price' => (int)$price,
  52. 'comment' => $comment
  53. ];
  54. return $this->_httpRequest($this->url, $params);
  55. }
  56. /**
  57. * 更新用户信息
  58. */
  59. public function userUpdate($login, $data)
  60. {
  61. if (!$login || !$data) {
  62. return false;
  63. }
  64. foreach ($data as $key => $val) {
  65. if (!in_array($key, $this->userParams)) {
  66. return false;
  67. }
  68. }
  69. $data['cmd'] = 'userupdate';
  70. $data['login'] = trim($login);
  71. return $this->_httpRequest($this->url, $data);
  72. }
  73. /**
  74. * curl 请求
  75. */
  76. public function _httpRequest($url, $params)
  77. {
  78. $curlPost = http_build_query($params);
  79. $ch = curl_init();//初始化curl
  80. curl_setopt($ch, CURLOPT_URL,$url);
  81. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  82. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  83. curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  84. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  85. $data = curl_exec($ch);//运行curl
  86. curl_close($ch);
  87. return $data;
  88. }
  89. }