1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // 应用公共文件
- header('Content-Type:text/html;Charset=utf-8');
- /**
- * 保存后台用户行为
- * @param string $remark 日志备注
- */
- function insert_admin_log($remark)
- {
- db('user_log')->insert([
- 'user_id' => session('id'),
- 'uname' => session('uname'),
- 'useragent' => request()->server('HTTP_USER_AGENT'),
- 'ip' => request()->ip(),
- 'url' => request()->url(true),
- 'method' => request()->method(),
- 'type' => request()->type(),
- 'param' => json_encode(request()->param()),
- 'remark' => $remark,
- 'create_time' => time(),
- ]);
- }
- /**
- * 获取用户真实 IP
- */
- function getIP()
- {
- static $realip;
- if (isset($_SERVER)){
- if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
- $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
- } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
- $realip = $_SERVER["HTTP_CLIENT_IP"];
- } else {
- $realip = $_SERVER["REMOTE_ADDR"];
- }
- } else {
- if (getenv("HTTP_X_FORWARDED_FOR")){
- $realip = getenv("HTTP_X_FORWARDED_FOR");
- } else if (getenv("HTTP_CLIENT_IP")) {
- $realip = getenv("HTTP_CLIENT_IP");
- } else {
- $realip = getenv("REMOTE_ADDR");
- }
- }
- return $realip;
- }
- //获取城市所在天气情况
- function tianqi($chengshi)
- {
- $url = 'http://wthrcdn.etouch.cn/weather_mini?city='.urlencode($chengshi);
- $html = file_get_contents($url);
- $jsondata = gzdecode($html);
- $data=json_decode($jsondata,true);
- $arr=array();
- $arr['chengshi']=$data['data']['city'];
- $dangtian=$data['data']['forecast'][0];
- $arr['gaowen']= str_replace("高温 ",null,$dangtian['high']);
- $arr['diwen']= str_replace("低温 ",null,$dangtian['low']);
- $arr['tianqi']=$dangtian['type'];
- $arr['fengxiang'] = $dangtian['fengxiang'];
- $arr['time'] =date("Y-m-d H:i:s");
- return $arr;
- }
|