| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Admin
- * Date: 2018/9/3
- * Time: 9:34
- */
- namespace common\lib;
- use backend\models\Config;
- class Mt4ManagerApi
- {
- /**
- * @var string
- */
- //public $url = 'http://43.239.176.170:30002/api';
- //public $url = 'http://54.255.235.124:30002/api';
- public $url = "";
- public $userParams = [
- 'group',
- 'password',
- 'password_investor',
- 'name',
- 'country',
- 'city',
- 'state',
- 'zipcode',
- 'address',
- 'lead_source',
- 'phone',
- 'email',
- 'commnet',
- 'id',
- 'status',
- 'regdate',
- 'leverage',
- 'agent_account',
- 'interestrate',
- 'taxes',
- 'send_reports',
- 'enable_read_only',
- 'enable'
- ];
- /**
- * 出入金操作
- */
- public function balance($cmd, $login, $price, $comment='')
- {
- if (!$cmd || !$login || !$price) {
- return false;
- }
- $params = [
- 'cmd' => trim($cmd),
- 'login' => trim($login),
- 'price' => $price,
- 'comment' => $comment
- ];
-
- $config = Config::findOne(1); //获取到配置文件
- $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
- $mt4_pay_port = $config['mt4_pay_port']; //获取出入金端口
- $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
-
- return $this->_httpRequest($this->url, $params);
- }
- /**
- * 更新用户信息
- */
- public function userUpdate($login, $data)
- {
- if (!$login || !$data) {
- return false;
- }
- foreach ($data as $key => $val) {
- if (!in_array($key, $this->userParams)) {
- return false;
- }
- }
- $data['cmd'] = 'userupdate';
- $data['login'] = trim($login);
-
-
- $config = Config::findOne(1); //获取到配置文件
- $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
- $mt4_pay_port = $config['mt4_pay_port']; //获取出入金端口
- $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
-
- return $this->_httpRequest($this->url, $data);
- }
- /**
- * 修改mt4用户交易密码
- */
- public function changePassword($login,$password)
- {
- $params = array(
- 'cmd' => 'userupdate',
- 'login' => trim($login),
- 'password' => trim($password),
- );
- $config = Config::findOne(1); //获取到配置文件
- $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
- $mt4_pay_port = $config['mt4_pay_port']; //获取出入金端口
- $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
- return $this->_httpRequest($this->url, $params);
- }
- /*
- * 删除mt4订单
- */
- public function revokeOrder($orders)
- {
- $params = array(
- 'cmd' => 'deleteorders',
- 'orders' => trim($orders),
- );
- $config = Config::findOne(1); //获取到配置文件
- $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
- $mt4_pay_port = $config['mt4_pay_port'] +1; //获取出入金端口
- $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
- return $this->_httpRequest($this->url, $params);
- }
- public function fixbalance($login)
- {
- $params = array(
- 'cmd' => 'balancefix',
- 'logins' => trim($login),
- );
- $config = Config::findOne(1); //获取到配置文件
- $mt4_pay_ip = $config['mt4_pay_ip']; //获取mt4出入金ip
- $mt4_pay_port = $config['mt4_pay_port'] +1; //获取出入金端口
- $this->url = "http://{$mt4_pay_ip}:{$mt4_pay_port}/api";
- return $this->_httpRequest($this->url, $params);
- }
- /**
- * curl 请求
- */
- public function _httpRequest($url, $params)
- {
- $curlPost = http_build_query($params);
- $ch = curl_init();//初始化curl
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
- curl_setopt($ch, CURLOPT_TIMEOUT, 15);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
- $data = curl_exec($ch);//运行curl
- curl_close($ch);
- return $data;
- }
- }
|