Mt4ManagerApi.php 2.9 KB

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