123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890 |
- <?php
- namespace bibidd\Controller;
- use Think\Controller;
- /**
- * 公共控制器,用于封装公函数。 v2.0 by:bingtan11
- */
- class CommonBaseController extends Controller
- {
- /**
- * 添加相应头
- * @return void
- */
- protected function addHeaders()
- {
- header('Content-Type:text/json;charset=utf-8');
- header('Access-Control-Allow-Origin:*');
- header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
- header('Access-Control-Allow-Methods:POST');
- header('Access-Control-Expose-Headers:*');
- }
- /**
- * 检查登录用户ID
- * @param $uid
- * @return void
- */
- protected function checkUserIsExist($uid)
- {
- if (empty($uid)) {
- $this->returnDataAndSendMsg("用户不存在");
- die();
- }
- $userInfo = M("user_info")->where("id='$uid'")->find();
- if (empty($userInfo)) {
- $this->returnDataAndSendMsg("用户不存在");
- die();
- }
- return $userInfo;
- }
- protected function returnData()
- {
- $this->addHeaders();
- $data['status'] = '0';
- $data['code'] = '202';//未携带参数,请求失败
- $data['message'] = 'error';
- echo json_encode($data);
- }
- protected function returnDataAndSendMsg($errMsg)
- {
- $this->addHeaders();
- $data['status'] = '0';
- $data['code'] = '202';//未携带参数,请求失败
- $data['message'] = $errMsg;
- echo json_encode($data);
- }
- /**
- * 为list数组添加广告
- * @param $adv_type 需要添加的广告类型
- * @param $adv_number 需要添加广告数
- * @param $start_point 追加的开始位置
- * @param $dataList 原始数组
- * @return void
- */
- protected function addAdvForDataList($adv_type, $adv_number, $start_point, $dataList)
- {
- $return_data = $dataList;
- //获取广告
- $adv_list = M("slgj_advert_list")->where("type='$adv_type'")->Field("img,jump_link,number")->order("rand()")->LIMIT($adv_number)->select();
- $jia_num = $start_point;
- $qishi_num = 0;
- $data_list_number = count($dataList);
- $quzheng_num = floor($data_list_number / $start_point);
- foreach ($adv_list as $key => $value) {
- $charu_array = array();
- $charu_array = array($adv_list[$key]);
- array_splice($return_data, $jia_num, 0, $charu_array);
- $jia_num += ($start_point + 1);
- $qishi_num += 1;
- if ($qishi_num >= $quzheng_num) {
- break;
- }
- }
- return $return_data;
- }
- protected function addAdvForDataList_increase($adv_type, $adv_number, $start_point, $dataList, $increase_num)
- {
- $return_data = $dataList;
- //获取广告
- $adv_list = M("slgj_advert_list")->where("type='$adv_type'")->Field("img,jump_link,number")->order("rand()")->LIMIT($adv_number)->select();
- $jia_num = $start_point;
- $qishi_num = 0;
- $data_list_number = count($dataList);
- $quzheng_num = floor($data_list_number / $start_point);
- foreach ($adv_list as $key => $value) {
- $charu_array = array();
- $charu_array = array($adv_list[$key]);
- array_splice($return_data, $jia_num, 0, $charu_array);
- $jia_num += ($increase_num + 1);
- $qishi_num += 1;
- if ($qishi_num >= $quzheng_num) {
- break;
- }
- }
- return $return_data;
- }
- /**
- *
- * 穿插数据
- * @param $src_data_list 被需要追加的列表
- * @param $insert_data_list 需要追加的列表
- * @param $start_point 追加启始位置,下标为0
- * @param $increase_num 增长数,间隔多少条数据插入
- * @return void
- */
- protected function insert_data_list($src_data_list, $insert_data_list, $start_point, $increase_num)
- {
- $return_data = $src_data_list;
- //获取广告
- $adv_list = $insert_data_list;
- $jia_num = $start_point;
- $qishi_num = 0;
- $data_list_number = count($src_data_list);
- $quzheng_num = floor($data_list_number / $increase_num);
- foreach ($adv_list as $key => $value) {
- $charu_array = array();
- $charu_array = array($adv_list[$key]);
- array_splice($return_data, $jia_num, 0, $charu_array);
- $jia_num += ($increase_num + 1);
- $qishi_num += 1;
- if ($qishi_num >= $quzheng_num) {
- break;
- }
- }
- return $return_data;
- }
- /**
- * 发送手机验证码
- * @param $mobile
- * @param $code
- * @return mixed
- */
- protected function sendMessage($mobile, $code)
- {
- // $mobile = ""; // 多个号码可用逗号分隔,最多200个
- $content = "您的验证码:" . $code . ",如非本人操作,请忽略本短信!"; // string 不建议太长
- $encode = "utf-8"; // 可选参数
- //可传 notify 或 ad , adcard,adfangchan,dxztd 五参数, notify: 表示通知类, ad: 表示106通道广告类,
- // adcard: 表示卡发通道广告类, adfangchan:表示106房产专用通道,dxztd:表示低限制通道,
- // 严禁用通知类发广告,否则将关掉api接口同时封帐号不退余额,严重的提交相关部门处理。
- $smstype = 'notify';
- $url = "http://www.huiyuandx.com/api/sms_send?";
- $url .= "user=liujinzaixian&";
- $url .= "hash=ab7d44b9599db2e2b4d2bf5ab35666cb&";
- $url .= "encode=$encode&";
- $url .= "smstype=$smstype&";
- $url .= "mobile=" . urlencode($mobile) . "&content=" . urlencode($content) . "";
- $ctx = stream_context_create(array(
- 'http' => array(
- 'timeout' => 30,
- 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;YNSMS API v1.0;)"
- )
- )
- );
- $r = file_get_contents($url, 0, $ctx);
- $rs = json_decode($r, true);
- return $rs;
- }
- /*
- * 生成随机字符串
- *
- * $length 字符串长度
- */
- protected function random_str($length)
- {
- // 密码字符集,可任意添加你需要的字符
- $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $str = '';
- for ($i = 0; $i < $length; $i++) {
- $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
- return $str;
- }
- protected function random_num($length)
- {
- // 密码字符集,可任意添加你需要的字符
- $chars = '1234567890';
- $str = '';
- for ($i = 0; $i < $length; $i++) {
- $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
- return $str;
- }
- protected function getIp()
- {
- if (isset($_SERVER['http_cf_connecting_ip'])) { // 支持Cloudflare
- $ip = $_SERVER['http_cf_connecting_ip'];
- } elseif (isset($_SERVER['REMOTE_ADDR']) === true) {
- $ip = $_SERVER['REMOTE_ADDR'];
- if (preg_match('/^(?:127|10)\.0\.0\.[12]?\d{1,2}$/', $ip)) {
- if (isset($_SERVER['HTTP_X_REAL_IP'])) {
- $ip = $_SERVER['HTTP_X_REAL_IP'];
- } elseif (isset($_SERVER['http_x_forewarded_for'])) {
- $ip = $_SERVER['http_x_forewarded_for'];
- }
- }
- } else {
- $ip = '127.0.0.1';
- }
- if (in_array($ip, ['::1', '0.0.0.0', '本地主机'], true)) {
- $ip = '127.0.0.1';
- }
- $filter = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
- if ($filter === false) {
- $ip = '127.0.0.1';
- }
- return $ip;
- }
- /**
- * 发送消息
- * @return void
- */
- protected function send_msg_to_telegram($botToken, $chatId, $text)
- {
- //$botToken = $_POST['token'];
- $website = "https://api.telegram.org/bot" . $botToken;
- //$chatId = $_POST['chatId']; // 你想要发送消息的聊天ID
- //$text = $_POST['text'];
- $params = [
- 'chat_id' => $chatId,
- 'text' => $text
- ];
- $ch = curl_init($website . '/sendMessage');
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($ch);
- if ($result === false) {
- // 如果请求失败,获取错误信息
- $error = curl_error($ch);
- $error_code = curl_errno($ch);
- // 输出错误信息
- curl_close($ch);
- return $error;
- }
- curl_close($ch);
- if ($result !== false) {
- // 如果请求成功,你可以对结果进行处理
- $response = json_decode($result, true);
- return $response;
- }
- }
- /**
- *
- * 根据用户ip返回用户的省和市的信息
- * @param $ip
- * @return mixed
- */
- protected function get_user_ip_info($ip)
- {
- $appId = "clLLhaWabJJnrWjE";
- $appSecret = "9e82fed66e40e3e438f3fe416a95925a";
- $url = "https://api.jumdata.com/ip/query";
- $method = "POST";
- $headers = array();
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
- $timestamp = $this->getUnixTimestamp();
- $sign = hash('sha256', $appId . $appSecret . $timestamp); // 生成sign
- $bodys = "appId=" . $appId . "&sign=" . $sign . "×tamp=" . $timestamp . "&productCode=ip_query" . "&ip=" . $ip;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- if (1 == strpos("$" . $url, "https://")) {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- $return = curl_exec($curl);
- $return_end = json_decode($return, true);
- return $return_end;
- }
- protected function getUnixTimestamp()
- {
- list($s1, $s2) = explode(' ', microtime());
- return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
- }
- /**
- * 处理文件上传
- * @param $files
- * @return array
- */
- protected function dealFiles($files)
- {
- $fileArray = array();
- $n = 0;
- if (is_array($files['name'])) {
- $keys = array_keys($files);
- foreach ($files['name'] as $key => $value) {
- foreach ($keys as $_key) {
- $fileArray[$n][$_key] = $files[$_key][$key];
- }
- $n++;
- }
- } else {
- $fileArray = $files; // 单个文件上传
- }
- return $fileArray;
- }
- /**
- * 通过id查找元素
- * @param $batch_list
- * @param $id
- * @return mixed
- */
- protected function get_info_by_batch($batch_list, $id, $field_name)
- {
- foreach ($batch_list as $info) {
- if ($info[$field_name] == $id) {
- $found = $info;
- break; // 找到后退出循环
- }
- }
- return $found;
- }
- /**
- * uploader 对应到付费类型
- * @param $uploader
- * @return string
- */
- public function uploader_map_to_pay_type($uploader)
- {
- //$uploader= $_POST['uploader'];
- $map = array(
- //'亚洲'=>'免费',
- // '欧美'=>'免费',
- // '动漫'=>'免费',
- // '吃瓜'=>'免费',
- '同城' => '金币',
- '网曝门' => '金币',
- '另类猎奇' => '金币',
- '女子SPA' => '金币',
- '经典AV' => '金币',
- '厕所偷拍' => '金币',
- '抄底偷拍' => '金币',
- '色情聊天' => '金币',
- '黑料吃瓜' => '金币',
- '粉嫩少女' => '金币',
- '顶臀街射' => '金币',
- '漫画' => '金币',
- '素人反差' => '金币',
- '色情小说' => '金币',
- );
- $rs = empty($map[$uploader]) ? '会员' : $map[$uploader];
- return $rs;
- }
- /**
- * 注册用户数统计
- * @param $invitation_code
- * @return void
- */
- protected function proxy_reg_count($invitation_code, $sub_uid, $sub_name, $sub_reg_time)
- {
- if (empty($invitation_code) || "" == trim($invitation_code)) {
- return;
- }
- // 使用 preg_match 函数进行匹配
- if (!preg_match('/^[A-Z]{4}\d{4}$/', $invitation_code)) {
- return;
- }
- //验证码是否有效
- $user_info_check = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- if (empty($user_info_check)) {
- return;
- }
- //汇总表
- $huizong_inof = M("user_proxy_huizong")->where("invitation_code='$invitation_code'")->find();
- if (empty($huizong_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['renshu_all'] = 1;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_huizong")->add($Add_info);
- }
- if (!empty($huizong_inof)) {
- $id = $huizong_inof["id"];
- $Add_info['renshu_all'] = $huizong_inof['renshu_all'] + 1;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_huizong")->where("id='$id'")->save($Add_info);
- }
- //月度表
- $current_month = date('Y') . '-' . date('m');
- $month_inof = M("user_proxy_month")->where("date_month='$current_month' AND invitation_code='$invitation_code'")->find();
- if (empty($month_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['date_month'] = $current_month;
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['renshu_all'] = 1;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_month")->add($Add_info);
- }
- if (!empty($month_inof)) {
- $id = $month_inof["id"];
- $Add_info['renshu_all'] = $month_inof['renshu_all'] + 1;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_month")->where("id='$id'")->save($Add_info);
- }
- //推荐子表汇总
- $sub_inof = M("user_proxy_sub")->where("invitation_code='$invitation_code' AND sub_uid='$sub_uid'")->find();
- if (empty($sub_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['date_month'] = $current_month;
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['sub_uid'] = $sub_uid;
- $Add_info['sub_name'] = $sub_name;
- $Add_info['renshu_all'] = 1;
- $Add_info['sub_reg_time'] = date('Y-m-d h:i:s', $sub_reg_time);
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_sub")->add($Add_info);
- }
- if (!empty($sub_inof)) {
- $id = $sub_inof["id"];
- $Add_info['renshu_all'] = $month_inof['renshu_all'] + 1;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_sub")->where("id='$id'")->save($Add_info);
- }
- }
- /**
- *
- * 统计用户充值
- * @param $uid 充值用户id
- * @param $money
- * @return void
- */
- protected function proxy_pay_count($uid, $money)
- {
- $user_info_tmp = M("user_info")->where("id = '$uid'")->find();
- $invitation_code = $user_info_tmp['register_invitation_code'];
- if (empty($invitation_code) || "" == trim($invitation_code)) {
- return;
- }
- // 使用 preg_match 函数进行匹配
- if (!preg_match('/^[A-Z]{4}\d{4}$/', $invitation_code)) {
- return;
- }
- //验证码是否有效
- $user_info_check = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- if (empty($user_info_check)) {
- return;
- }
- $choucheng = 0.5;
- //汇总表
- $huizong_inof = M("user_proxy_huizong")->where("invitation_code='$invitation_code'")->find();
- if (empty($huizong_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['chognzhi_all'] = $money;
- $Add_info['yongjin_all'] = $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_huizong")->add($Add_info);
- }
- if (!empty($huizong_inof)) {
- $id = $huizong_inof["id"];
- $Add_info['chognzhi_all'] = $huizong_inof['chognzhi_all'] + $money;
- $Add_info['yongjin_all'] = $huizong_inof['yongjin_all'] + $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_huizong")->where("id='$id'")->save($Add_info);
- }
- //月度表
- $current_month = date('Y') . '-' . date('m');
- $month_inof = M("user_proxy_month")->where("date_month='$current_month' AND invitation_code='$invitation_code'")->find();
- if (empty($month_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['date_month'] = $current_month;
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['chognzhi_all'] = $money;
- $Add_info['yongjin_all'] = $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_month")->add($Add_info);
- }
- if (!empty($month_inof)) {
- $id = $month_inof["id"];
- $Add_info['chognzhi_all'] = $month_inof['chognzhi_all'] + $money;
- $Add_info['yongjin_all'] = $month_inof['yongjin_all'] + $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_month")->where("id='$id'")->save($Add_info);
- }
- //推荐子表汇总
- $sub_uid = $user_info_tmp['id'];
- $sub_inof = M("user_proxy_sub")->where("date_month='$current_month' AND invitation_code='$invitation_code' AND sub_uid='$sub_uid'")->find();
- if (empty($sub_inof)) {
- $user_info = M("user_info")->where("my_invitation_code='$invitation_code'")->find();
- $Add_info['uid'] = $user_info['id'];
- $Add_info['date_month'] = $current_month;
- $Add_info['invitation_code'] = $user_info['my_invitation_code'];
- $Add_info['sub_uid'] = $user_info_tmp['id'];
- $Add_info['sub_name'] = $user_info_tmp['name'];
- $Add_info['sub_reg_time'] = $user_info_tmp['add_date'];
- $Add_info['chognzhi_all'] = $money;
- $Add_info['yongjin_all'] = $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_sub")->add($Add_info);
- }
- if (!empty($sub_inof)) {
- $id = $sub_inof["id"];
- $Add_info['chognzhi_all'] = $sub_inof['chognzhi_all'] + $money;
- $Add_info['yongjin_all'] = $sub_inof['yongjin_all'] + $money * $choucheng;
- $Add_info['last_update'] = date('Y-m-d H:i:s');
- M("user_proxy_sub")->where("id='$id'")->save($Add_info);
- }
- }
- /**
- * 统计充值数
- * @param $uid
- * @param $jinbi
- * @return void
- */
- protected function count_chongzhi($uid, $jinbi)
- {
- $sun_info = M("user_xf_cz_sum")->field("id")->where("uid='$uid'")->find();
- if (empty($sun_info)) {
- //插入
- $save_info["uid"] = $uid;
- $save_info["chongzhi_count"] = $jinbi;
- $save_info["start_time"] = date('Y-m-d H:i:s');
- $save_info["last_update_time"] = date('Y-m-d H:i:s');
- M("user_xf_cz_sum")->add($save_info);
- return;
- }
- //更新
- M("user_xf_cz_sum")->where("uid='$uid'")->setInc("chongzhi_count", $jinbi);
- $save_info["last_update_time"] = date('Y-m-d H:i:s');
- M("user_xf_cz_sum")->where("uid='$uid'")->save($save_info);
- }
- /**
- *
- * 记录消费明细,并添加消费统计
- * @param $uid
- * @param $item_name
- * @param $item_desc
- * @param $take_coins
- * @return void
- */
- protected function xiaofei_detail($uid, $item_name, $item_desc, $take_coins)
- {
- //打印统计数据
- $sun_info = M("user_xf_cz_sum")->field("id")->where("uid='$uid'")->find();
- if (empty($sun_info)) {
- //插入
- $save_info["uid"] = $uid;
- $save_info["xiaofei_count"] = $take_coins;
- $save_info["start_time"] = date('Y-m-d H:i:s');
- $save_info["last_update_time"] = date('Y-m-d H:i:s');
- M("user_xf_cz_sum")->add($save_info);
- } else {
- //更新
- M("user_xf_cz_sum")->where("uid='$uid'")->setInc("xiaofei_count", $take_coins);
- $save_info["last_update_time"] = date('Y-m-d H:i:s');
- M("user_xf_cz_sum")->where("uid='$uid'")->save($save_info);
- }
- //保存消费流水
- $xiaofei_info["uid"] = $uid;
- $xiaofei_info["item_name"] = $item_name;
- $xiaofei_info["item_desc"] = $item_desc;
- $xiaofei_info["take_coins"] = $take_coins;
- $xiaofei_info["creater_at"] = date('Y-m-d H:i:s');
- M("user_xf_detail")->add($xiaofei_info);
- }
- /**
- * 生成uuid
- * @return string
- * @throws \Exception
- */
- protected function generateUUIDv4()
- {
- $data = random_bytes(16);
- $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100
- $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10
- return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
- }
- protected function generateUUIDv4Nodash()
- {
- $data = random_bytes(16);
- $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100
- $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10
- return vsprintf('%s%s%s%s%s%s%s%s', str_split(bin2hex($data), 4));
- }
- /**
- * 统一拦截器
- * @return void
- */
- public function _initialize()
- {
- //需要跳过的接口请求
- $jump_urls = array(
- '/bibidd/Jiajin/jia',
- '/bibidd/Mediaonenine/twotwoone_list',
- '/bibidd/MediaPayonenine/call_back_coins',
- '/bibidd/Index/get_gonggao_url',
- '/bibidd/Advert/get_index_Advert',
- '/bibidd/GameBet/get_pre_result',
- '/bibidd/GameLuck100/get_pre_result',
- '/home/FileUpload/file_upload',
- '/bibidd/Mediaonenine/yuepao_xiafang_tuijian_list',
- '/bibidd/Mediaonenine/woman_detail',
- '/bibidd/Mediaonenine/yuepao_women_list_show',
- '/bibidd/Mediaonenine/yuepao_city_show',
- '/bibidd/Mediaonenine/jingping_video_list',
- '/bibidd/Teacher/query_teacher',
- '/bibidd/Teacher/query_three_rand_teacher',
- '/bibidd/Index/get_game_url',
- '/bibidd/Mediaonenine/game_jump_link_list',
- '/bibidd/Index/get_gonggao_url',
- '/bibidd/user/slUserLogin',
- '/bibidd/user/slUserRegister',
- '/bibidd/Mediaonenine/cowb_list_show',
- '/bibidd/TaskManager/get_sai_dan',
- '/bibidd/GameLuck100/get_luck_users',
- '/bibidd/WebsiteMoniter/websit_speed',
- '/bibidd/WebsiteMoniter/clearGt3h',
- '/bibidd/WebsiteMoniter/zhaleme_speed_call_back',
- '/bibidd/GetVedioForFreeOf10/getVedioForFreeOf10',
- '/bibidd/Mediaonesevenfive/shouye_lianjei',
- '/bibidd/ShopIndex/query_list',
- '/bibidd/LinghangPay/call_back_coins',
- '/bibidd/YiyunPay/call_back_coins',
- '/bibidd/TmplTokenForDay/getToken',
- '/bibidd/Mediatime/one_free_video_test',
- '/bibidd/Mediatime/last_month_commission',
- '/bibidd/Mediatime/two_button_close',
- '/bibidd/Mediatime/last_month_agent_add_amount',
- '/bibidd/Mediatime/pop_user_commission_close',
- '/bibidd/Mediatime/two_two_one',
- '/bibidd/Mediatime/suiji_shoucang_six',
- '/bibidd/Mediaonefivetest/get_agent_record',
- '/bibidd/Mediatime/twelve_update_num',
- '/bibidd/Mediatime/twotwoone_list',
- '/bibidd/Mediatime/Mediaonenine/jingping_video_list',
- '/bibidd/Mediaonenine/chezhen_list_show',
- '/bibidd/Mediaonenine/video_info_list',
- '/bibidd/Mediaonenine/swag_list_show',
- '/bibidd/Mediaonenine/last_login_jilu',
- '/bibidd/Mediaonenine/fuliji_list_show',
- '/bibidd/Mediaonenine/chaoshuang_list_show',
- '/bibidd/Mediaonenine/gangtai_sanji_list_show',
- '/bibidd/Mediaonenine/nantong_gay_list_show'
- );
- $path = $_SERVER['PHP_SELF'];
- // $path = $_SERVER['PHP_SELF'];
- if(strpos($path,'/bibidd/Mediatime')){
- return;
- }else{
- $path = str_replace("/index.php", "", $path);
- if (in_array($path, $jump_urls)) {
- //跳过用户检查,并检查用户段是否有传token如有还需要继续转换用户
- $uid = $this->checkToken();
- if (!empty($uid)) {
- $_POST['uid'] = $uid;
- }
- return;
- }
- }
- $uid = $this->checkToken();
- if (empty($uid)) {
- $this->returnDataAndSendMsg("无效请求a");
- die();
- }
- //检查
- $http_url = $_SERVER["HTTP_REFERER"];
- $http_lg = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
- if (empty($http_url) || empty($http_lg)) {
- $this->returnDataAndSendMsg("无效请求a");
- die();
- }
- $doman = $this->matchurl($http_url);
- //$today= date("Y-m-d");
- $today_url = M("huoyue_list")->where("uid='$uid'")->order("id DESC")->getField("url");
- if (empty($today_url)) {
- $this->returnDataAndSendMsg("无效请求a");
- die();
- }
- if (strpos($today_url, $doman) === false) {
- $this->returnDataAndSendMsg("无效请求a");
- die();
- }
- $_POST['uid'] = $uid;
- }
- private function checkToken()
- {
- $token = $_SERVER['HTTP_TOKEN'];
- if (empty($token)) {
- $token = $_POST['token'];
- }
- if (empty($token)) {
- return null;
- }
- //验证token是否有效
- $current_time = date('Y-m-d H:i:s');
- $uid = M("user_info")->where("token='$token' AND token_time_out>='$current_time'")->getField("id");
- if (empty($uid)) {
- return null;
- }
- return $uid;
- }
- /**
- * 下发token
- * @param $uid
- * @return void
- */
- protected function genToken($uid)
- {
- $token = $this->generateUUIDv4Nodash();
- $current_time = date('Y-m-d H:i:s');
- $out_time = date('Y-m-d H:i:s', strtotime('+7 days', strtotime($current_time)));
- $update_info['token'] = $token;
- $update_info['token_time_out'] = $out_time;
- M("user_info")->where("id='$uid'")->save($update_info);
- return $token;
- }
- /**
- * 更新token时间
- * @param $uid
- * @return bool|float|int|string
- */
- protected function updateToken($uid)
- {
- $current_time = date('Y-m-d H:i:s');
- $out_time = date('Y-m-d H:i:s', strtotime('+7 days', strtotime($current_time)));
- $update_info['token_time_out'] = $out_time;
- return M("user_info")->where("id='$uid'")->save($update_info);
- }
- /**
- * 获取域名
- * @param $param
- * @return array|string|string[]
- */
- private function matchurl($param)
- {
- preg_match('/^http(s)?:\/\/(.*)\//U', $param, $url);
- $value = str_replace(array('http://', 'https://', '/'), "", $url[2]);
- return $value;
- }
- protected function SHA256Hex($str)
- {
- $re = hash('sha256', $str, true);
- return base64_encode(bin2hex($re));
- }
- /**
- * 投注统计
- * @param $uid
- * @param $tz_jin
- * @return void
- */
- protected function touzhu_tongji_for_day($uid, $tz_jin, $game_type)
- {
- $day = date('Y-m-d');//日期
- $count_info = M("game_user_tongji")->field("id,tz_jin,tz_count")->where("uid='$uid' AND tz_day='$day' AND game_type='$game_type'")->find();
- if (empty($count_info)) {
- //插入
- $add_info['tz_day'] = $day;
- $add_info['uid'] = $uid;
- $add_info['tz_jin'] = $tz_jin;
- $add_info['tz_count'] = 1;
- $add_info['game_type'] = $game_type;
- M("game_user_tongji")->add($add_info);
- return;
- }
- $id = $count_info['id'];
- $add_info['tz_jin'] = $count_info['tz_jin'] + $tz_jin;
- $add_info['tz_count'] = $count_info['tz_count'] + 1;
- M("game_user_tongji")->where("id='$id'")->save($add_info);
- }
- /**
- * 游戏提现统计
- * @param $uid
- * @param $tx_jin
- * @return void
- */
- protected function tx_tongji_for_day($uid, $tx_jin)
- {
- $day = date('Y-m-d');//日期
- $count_info = M("game_user_tongji")->field("id,tx_jin,tx_count")->where("uid='$uid' AND tz_day='$day'")->find();
- if (empty($count_info)) {
- //插入
- $add_info['tz_day'] = $day;
- $add_info['uid'] = $uid;
- $add_info['tx_jin'] = $tx_jin;
- $add_info['tx_count'] = 1;
- M("game_user_tongji")->add($add_info);
- return;
- }
- $id = $count_info['id'];
- $add_info['tx_jin'] = $count_info['tx_jin'] + $tx_jin;
- $add_info['tx_count'] = $count_info['tx_count'] + 1;
- M("game_user_tongji")->where("id = '$id'")->save($add_info);
- }
- }
|