Index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. *------Create thems Controller------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-23 15:06:45------
  7. */
  8. namespace App\InApi\Controller;
  9. use BaseController\Controller;
  10. use Biz\Game\GameLogic;
  11. use App\Commons\Model\Wagent;
  12. class Index extends Controller
  13. {
  14. //用户上传参数数组;
  15. private $paras = [];
  16. private $parasString = '';
  17. private $userKey = '';
  18. private $model = null;
  19. private $logic = null;
  20. //默认返回数据格式
  21. private $defformat = 'json';
  22. //所有请求入口
  23. public function dobusiness()
  24. {
  25. $this->doLogic();
  26. }
  27. public function getdata()
  28. {
  29. $this->doLogic();
  30. }
  31. private function doLogic()
  32. {
  33. $this->ParasCheck();
  34. $this->AgentKeyCheck();
  35. $method = $this->ActionMap()[$this->paras['method']];
  36. $this->logic = new GameLogic($this->paras, $this->userKey, $this->model);
  37. if ((new \ReflectionClass($this->logic))->hasMethod($method)) {
  38. $ret = $this->logic->$method();
  39. Render($ret['datas'], $ret['status'], $ret['msg']);
  40. }
  41. Render('', 10009, lang('Errors', 'Sports')->get('error-10009'));
  42. }
  43. private function ActionMap()
  44. {
  45. $maps = [
  46. 'caie' => 'CheckAccountIsExist',
  47. 'caca' => 'CheckAndCreateAccount',
  48. 'gb' => 'GetBalance',
  49. 'ptc' => 'TransferCredit',
  50. 'ctc' => 'ConfirmTransferCredit',
  51. 'tg' => 'TransferGame',
  52. 'gr' => 'GetReport',
  53. 'gct' => 'GetCashTrade',
  54. 'gbrbv' => 'GetBettingRecordByVendor',
  55. 'gsbrbv' => 'GetSportsBettingRecordByVendor',
  56. 'gebrbv' => 'GetEleBettingRecord',
  57. 'gfbrbv' => 'GetFishBettingRecord',
  58. 'glbrbv' => 'GetLotteryBettingRecord',
  59. 'ggr' => 'GetGameResult',
  60. 'ua' => 'UpdateAccount',
  61. 'gvvi' => 'GetVideoVendorId',
  62. 'gsvi' => 'GetSportVendorId',
  63. 'atin' => 'AutoLogin',
  64. 'todaycr' => 'ConsumptionRanking',
  65. ];
  66. return $maps;
  67. }
  68. //输入参数校验
  69. private function ParasCheck()
  70. {
  71. $this->parasString = $params = $_REQUEST['params'];
  72. $this->userKey = $_REQUEST['Key'];
  73. $arr = explode('&', base64_decode($params));
  74. if (is_array($arr)) {
  75. foreach ($arr as $substring) {
  76. $tmp = explode("=", $substring);
  77. if (isset($tmp['0'])) {
  78. $tmpkey = strtolower(trim($tmp['0']));
  79. $val = isset($tmp['1']) ? trim($tmp['1']) : '';
  80. $this->paras[$tmpkey] = $val;
  81. }
  82. }
  83. } else {
  84. Render('', 10010, lang('Errors', 'Sports')->get('error-10009'));
  85. }
  86. $allmap = $this->ActionMap();
  87. $method = isset($this->paras['method']) ? $this->paras['method'] : '';
  88. if (!isset($allmap[$method])) {
  89. Render('', 10011, lang('Errors', 'Sports')->get('error-10009'));
  90. }
  91. $format = isset($this->paras['format']) ? strtolower(trim($this->paras['format'])) : '';
  92. if ($format == '' || !in_array($format, ['json', 'xml'])) {
  93. $format = $this->defformat;
  94. }
  95. S('CUR_RETURN_FORMAT', $format);
  96. }
  97. //Key验证
  98. private function AgentKeyCheck()
  99. {
  100. $agent = isset($this->paras['agent']) ? trim($this->paras['agent']) : '';
  101. if (empty($agent)) {
  102. Render('key_error', 0, 'key_error');
  103. }
  104. $model = (new Wagent)->getByName($agent);
  105. if (empty($model)) {
  106. Render('10', 0, 'The agent not exist');
  107. }
  108. $ret = $model->CheckKey($model, $this->parasString, $this->userKey);
  109. if ($ret != 1) {
  110. if ($ret == -1) {
  111. Render('10', 2, 'Token overTime,please Refresh!');
  112. }
  113. Render('10', 0, 'key check error!-' . $ret);
  114. }
  115. $this->model = $model;
  116. return true;
  117. }
  118. //调试地址生成用
  119. public function makeurl()
  120. {
  121. $remotip = $_SERVER['REMOTE_ADDR'];
  122. if (!($remotip == '127.0.0.1' || substr($remotip, 0, 7) == '192.168')) {
  123. //只能在内网调试使用
  124. exit;
  125. }
  126. $paras = $_REQUEST;
  127. unset($paras['_url']);
  128. if (empty($paras)) {
  129. exit;
  130. }
  131. $strArr = array();
  132. foreach ($paras as $key => $val) {
  133. //if ($key=='agent'){ $val = 'test1agent' ; }
  134. array_push($strArr, $key . '=' . $val);
  135. }
  136. $string = implode('&', $strArr);
  137. $key = md5(base64_encode($string) . '58f306c11e6a9d4cc74723bb76b17500');
  138. if (isset($_REQUEST['debug'])) {
  139. $host = $_SERVER['HTTP_HOST'];
  140. $url = 'http://' . $host . '/InApi-index/dobusiness?params=' . base64_encode($string) . '&Key=' . $key;
  141. } else {
  142. $url = 'http://sports.5gogo.com/InApi-index/dobusiness?params=' . base64_encode($string) . '&Key=' . $key;
  143. }
  144. Render(['url' => $url], 1, 'success');
  145. }
  146. //客户获取token用于 Key 的生成使用
  147. public function getToken()
  148. {
  149. $agengname = $_POST['wagent_name'];
  150. $key = $_POST['wagent_key'];
  151. $secret = $_POST['wagent_secret'];
  152. $model = (new Wagent)->TokenGetAndUpdate($agengname, $key, $secret);
  153. if (!$model) {
  154. Render('', 3, 'get Token false!');
  155. }
  156. Render(['token' => $model->auth_token], 1, 'success');
  157. }
  158. }