Mt4ManagerApi.php 2.2 KB

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