Route::group(['middleware' => ['DataValidation']], function(){
// 移动端主页
Route::get('meeting_move/{meetingId}', 'Move\MeetingMoveController@meeting_move'); //移动端详情页面
});
默认middleware
类名 DataValidation
222222
必须添加
333333
<?php
namespace App\Http\Middleware;
use Closure;
use App\Tools\CommonTool;
use App\Http\Controllers\H5\GetunionidController; //微信授权
class DataValidation
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (self::isMobileNew()) { // 判断是否是手机端
$user_agent = $_SERVER['HTTP_USER_AGENT']; //获取端
if (strpos($user_agent, 'MicroMessenger') !== false ) {// 判断是否微信浏览器,如果为微信浏览器,直接跳转到授权页面
echo "微信浏览器";exit;
// 进入手机端
// $meetingUrl = $request->getRequestUri(); //获取地址
// if(empty(session('uid'))){ //不为空直接进入 微信授权
// session('yun_wechat_url',$meetingUrl); //
// if (CommonTool::isHttps()) {// https访问还是http
// session(['yun_wechat_url' => secure_url($meetingUrl)]); //注册完成回到原来访问的页面
// return redirect()->intended(secure_url('getunionid')); //getunionid微信授权地址http访问
// } else {
// session(['yun_wechat_url' => url($meetingUrl)]);
// return redirect()->intended(url('getunionid')); //getunionid微信授权地址http访问
// }
// }
// return $next($request);
} else {
echo "移动其他端";exit;
// return $next($request);
}
}else{ //pc端
echo "进入pc端";exit;
}
}
// 判断是否是手机端
public function isMobileNew() {
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset($_SERVER['HTTP_VIA'])) {
// 找不到为flase,否则为true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
// 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = array('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','MicroMessenger');
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset ($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
}