Mt4ManagerApi.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. * 修改mt4用户交易密码
  86. */
  87. public function changePassword($login,$password)
  88. {
  89. $params = array(
  90. 'cmd' => 'userupdate',
  91. 'login' => trim($login),
  92. 'password' => trim($password),
  93. );
  94. $config = Config::findOne(1); //获取到配置文件
  95. $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
  96. $mt4_pay_port = $config['mt4_pay_port']; //获取出入金端口
  97. $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
  98. return $this->_httpRequest($this->url, $params);
  99. }
  100. /*
  101. * 删除mt4订单
  102. */
  103. public function revokeOrder($orders)
  104. {
  105. $params = array(
  106. 'cmd' => 'deleteorders',
  107. 'orders' => trim($orders),
  108. );
  109. $config = Config::findOne(1); //获取到配置文件
  110. $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
  111. $mt4_pay_port = $config['mt4_pay_port'] +1; //获取出入金端口
  112. $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
  113. return $this->_httpRequest($this->url, $params);
  114. }
  115. public function fixbalance($login)
  116. {
  117. $params = array(
  118. 'cmd' => 'balancefix',
  119. 'logins' => trim($login),
  120. );
  121. $config = Config::findOne(1); //获取到配置文件
  122. $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
  123. $mt4_pay_port = $config['mt4_pay_port'] +1; //获取出入金端口
  124. $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
  125. return $this->_httpRequest($this->url, $params);
  126. }
  127. /**
  128. * curl 请求
  129. */
  130. public function _httpRequest($url, $params)
  131. {
  132. $curlPost = http_build_query($params);
  133. $ch = curl_init();//初始化curl
  134. curl_setopt($ch, CURLOPT_URL,$url);
  135. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  136. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  137. curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  138. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  139. $data = curl_exec($ch);//运行curl
  140. curl_close($ch);
  141. return $data;
  142. }
  143. }