/** * Set the User geolocation and page */ function init($link = null, $id = null, $online_time = USER_ONLINE_TIME) { $file = basename($_SERVER['SCRIPT_FILENAME']); $url = $_SERVER['REQUEST_URI']; $user_localization = isset($_SESSION['user_localization']) ? $_SESSION['user_localization'] : null; $sid = session_id(); $browser = BROWSER . " " . BROWSER_VERSION; $os = BROWSER_OS; $ip = IP; if (!$user_localization) { $time = TIME - HOUR; DB::query("DELETE FROM " . DB_PREFIX . "user_localization WHERE time < " . HOUR); } $user_localization_id = $user_localization ? $_SESSION['user_localization']['user_localization_id'] : DB::get_field("SELECT user_localization_id FROM " . DB_PREFIX . "user_localization WHERE sid='{$sid}'"); if ($user_id = User::get_user_id()) { $guest_id = 0; $name = User::get_user_field("name"); } else { $guest_id = isset($user_localization['guest_id']) ? $user_localization['guest_id'] : 1 + DB::get_field("SELECT guest_id FROM " . DB_PREFIX . "user_localization ORDER BY guest_id DESC LIMIT 1;"); $name = get_msg('guest') . " " . $guest_id; } if ($user_localization_id) { DB::query("UPDATE " . DB_PREFIX . "user_localization SET ip='{$ip}', user_id='{$user_id}', name='{$name}', url='{$url}', id='{$id}', file='{$file}', time='" . TIME . "', sid='{$sid}' WHERE user_localization_id='{$user_localization_id}'"); } else { if (!($location = ip_to_location($ip, $assoc = true))) { $location = array('CountryCode' => null, 'CountryName' => null, 'RegionCode' => null, 'RegionName' => null, 'City' => null, 'ZipPostalCode' => null, 'Latitude' => null, 'Longitude' => null, 'TimezoneName' => null, 'Gmtoffset' => null); } //replace_sql_injection( $location ); DB::query("INSERT INTO " . DB_PREFIX . "user_localization\r\n (ip,sid,user_id,guest_id,name,url,id,file,os,browser,time,time_first_click,country_code,country_name,region_code,region_name,city_name,zip,latitude,longitude,timezone_name,gmt_offset)\r\n VALUES\r\n ('{$ip}','{$sid}','{$user_id}','{$guest_id}','{$name}','{$url}','{$id}','{$file}','{$os}','{$browser}', " . TIME . ", " . TIME . ", '{$location['CountryCode']}', '{$location['CountryName']}', '{$location['RegionCode']}', '{$location['RegionName']}','{$location['City']}', '{$location['ZipPostalCode']}', '{$location['Latitude']}', '{$location['Longitude']}', '{$location['TimezoneName']}', '{$location['Gmtoffset']}')"); $user_localization_id = DB::get_last_id(); } $_SESSION['user_localization'] = array('user_localization_id' => $user_localization_id, 'id' => $id, 'guest_id' => $guest_id, 'name' => $name, 'time' => TIME, 'file' => $file, 'user_id' => $user_id, 'os' => $os, 'browser' => $browser); }
/** * Set the User geolocation and page */ function user_where_is_init($id, $link, $online_time = USER_ONLINE_TIME) { $file = basename($_SERVER['PHP_SELF']); $url = $_SERVER['REQUEST_URI']; $where_is = isset($_SESSION['where_is']) ? $_SESSION['where_is'] : null; $sid = session_id(); $browser = BROWSER . " " . BROWSER_VERSION; $os = BROWSER_OS; $ip = get_ip(); if (!$where_is) { $time = TIME - HOUR; DB::query("DELETE FROM " . DB_PREFIX . "user_where_is WHERE time < " . HOUR); } $user_where_is_id = $where_is ? $_SESSION['where_is']['user_where_is_id'] : DB::get_field("SELECT user_where_is_id FROM " . DB_PREFIX . "user_where_is WHERE sid='{$sid}'"); if ($user_id = $this->get_user_id()) { $guest_id = 0; $name = $this->get_user_field("name"); } else { $guest_id = isset($where_is['guest_id']) ? $where_is['guest_id'] : 1 + DB::get_field("SELECT guest_id FROM " . DB_PREFIX . "user_where_is ORDER BY guest_id DESC LIMIT 1;"); $name = _GUEST_ . " " . $guest_id; } if ($user_where_is_id) { DB::query("UPDATE " . DB_PREFIX . "user_where_is SET ip='{$ip}', user_id='{$user_id}', name='{$name}', url='{$url}', id='{$id}', file='{$file}', time='" . TIME . "', sid='{$sid}' WHERE user_where_is_id='{$user_where_is_id}'"); } else { if (!($location = ip_to_location($ip, $type = 'array'))) { $location = array('CountryCode' => null, 'CountryName' => null, 'RegionCode' => null, 'RegionName' => null, 'City' => null, 'ZipPostalCode' => null, 'Latitude' => null, 'Longitude' => null, 'TimezoneName' => null, 'Gmtoffset' => null); } DB::query("INSERT INTO " . DB_PREFIX . "user_where_is\n\t\t\t\t\t\t(ip,sid,user_id,guest_id,name,url,id,file,os,browser,time,time_first_click,country_code,country_name,region_code,region_name,city_name,zip,latitude,longitude,timezone_name,gmt_offset)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t('{$ip}','{$sid}','{$user_id}','{$guest_id}','{$name}','{$url}','{$id}','{$file}','{$os}','{$browser}', " . TIME . ", " . TIME . ", '{$location['CountryCode']}', '{$location['CountryName']}', '{$location['RegionCode']}', '{$location['RegionName']}','{$location['City']}', '{$location['ZipPostalCode']}', '{$location['Latitude']}', '{$location['Longitude']}', '{$location['TimezoneName']}', '{$location['Gmtoffset']}')"); $user_where_is_id = DB::get_last_id(); } $_SESSION['where_is'] = array('user_where_is_id' => $user_where_is_id, 'id' => $id, 'guest_id' => $guest_id, 'name' => $name, 'time' => TIME, 'file' => $file, 'user_id' => $user_id, 'os' => $os, 'browser' => $browser); }
public function getAccessToken() { //实例化数据库类并连接数据库 $db = new DB(); $db->open(); $accessToken = $db->get_field('wx_config', "_key='WX_ACCESS_TOKEN'", '_value'); $access = $accessToken ? json_decode($access, true) : array(); if ($access['expires_in'] < time()) { //已经过期 $app = self::getApp(); //获取appid和appsecret include_once HANDLE_DIR . 'tools.class.php'; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $app['appid'] . '&secret=' . $app['appsec']; $access = curl_get($url); $access_arr = json_decode($access, true); $access_arr['expires_in'] += time(); $data = array('_key' => 'WX_ACCESS_TOKEN', '_value' => json_encode($access_arr)); //保存 if (empty($accessToken)) { //需要创建 $db->insert('wx_config', $data); } else { //需要更新 $db->update('wx_config', $data, "_key='WX_ACCESS_TOKEN'"); } return $access_arr['access_token']; } else { return $access['access_token']; } }
<?php global $postObj; include_once HANDLE_DIR . 'db.class.php'; include_once HANDLE_DIR . 'tools.class.php'; //实例化数据库类并连接数据库 $db = new DB(); $db->open(); //用户消息 $data = array('from' => $postObj->FromUserName, 'to' => $postObj->ToUserName, 'text' => (string) $postObj->Recognition, 'media_id' => $postObj->MediaId, 'time' => $postObj->CreateTime, 'format' => $postObj->Format, 'message_id' => $postObj->MsgId); //消息存入数据库 $db->insert('wx_message_voice', $data); //获取默认回复 $default_key = 'ANSWER_DEFAULT_' . round(rand(1, 4)); $contentStr = $db->get_field("wx_config", "_key='{$default_key}'", "_value"); if (empty($data['text'])) { $contentStr = '您的消息我已经收到!'; } else { if (mb_substr($data['text'], 0, 2, 'utf-8') == '天气') { //天气查询 $contentStr = getWeather($data['text'], false); } else { if (mb_substr($data['text'], 0, 2, 'utf-8') == '快递') { //快递查询 $contentStr = doGetKuaiDi($data['text']); } else { if ($db->count('wx_answer', "_key='{$data['text']}'") > 0) { $contentStr = $db->get_field("wx_answer", "_key='{$data['text']}'", "_value"); } else { //机器人查询 $str = $data['text'];
//实例化数据库类并连接数据库 $db = new DB(); $db->open(); //用户表 $table = 'wx_user'; if (trim($postObj->Event) == 'subscribe') { $access_token = O('API')->getAccessToken(); $data = array('openid' => $postObj->FromUserName, 'subscribe_time' => $postObj->CreateTime, 'belong' => $_GET['id']); //获取用户详情 if (!empty($access_token)) { $userInfo = userInfo($postObj->FromUserName, $access_token); $data['nickname'] = $userInfo['nickname']; $data['sex'] = $userInfo['sex']; $data['language'] = $userInfo['language']; $data['city'] = $userInfo['city']; $data['province'] = $userInfo['province']; $data['country'] = $userInfo['country']; $data['headimgurl'] = $userInfo['headimgurl']; } //保存用户信息 $db->insert($table, $data); //欢迎词 $contentStr = $db->get_field('wx_config', "_key='ANSWER_WELCOME' and belong='{$_GET['id']}'", '_value'); exit(Tools::answer_text($postObj->ToUserName, $postObj->FromUserName, $contentStr)); } else { if (trim($postObj->Event) == 'unsubscribe') { $data = array('unsubscribe_time' => $postObj->CreateTime, 'status' => 0); //注销用户 $db->update($table, $data, "openid='{$postObj->FromUserName}' and status=1 and belong='{$_GET['id']}'"); } }