Rgame_setting.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ikeke
  5. * Date: 2018/12/15
  6. * Time: 13:13
  7. */
  8. namespace App\Models;
  9. class Rgame_setting extends BaseModel
  10. {
  11. protected $table = "rgame_setting";
  12. public $timestamps = false;
  13. public function getGame($where='')
  14. {
  15. $res = $this->where($where)->first();
  16. if(!$res)
  17. {
  18. return -1;
  19. }
  20. else
  21. {
  22. return $res;
  23. }
  24. }
  25. public function getGames($where='')
  26. {
  27. $res = $this->where('game_type',$where)->first();
  28. if(!$res)
  29. {
  30. return -1;
  31. }
  32. else
  33. {
  34. return $res;
  35. }
  36. }
  37. function getlist($list = 10, $where = '') {//获取列表
  38. $data = $this->orderBy('ctime', 'desc');
  39. if (!empty($where) && is_array($where)) {
  40. $data = $data->where($where);
  41. }
  42. $data = $data->paginate($list);
  43. if (!$data) {
  44. return -4010010022; //没有数据
  45. }
  46. return $data->toArray();
  47. }
  48. function getGameList()
  49. {
  50. $data = $this->select('game_type','game_zh','extend','agent_name','user_prefix')->where('isopen',1)->get()->toArray();
  51. return $data;
  52. }
  53. //获取真人游戏基本信息
  54. protected function GetRgameInfo($where=array()){
  55. $data = $this->select('game_zh','game_type','extend','agent_name','user_prefix');
  56. if(!empty($where))$data = $data->where($where);
  57. $data = $data->get();
  58. if(!$data || count($data->toArray())<1)return -4010010022; //没有数据
  59. return $data->toArray();
  60. }
  61. //查询可下分
  62. protected function getBalance($account,$gdata){
  63. //if (empty($account))Render('',-7030);lcqpgame
  64. $a = array(
  65. 'status' => -1,
  66. 'game_type' => $gdata['game_type']??'lcqpgame',
  67. 'money' => "0.00",
  68. );
  69. if(!is_array($gdata)){
  70. $gdata = $this->GetRgameInfo(array('game_type'=>$gdata));
  71. if($gdata<0)return $a;
  72. $gdata = current($gdata);
  73. }
  74. $gdata['s'] = 1;
  75. $agent = $gdata['agent_name'];
  76. if(count(explode('_', $account))<2){
  77. $account = $this->setGameName($gdata['user_prefix'],$account,$gdata['game_type']);
  78. if($account<0)return $a;
  79. }
  80. $betobj = '\\App\\Model\\' .ucfirst($gdata['game_type']) . '_betting_ogrbv';
  81. $jump_url = $betobj::transferGame($agent,$gdata,$account);
  82. $arr = $this->curl_get_content($jump_url);
  83. $array = json_decode($arr, 1);
  84. if(isset($array['d']['code']) && $array['d']['code'] == 0)
  85. {
  86. $a['status'] = 1;
  87. $a['money'] = is_float($array['d']['money']) ? (string)$array['d']['money'] : $array['d']['money'];
  88. }
  89. return $a;
  90. }
  91. //上分1,下分2 lcqpgame
  92. protected function transferCreditNew($account,$money,$ss,$gdata,$loname='')
  93. {
  94. if(!is_array($gdata)){
  95. $gdata = $this->GetRgameInfo(array('game_type','=',$gdata));
  96. if($gdata<0)return $a;
  97. $gdata = current($gdata);
  98. }
  99. if(count(explode('_', $account))<2){
  100. $account = $this->setGameName($gdata['user_prefix'],$account,$gdata['game_type']);
  101. if($account<0)return $a;
  102. }
  103. $gdata['s'] = $ss == 1 ? 2 : 3;
  104. $agent = $gdata['agent_name'];
  105. $orderid = $this->getOrderId($agent);
  106. $og = new \App\Models\Oggame_transfer_record();
  107. //如果Ky用户存在则直接登录//否则注册后登录
  108. $jump_url = $this->transferGame($agent,$gdata,$account,$money,$orderid);
  109. $arr = $this->curl_get_content($jump_url);
  110. $str = json_decode($arr,1);
  111. $data = array(
  112. 'order_no' => $orderid,
  113. 'game_type' => $gdata['game_type'],
  114. 'transfer_type' => $ss,
  115. 'casino_user' => $account,
  116. 'local_user' => empty($loname)?explode('_', $account)[2]:$loname,
  117. 'transfer_money' => $money,
  118. 'sub_time' => time(),
  119. 'exec_time' => time(),
  120. );
  121. if ($str['d']['code'] == 0)
  122. {
  123. $data['exec_result'] = '[成功]单笔转账成功(手机版)';
  124. $data['type'] = '5';
  125. $og->insertRec($data);
  126. $d['status'] = 1;
  127. $d['data'] = $data;
  128. $d['msg'] = '充值成功';
  129. return $d;
  130. }
  131. else
  132. {
  133. $data['exec_result'] = '[失败]单笔转账失败(手机版)';
  134. $data['type'] = '2';
  135. $og->insertRec($data);
  136. $d['status'] = -1;
  137. $d['data'] = $str;
  138. $d['msg'] = '[失败]单笔转账失败(手机版)';
  139. return $d;
  140. }
  141. }
  142. //接口地址获取
  143. protected function transferGame($agent,$data,$account,$money=0,$orderid='',$KindID=0,$time=5)
  144. {
  145. $ip= GETIP();
  146. $s = $data['s'];
  147. $robj = '\App\Models\Rgame_setting';
  148. $timestamp = str_pad($robj::getMillisecond(),13,0);//时间戳
  149. $jdata = json_decode($data['extend'], true);
  150. $DESKey = $jdata['desKey'];//'139B4CCEF28033C9';
  151. $lineCode=$jdata['lineCode'];
  152. $prams = 's='.$s;
  153. if ($s==0){
  154. $prams .= '&account='.$account.'&money='.$money.'&orderid='.$orderid.'&ip='.$ip.'&lineCode='.$lineCode.'&KindID='.$KindID;
  155. }elseif ($s==1 || $s==5 || $s==7 || $s==8){
  156. $prams .= '&account='.$account;
  157. }else if($s==2||$s==3){
  158. if($data['game_type'] == 'lcqpgame' || $data['game_type'] == 'lygame'){
  159. $prams .= '&account='.$account.'&money='.$money.'&orderid='.$orderid;
  160. }else{
  161. $prams .= '&account='.$account.'&orderid='.$orderid.'&money='.$money;
  162. }
  163. }else if($s==4){
  164. $prams .= '&orderid='.$orderid;
  165. }else if($s==6)
  166. {
  167. $startTime = $timestamp-60*$time*1000;
  168. $endTime = $timestamp;
  169. $prams .= '&startTime='.$startTime.'&endTime='.$endTime;
  170. }
  171. $params = urlencode($robj::openssl_desEncode($prams,$DESKey));//参数加密字符串
  172. $key = md5($agent.$timestamp.$jdata['md5key']);
  173. $param = [
  174. 'agent' => $agent,
  175. 'timestamp' => $timestamp,
  176. 'param' => $params,
  177. 'key' => $key,
  178. ];
  179. if ($s == 6)
  180. {
  181. $url = $jdata['host2'].'?agent='.$agent.'&timestamp='.$timestamp.'&param='.$params.'&key='.$key;
  182. return $url;
  183. }
  184. $url = $jdata['host1'].'?agent='.$agent.'&timestamp='.$timestamp.'&param='.$params.'&key='.$key;
  185. return $url;
  186. }
  187. //获取接口用户名
  188. protected function setGameName($upex='',$username='',$type='')
  189. {
  190. if(empty($upex))return -50630200702;
  191. if(empty($username))return -50630200802;
  192. if(empty($type))return -50630200902;
  193. $user = new \App\Models\Oggame_user();
  194. $is_user = $user->getUser($username,$type);
  195. if(empty($is_user->rp_name))
  196. {
  197. $str = '';
  198. if(strlen($username) > 6)
  199. {
  200. $str = substr($username, -6);
  201. }
  202. else
  203. {
  204. $str = $username;
  205. }
  206. $strs = $upex.$str.'_'.$this->getLetter();
  207. return $strs;
  208. }
  209. else
  210. {
  211. return $is_user->rp_name;
  212. }
  213. }
  214. //获取随机4个英文字母
  215. protected function getLetter()
  216. {
  217. $letter = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
  218. $str = '';
  219. for($i = 0; $i < 4; $i++)
  220. {
  221. $s = rand(0,25);
  222. $str .= $letter[$s];
  223. }
  224. return $str;
  225. }
  226. //参数设置方法
  227. protected function getMillisecond()
  228. {
  229. list($t1, $t2) = explode(' ', microtime());
  230. return $t2 . ceil( ($t1 * 1000) );
  231. }
  232. protected function openssl_desEncode($str,$key)
  233. {
  234. $str = $this->pkcs5_pad(trim($str), 16);
  235. $encrypt_str = openssl_encrypt($str, 'AES-128-ECB', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING);
  236. return base64_encode($encrypt_str);
  237. }
  238. protected function pkcs5_pad($text, $blocksize)
  239. {
  240. $pad = $blocksize - (strlen($text) % $blocksize);
  241. return $text . str_repeat(chr($pad), $pad);
  242. }
  243. protected function curlData($url, $data, $methd='POST')
  244. {
  245. if($data['dbg'] > 0)
  246. {
  247. dump($data);
  248. }
  249. unset($data['dbg']);
  250. $ch = curl_init();
  251. $timeout = 10;
  252. curl_setopt($ch, CURLOPT_URL, $url);
  253. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  254. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  255. curl_setopt($ch, CURLOPT_POST, $methd);
  256. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  257. $file_contents = curl_exec($ch);
  258. curl_close($ch);
  259. return $file_contents;
  260. }
  261. protected function is_curl_ready()
  262. {
  263. return function_exists('curl_version');
  264. }
  265. protected function dbglog($msg)
  266. {
  267. if (is_string($msg))
  268. {
  269. syslog(LOG_DEBUG, $msg);
  270. }
  271. else
  272. {
  273. syslog(LOG_DEBUG, json_encode($msg));
  274. }
  275. }
  276. function getOrderId($agent){
  277. list($usec, $sec) = explode(" ", microtime());
  278. $msec=round($usec*1000);
  279. return $agent.date("YmdHis").$msec;
  280. }
  281. protected function curl_get_content($url, $conn_timeout=7, $timeout=15, $user_agent=null)
  282. {
  283. if (!$this->is_curl_ready()) {
  284. $this->dbglog('PHP CURL MODULE MISSING. INSTALL: apt install php7.1-curl php7.2-curl');
  285. return null;
  286. }
  287. $headers = array(
  288. "Accept: application/json",
  289. "Cache-Control: no-cache",
  290. "Pragma: no-cache",
  291. "Accept-Charset: utf-8;q=1"
  292. );
  293. if ($user_agent === null) {
  294. $user_agent = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36';
  295. }
  296. $headers[] = $user_agent;
  297. $ch = curl_init();
  298. curl_setopt($ch, CURLOPT_URL, $url);
  299. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  300. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  301. curl_setopt($ch, CURLOPT_HEADER, 0);
  302. // curl_setopt($ch, CURLOPT_POST, $methd);
  303. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $conn_timeout);
  304. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  305. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  306. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  307. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  308. $res = curl_exec($ch);
  309. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  310. $err = curl_errno($ch);
  311. curl_close($ch);
  312. if (($err) || ($httpcode !== 200)) {
  313. $this->dbglog($res, 'curl result');
  314. $this->dbglog(["err"=>$err, "code"=>$httpcode], 'curl error');
  315. return null;
  316. }
  317. return $res;
  318. }
  319. }