提交 cc8ea0da 编写于 作者: 李光春's avatar 李光春

- 更新请求门面

上级 12a9c96c
......@@ -34,6 +34,11 @@ use think\Facade;
* @method static bool isPut() 判断是否为PUT方式
* @method static bool isDelete() 判断是否为DELETE方式
* @method static bool isAjax() 判断是否为Ajax方式
* @method static bool isMobile() 判断是否为移动端访问
* @method static bool isWeXin() 判断是否微信内置浏览器访问
* @method static bool isAliPay() 判断是否支付宝内置浏览器访问
* @method static bool isQQ() 判断是否QQ内置浏览器访问
* @method static bool isQQBrowser() 判断是否QQ浏览器访问
* @method static string getWebsiteAddress() 获取域名地址
*/
class Requests extends Facade
......
......@@ -93,6 +93,80 @@ class Requests
return request()->isAjax();
}
/**
* 判断是否为移动端访问
* @return bool
*/
public function isMobile(): bool
{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) return true;
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
//找不到为flase,否则为true
if (isset($_SERVER['HTTP_VIA'])) return stristr(request()->server('HTTP_VIA'), "wap") ? true : false;
//判断手机发送的客户端标志
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = [
'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp',
'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi',
'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile', 'alipay'
];
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower(request()->server('HTTP_USER_AGENT')))) return true;
}
//协议法,因为有可能不准确,放到最后判断
if (isset($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') !== false) && (strpos(request()->server('HTTP_ACCEPT'), 'text/html') === false || (strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') < strpos(request()->server('HTTP_ACCEPT'), 'text/html')))) return true;
}
return false;
}
/**
* 判断是否微信内置浏览器访问
* @return bool
*/
public function isWeXin(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false) return true;
return false;
}
/**
* 判断是否支付宝内置浏览器访问
* @return bool
*/
public function isAliPay(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'Alipay') !== false) return true;
return false;
}
/**
* 判断是否QQ内置浏览器访问
* @return bool
*/
public function isQQ(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) if (strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false) return true;
return false;
}
/**
* 判断是否QQ浏览器访问
* @return bool
*/
public function isQQBrowser(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) {
if (strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false) return false;
else return true;
}
return false;
}
/**
* 获取域名地址
* @return string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册