MtKit.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. /*
  79. $client = new Client();
  80. $data = [
  81. 'login' => $login,
  82. 'balance' => $balance,
  83. 'comment' => $comment,
  84. ];
  85. // http://192.168.1.100:9090/MtService/withdrawal?login=Int32&balance=Double&comment=String
  86. $response = $client->get(Yii::$app->params['mtHttpServerUrl'] . "/MtService/withdrawal", $data)->send();
  87. if ($response->getIsOk()) {
  88. $content = $response->getContent();
  89. $jsonArr = @json_decode($content, true);
  90. if ($jsonArr['Ret'] == 0) {
  91. return true;
  92. }
  93. }
  94. Yii::warning($response->getContent(), __CLASS__);
  95. */
  96. return false;
  97. }
  98. /**
  99. * 真实账户开户
  100. * @param int $login
  101. * @param string $password
  102. * @param string $passwordInvestor
  103. * @param string $passwordPhone
  104. * @param string $name
  105. * @param int $group
  106. * @param string $email
  107. * @param string $phone
  108. * @param int $leverage
  109. * @param string $country
  110. * @param int $state
  111. * @param string $city
  112. * @param string $address
  113. * @param string $zipCode
  114. * @param int $id
  115. * @param int $agentAccount
  116. * @return bool|int
  117. */
  118. public static function openUser($login, $password, $passwordInvestor, $passwordPhone, $name, $group, $email,
  119. $phone, $leverage, $country, $state, $city, $address, $zipCode, $id, $agentAccount)
  120. {
  121. /*
  122. $data = [
  123. 'LOGIN' => $login,
  124. 'PASSWORD' => $password,
  125. 'INVESTOR' => $passwordInvestor,
  126. 'PHONE_PASSWORD' => $passwordPhone,
  127. 'NAME' => $name,
  128. 'GROUP' => $group,
  129. 'EMAIL' => $email,
  130. 'PHONE' => $phone,
  131. 'LEVERAGE' => $leverage,
  132. 'COUNTRY' => $country,
  133. 'STATE' => $state,
  134. 'CITY' => $city,
  135. 'ADDRESS' => $address,
  136. 'ZIPCODE' => $zipCode,
  137. 'ID' => $id,
  138. 'AGENT_ACCOUNT' => $agentAccount,
  139. ];
  140. $api = new Mt4Api();
  141. $result = $api->addAccount($data, 1);
  142. if ($result['Ret'] == 0) {
  143. return trim($result['Obj']['Login']);
  144. } else {
  145. Yii::warning(json_encode($result), __CLASS__);
  146. }
  147. */
  148. $data = [
  149. 'login' => $login,
  150. 'password' => $password,
  151. 'passwordInvestor' => $passwordInvestor,
  152. 'passwordPhone' => $passwordPhone,
  153. 'name' => $name,
  154. 'group' => $group,
  155. 'email' => $email,
  156. 'phone' => $phone,
  157. 'leverage' => $leverage,
  158. 'country' => $country,
  159. 'state' => $state,
  160. 'city' => $city,
  161. 'address' => $address,
  162. 'zipCode' => $zipCode,
  163. 'id' => $id,
  164. 'agentAccount' => $agentAccount,
  165. ];
  166. $client = new Client();
  167. $response = $client->get(Yii::$app->params['mtHttpServerUrl'] . "/MtService/openUser", $data)->send();
  168. Yii::warning($response->getContent(), __CLASS__);
  169. if ($response->getIsOk()) {
  170. $content = $response->getContent();
  171. $jsonArr = @json_decode($content, true);
  172. if ($jsonArr['Ret'] == 0) {
  173. return trim($jsonArr['Obj']['Login']);
  174. } else {
  175. return 0;
  176. }
  177. }
  178. return false;
  179. }
  180. /**
  181. * 模拟账户开户
  182. * @param null $login
  183. * @param string $password
  184. * @param string $passwordInvestor
  185. * @param string $passwordPhone
  186. * @param string $name
  187. * @param null $group
  188. * @param string $email
  189. * @param string $phone
  190. * @param null $leverage
  191. * @param null $country
  192. * @param null $state
  193. * @param null $city
  194. * @param null $address
  195. * @param null $zipCode
  196. * @param null $id
  197. * @param null $agentAccount
  198. * @return bool|int|string
  199. */
  200. public static function openUserDemo($login = null, $password, $passwordInvestor, $passwordPhone, $name, $group = null,
  201. $email, $phone, $leverage = null, $country = null, $state = null, $city = null,
  202. $address = null, $zipCode = null, $id = null, $agentAccount = null)
  203. {
  204. /*
  205. $data = [
  206. 'PASSWORD' => $password,
  207. 'INVESTOR' => $passwordInvestor,
  208. 'PHONE_PASSWORD' => $passwordPhone,
  209. 'NAME' => $name,
  210. 'EMAIL' => $email,
  211. 'PHONE' => $phone,
  212. ];
  213. $api = new Mt4Api();
  214. $result = $api->addAccount($data, 0);
  215. if ($result['Ret'] == 0) {
  216. return $result['Obj']['Login'];
  217. } else {
  218. Yii::warning(json_encode($result), __CLASS__);
  219. }
  220. */
  221. $data = [
  222. 'password' => $password,
  223. 'investor' => $passwordInvestor,
  224. 'phone_password' => $passwordPhone,
  225. 'username' => $name,
  226. 'email' => $email,
  227. 'phone' => $phone,
  228. ];
  229. $client = new Client();
  230. $response = $client->get("http://live.taikong88.com/index/index/openDemo", $data)->send();
  231. if ($response->getIsOk()) {
  232. $content = $response->getContent();
  233. $jsonArr = @json_decode($content, true);
  234. if ($jsonArr['Ret'] == 0) {
  235. return trim($jsonArr['Obj']['Login']);
  236. } else {
  237. return 0;
  238. }
  239. }
  240. Yii::warning($response->getContent(), __CLASS__);
  241. return false;
  242. }
  243. }