Helper.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. namespace App\Http\helper;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Log;
  9. use phpDocumentor\Reflection\Types\Self_;
  10. class Helper
  11. {
  12. // 游戏配置
  13. const Games = [1005, 2010, 2030, 2050, 2060, 2061, 3000, 3010, 3050];
  14. // rummy 配置
  15. const RUMMY_SERVER_IDS = [29, 30, 34, 35, 36, 37, 40, 41, 42, 43, 44, 45, 46, 48];
  16. // tp 配置
  17. const TEEN_PATTI_SERVER_IDS = [18, 19, 20, 31];
  18. public static function return_time(Request $request)
  19. {
  20. $start_time = str_replace('T', ' ', $request->start_time ?: '');
  21. $end_time = str_replace('T', ' ', $request->end_time ?: '');
  22. return compact('start_time', 'end_time');
  23. }
  24. public static function time($start_time, $end_time)
  25. {
  26. $start_time = str_replace('T', ' ', $start_time);
  27. $end_time = str_replace('T', ' ', $end_time);
  28. return compact('start_time');
  29. }
  30. // 获取毫秒
  31. public static function millisecond()
  32. {
  33. // 微妙时间戳
  34. list($msec, $sec) = explode(' ', microtime());
  35. $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
  36. return $millisecond;
  37. }
  38. // 时间转换
  39. public static function timeChange($time)
  40. {
  41. !empty($time) && $time = date('Y-m-d', strtotime($time)) . 'T' . date('H:i:s', strtotime($time));
  42. return $time;
  43. }
  44. public static function str_replace($str = '')
  45. {
  46. if (strpos($str, '代付失败')) {
  47. $str = str_replace("代付失败", "Payment failed", $str);
  48. }
  49. if (strpos($str, '代付人信息不合法')) {
  50. $str = str_replace("代付人信息不合法", "Illegal payer information", $str);
  51. }
  52. if (strpos($str, '调用第三方渠道异常')) {
  53. $str = str_replace("调用第三方渠道异常", "Exception calling third-party channel", $str);
  54. }
  55. if (strpos($str, '请求三方通道异常')) {
  56. $str = str_replace("请求三方通道异常", "Request for third-party channel exception", $str);
  57. }
  58. if (strpos($str, '提交失败:订单重复')) {
  59. $str = str_replace("提交失败:订单重复", "Failed to submit: duplicate order", $str);
  60. }
  61. if (strpos($str, '订单重复')) {
  62. $str = str_replace("订单重复", "duplicate order", $str);
  63. }
  64. return $str;
  65. }
  66. public static function str_replaceCode($code = '')
  67. {
  68. switch ($code) {
  69. case '000218':
  70. $msg = '';
  71. break;
  72. case '000215':
  73. $msg = '';
  74. break;
  75. case '900000':
  76. $msg = '';
  77. break;
  78. case '000801':
  79. $msg = '';
  80. break;
  81. case '100301':
  82. $msg = '';
  83. break;
  84. case '999999':
  85. $msg = '';
  86. break;
  87. }
  88. }
  89. // 生成随机手机号
  90. public static function randPhone($UserID, $flag = false)
  91. {
  92. $prefix = '7436';
  93. if ($flag)
  94. $prefix = '+917436';
  95. $phone = $prefix . str_pad(array_random([7, 9]) . substr(time(), 5), 6);
  96. $first = DB::connection('write')->table('agent.dbo.PaymentSimulation')->where('UserID', $UserID)->first();
  97. if ($first) {
  98. $phone = $first->Phone;
  99. } else {
  100. DB::connection('write')->table('agent.dbo.PaymentSimulation')
  101. ->updateOrInsert(['UserID' => $UserID], [
  102. 'Phone' => $phone
  103. ]);
  104. }
  105. return $phone;
  106. }
  107. // 获取用户手机号
  108. public static function getPhone($UserID, $phone, $userName = '', $email = '')
  109. {
  110. // $AccountsInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('UserID', $UserID)->select('WebLogonTimes')->first();
  111. $AccountPhone = DB::connection('write')->table('QPAccountsDB.dbo.AccountPhone')->where('UserID', $UserID)->select('PhoneNum')->first()->PhoneNum ?? '';
  112. // 是否提现过
  113. // $AccountWithDrawInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountWithDrawInfo')->where('UserID', $UserID)->select('PhoneNumber', 'BankUserName', 'EmailAddress')->first();
  114. // if ($AccountWithDrawInfo && !empty($AccountWithDrawInfo->BankUserName) && !empty($AccountWithDrawInfo->EmailAddress) && !empty($AccountWithDrawInfo->PhoneNumber)) {
  115. // $userName = $AccountWithDrawInfo->BankUserName;
  116. // $email = $AccountWithDrawInfo->EmailAddress;
  117. // $phone = $AccountWithDrawInfo->PhoneNumber;
  118. // }
  119. $userPayInfo = self::userPayInfo($UserID);
  120. // 绑定过手机号
  121. if (!empty($AccountPhone)) {
  122. // if (!$AccountWithDrawInfo || empty($AccountWithDrawInfo->PhoneNumber)) { # 没有绑定过提现信息
  123. $phone = trim($AccountPhone);
  124. $userName = $userPayInfo['userName'];
  125. $email = $userPayInfo['email'];
  126. // }
  127. }
  128. $phone = str_replace('+91', '', $phone);
  129. if (empty($phone) || $phone == 'undefined') {
  130. $phone = $userPayInfo['phone'];
  131. }
  132. if (empty($userName) || $userName == 'undefined') {
  133. $userName = $userPayInfo['userName'];
  134. }
  135. if (empty($email) || $email == 'undefined') {
  136. $email = $userPayInfo['email'];
  137. }
  138. return compact('phone', 'userName', 'email');
  139. }
  140. // 用户支付信息模拟
  141. public static function userPayInfo($UserID, $userName = '', $email = '')
  142. {
  143. $PaymentSimulation = DB::connection('read')->table('agent.dbo.PaymentSimulation')
  144. ->where('UserID', $UserID)
  145. ->first();
  146. $mt_rand = mt_rand(1, 6719);
  147. $PayUserNames = DB::connection('read')->table('agent.dbo.PayUserNames')->where('id', $mt_rand)->first();
  148. if (!$PayUserNames) {
  149. $PayUserNames = DB::connection('read')->table('agent.dbo.PayUserNames')->where('id', 1)->first();
  150. }
  151. // Log::info('用户姓名:'.$userName);
  152. // 用户输入 》 用户提现的信息 》 随机模拟值
  153. if (empty($userName) || empty($email) || $userName == 'undefined' || $email == 'undefined') {
  154. $first = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  155. ->where('UserID', $UserID)
  156. ->select('BankUserName', 'EmailAddress')
  157. ->first();
  158. if (!$first || empty($first->BankUserName) || empty($first->EmailAddress)) {
  159. if (!$PaymentSimulation) {
  160. $userName = $PayUserNames->user_name;
  161. $email = $userName . mt_rand(1, 9999) . self::rand_email();
  162. } else {
  163. $userName = empty($PaymentSimulation->UserName) ? $PayUserNames->user_name : $PaymentSimulation->UserName;
  164. $email = empty($PaymentSimulation->Email) ? $userName . mt_rand(1, 9999) . self::rand_email() : $PaymentSimulation->Email;
  165. }
  166. } else {
  167. $userName = empty($first->BankUserName) ? $PayUserNames->user_name : $first->BankUserName;
  168. $email = empty($first->EmailAddress) ? $userName . mt_rand(1, 9999) . self::rand_email() : $first->EmailAddress;
  169. }
  170. }
  171. if (!$PaymentSimulation) {
  172. $phone = self::randPhone($UserID);
  173. } else {
  174. $phone = $PaymentSimulation->Phone;
  175. }
  176. DB::connection('write')->table('agent.dbo.PaymentSimulation')
  177. ->updateOrInsert(['UserID' => $UserID], [
  178. 'Phone' => $phone,
  179. 'UserName' => $userName,
  180. 'Email' => $email,
  181. 'LastTime' => date('Y-m-d H:i:s')
  182. ]);
  183. return compact('userName', 'email', 'phone');
  184. }
  185. // 获取随机邮箱后缀
  186. public static function rand_email()
  187. {
  188. $rand_email = array(
  189. '0' => array('id' => 1, 'email' => '@169.cb', 'v' => 2),
  190. '1' => array('id' => 2, 'email' => '@1236.com', 'v' => 3),
  191. '2' => array('id' => 3, 'email' => '@gmail.com', 'v' => 95),
  192. );
  193. $arr = [];
  194. foreach ($rand_email as $key => $val) {
  195. $arr[$val['id']] = $val['v'];
  196. }
  197. $rid = self::get_rand($arr); //根据概率获取奖项id
  198. $email = $rand_email[$rid - 1]['email']; //中奖项
  199. return $email;
  200. }
  201. // 获取随机数
  202. public static function get_rand($proArr)
  203. {
  204. $result = '';
  205. //概率数组的总概率精度
  206. $proSum = array_sum($proArr);
  207. //概率数组循环
  208. foreach ($proArr as $key => $proCur) {
  209. $randNum = mt_rand(1, $proSum);
  210. if ($randNum <= $proCur) {
  211. $result = $key;
  212. break;
  213. } else {
  214. $proSum -= $proCur;
  215. }
  216. }
  217. unset ($proArr);
  218. return $result;
  219. }
  220. // 生成随机手机号
  221. public static function round_phone($flag = true)
  222. {
  223. $prefix = '7436';
  224. if ($flag)
  225. $prefix = '+917436';
  226. $phone = $prefix . str_pad(array_random([7, 9]) . substr(time(), 5), 6);
  227. return $phone;
  228. }
  229. // 获取IP所在地址
  230. public static function get_ip_city($ip)
  231. {
  232. $ch = curl_init();
  233. $url = 'https://whois.pconline.com.cn/ipJson.jsp?ip=' . $ip;
  234. //用curl发送接收数据
  235. curl_setopt($ch, CURLOPT_URL, $url);
  236. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  237. //请求为https
  238. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  239. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  240. $location = curl_exec($ch);
  241. curl_close($ch);
  242. //转码
  243. $location = mb_convert_encoding($location, 'utf-8', 'GB2312');
  244. //var_dump($location);
  245. //截取{}中的字符串
  246. $location = substr($location, strlen('({') + strpos($location, '({'), (strlen($location) - strpos($location, '})')) * (-1));
  247. //将截取的字符串$location中的‘,’替换成‘&’ 将字符串中的‘:‘替换成‘=’
  248. $location = str_replace('"', "", str_replace(":", "=", str_replace(",", "&", $location)));
  249. //php内置函数,将处理成类似于url参数的格式的字符串 转换成数组
  250. parse_str($location, $ip_location);
  251. return $ip_location['addr'];
  252. }
  253. // 获取IP所在地址 -- 阿里
  254. public static function getIPCity($ip)
  255. {
  256. $config = config('api.aliyun');
  257. AlibabaCloud::accessKeyClient($config['accessKeyID'], $config['accessKeySecret'])
  258. ->regionId('cn-hangzhou')
  259. ->asDefaultClient();
  260. try {
  261. $result = AlibabaCloud::rpc()
  262. ->product('geoip')
  263. // ->scheme('https') // https | http
  264. ->version('2020-01-01')
  265. ->action('DescribeIpv4Location')
  266. ->method('POST')
  267. ->host('geoip.aliyuncs.com')
  268. ->options([
  269. 'query' => [
  270. 'RegionId' => "cn-hangzhou",
  271. 'Ip' => $ip,
  272. ],
  273. ])
  274. ->request();
  275. return $result->toArray();
  276. } catch (ClientException $e) {
  277. return $e->getErrorMessage() . PHP_EOL;
  278. } catch (ServerException $e) {
  279. return $e->getErrorMessage() . PHP_EOL;
  280. }
  281. }
  282. }