Index.php 5.3 KB

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