MtKit.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace common\helpers;
  3. use common\lib\Mt4Api;
  4. use common\lib\Mt4Deposit;
  5. use Yii;
  6. use yii\httpclient\Client;
  7. class MtKit
  8. {
  9. /**
  10. * 获取MT4分组
  11. * @return array
  12. */
  13. public static function getGroups()
  14. {
  15. $result = [];
  16. $client = new Client();
  17. // http://192.168.1.100:9090/MtService/getGroups
  18. $response = $client->get(Yii::$app->params['mtHttpServerUrl'] . "/MtService/getGroups")->send();
  19. if ($response->getIsOk()) {
  20. $content = $response->getContent();
  21. $jsonArr = @json_decode($content, true);
  22. foreach ((array)$jsonArr as $key => $row) {
  23. $result[] = isset($row['Name']) ? trim($row['Name']) : '';
  24. }
  25. } else {
  26. Yii::warning($response->getContent(), __CLASS__);
  27. }
  28. return $result;
  29. }
  30. /**
  31. * 入金
  32. * @param int $login
  33. * @param float $balance
  34. * @param string $comment
  35. * @return bool
  36. */
  37. public static function deposit($login, $balance, $comment)
  38. {
  39. $mt4 = new Mt4Deposit();
  40. $result = $mt4->deposit($login, $balance, $comment);
  41. if ($result['errCode'] == 0) {
  42. return true;
  43. }
  44. /*
  45. $client = new Client();
  46. $data = [
  47. 'login' => $login,
  48. 'balance' => $balance,
  49. 'comment' => $comment,
  50. ];
  51. // http://192.168.1.100:9090/MtService/deposit?login=Int32&balance=Double&comment=String
  52. $response = $client->get(Yii::$app->params['mtHttpServerUrl'] . "/MtService/deposit", $data)->send();
  53. if ($response->getIsOk()) {
  54. $content = $response->getContent();
  55. $jsonArr = @json_decode($content, true);
  56. if ($jsonArr['Ret'] == 0) {
  57. return true;
  58. }
  59. }
  60. Yii::warning($response->getContent(), __CLASS__);
  61. */
  62. return false;
  63. }
  64. /**
  65. * 出金
  66. * @param int $login
  67. * @param float $balance
  68. * @param string $comment
  69. * @return bool
  70. */
  71. public static function withdrawal($login, $balance, $comment)
  72. {
  73. $mt4 = new Mt4Deposit();
  74. $result = $mt4->withdraw($login, $balance, $comment);
  75. if ($result['errCode'] == 0) {
  76. return true;
  77. }
  78. return false;
  79. }
  80. /**
  81. * 真实账户开户
  82. * @param int $login
  83. * @param string $password
  84. * @param string $passwordInvestor
  85. * @param string $passwordPhone
  86. * @param string $name
  87. * @param int $group
  88. * @param string $email
  89. * @param string $phone
  90. * @param int $leverage
  91. * @param string $country
  92. * @param int $state
  93. * @param string $city
  94. * @param string $address
  95. * @param string $zipCode
  96. * @param int $id
  97. * @param int $agentAccount
  98. * @return bool|int
  99. */
  100. public static function openUser($realip, $port, $login, $password, $passwordInvestor, $passwordPhone, $name, $group, $email,
  101. $phone, $leverage, $country, $state, $city, $address, $zipCode, $id, $agentAccount)
  102. {
  103. $data = [
  104. 'LOGIN' => $login,
  105. 'PASSWORD' => $password,
  106. 'INVESTOR' => $passwordInvestor,
  107. 'PHONE_PASSWORD' => $passwordPhone,
  108. 'NAME' => $name,
  109. 'GROUP' => $group,
  110. 'EMAIL' => $email,
  111. 'PHONE' => $phone,
  112. 'LEVERAGE' => $leverage,
  113. 'COUNTRY' => $country,
  114. 'STATE' => $state,
  115. 'CITY' => $city,
  116. 'ADDRESS' => $address,
  117. 'ZIPCODE' => $zipCode,
  118. 'ID' => $id,
  119. 'AGENT_ACCOUNT' => $agentAccount,
  120. ];
  121. $api = new Mt4Api($realip, $port);
  122. $result = $api->addAccount($data, 1);
  123. if ($result['Ret'] == 0) {
  124. return trim($result['Obj']['Login']);
  125. } else {
  126. Yii::warning(json_encode($result), __CLASS__);
  127. }
  128. return false;
  129. }
  130. /**
  131. * 模拟账户开户
  132. * @param null $login
  133. * @param string $password
  134. * @param string $passwordInvestor
  135. * @param string $passwordPhone
  136. * @param string $name
  137. * @param null $group
  138. * @param string $email
  139. * @param string $phone
  140. * @param null $leverage
  141. * @param null $country
  142. * @param null $state
  143. * @param null $city
  144. * @param null $address
  145. * @param null $zipCode
  146. * @param null $id
  147. * @param null $agentAccount
  148. * @return bool|int|string
  149. */
  150. public static function openUserDemo($realip, $port,$login = null, $password, $passwordInvestor, $passwordPhone, $name, $group = null,
  151. $email, $phone, $leverage = null, $country = null, $state = null, $city = null,
  152. $address = null, $zipCode = null, $id = null, $agentAccount = null)
  153. {
  154. $data = [
  155. 'PASSWORD' => $password,
  156. 'INVESTOR' => $passwordInvestor,
  157. 'PHONE_PASSWORD' => $passwordPhone,
  158. 'NAME' => $name,
  159. 'EMAIL' => $email,
  160. 'PHONE' => $phone,
  161. ];
  162. $api = new Mt4Api($realip, $port);
  163. $result = $api->addAccount($data, 0);
  164. if ($result['Ret'] == 0) {
  165. return $result['Obj']['Login'];
  166. } else {
  167. Yii::warning(json_encode($result), __CLASS__);
  168. }
  169. return false;
  170. }
  171. }