<?php
/**
 * 登录服务
 * 登录基础操作权限
 * @author DouBin
 * @Date: 2021/07/14
 * @Time: 下午17:50
 * @Email: db@sudianwang.com
 * @version 1.0
 * @copyright BlueCity
 */

namespace App\Services;

use BlueCity\Core\Service\Service;
use Illuminate\Support\Facades\Log;
use phpDocumentor\Reflection\Types\Integer;

class LoginService extends Service{
   public static function ipDress ( $ip ){
		$url = "https://restapi.amap.com/v5/ip?parameters&key=bf7919b601432722e4353ba6358e9c10&type=4&ip=".$ip;
		$result = file_get_contents($url);
		$arr = json_decode($result,true);
		if($arr['status'] == '1'){
			return $arr['province']." ".$arr['city']." ".$arr['district']." ".$arr['isp'];
		}else{
			return '';
		}
	}
	/**|----------------------------------------------------------------------
     * @name 判定当前登录的浏览器以及操作系统
     * @param $browser   登录设备信息
     * @param Request $request
     * @return json
     * @author dou <2021-07-06 17:18>
     * |----------------------------------------------------------------------
     */
	public static function judgeEquipment ( $browser ){
		//判定浏览器
	    if (stripos($browser, "Maxthon") && stripos($browser, "MSIE")) {
	        $visitor_browser = "Maxthon(Microsoft IE)";
	    } elseif (stripos($browser, "Maxthon 2.0")) {
	        $visitor_browser = "Maxthon 2.0";
	    } elseif (stripos($browser, "Maxthon")) {
	        $visitor_browser = "Maxthon";
	    } elseif (stripos($browser, "MSIE 9.0")) {
	        $visitor_browser = "MSIE 9.0";
	    } elseif (stripos($browser, "MSIE 8.0")) {
	        $visitor_browser = "MSIE 8.0";
	    } elseif (stripos($browser, "MSIE 7.0")) {
	        $visitor_browser = "MSIE 7.0";
	    } elseif (stripos($browser, "MSIE 6.0")) {
	        $visitor_browser = "MSIE 6.0";
	    } elseif (stripos($browser, "MSIE 5.5")) {
	        $visitor_browser = "MSIE 5.5";
	    } elseif (stripos($browser, "MSIE 5.0")) {
	        $visitor_browser = "MSIE 5.0";
	    } elseif (stripos($browser, "MSIE 4.01")) {
	        $visitor_browser = "MSIE 4.01";
	    } elseif (stripos($browser, "MSIE")) {
	        $visitor_browser = "MSIE 较高版本";
	    } elseif (stripos($browser, "NetCaptor")) {
	        $visitor_browser = "NetCaptor";
	    } elseif (stripos($browser, "Netscape")) {
	        $visitor_browser = "Netscape";
	    } elseif (stripos($browser, "Chrome")) {
	        $visitor_browser = "Chrome";
	    } elseif (stripos($browser, "Lynx")) {
	        $visitor_browser = "Lynx";
	    } elseif (stripos($browser, "Opera")) {
	        $visitor_browser = "Opera";
	    } elseif (stripos($browser, "Konqueror")) {
	        $visitor_browser = "Konqueror";
	    } elseif (stripos($browser, "Mozilla/5.0")) {
	        $visitor_browser = "Mozilla";
	    } elseif (stripos($browser, "Firefox")) {
	        $visitor_browser = "Firefox";
	    } elseif (stripos($browser, "U")) {
	        $visitor_browser = "Firefox";
	    } else {
	        $visitor_browser = "其它";
	    }

		//判定操作系统
		$name = "未确认";
		$version = "未确认";
		if (stripos($browser, "win")) {
	        $name = 'Windows';
	        if (stripos($browser, "windows nt 5.0")) {
		        $version = '2000';
		    }elseif (stripos($browser, "windows nt 5.1")){
		    	 $version = 'XP';
		    }elseif (stripos($browser, "windows nt 6.0")){
		    	 $version = 'Vista';
		    }elseif (stripos($browser, "windows nt 6.1") || stripos($browser, "windows nt 7")){
		    	 $version = '7';
		    }elseif (stripos($browser, "windows nt 6.2") || stripos($browser, "windows nt 8")){
		    	 $version = '8';
		    }elseif (stripos($browser, "windows nt 6.3")){
		    	 $version = '8.1';
		    }elseif (stripos($browser, "windows nt 6.2") || stripos($browser, "windows nt 10")){
		    	 $version = '10';
		    }
	    }elseif ( stripos($browser, "iphone") ){
	    	$name = 'Iphone';
	    }elseif ( stripos($browser, "mac") ){
	    	$name = 'mac';
	    }elseif ( stripos($browser, "x11") || stripos($browser, "unix") || stripos($browser, "sunname") || stripos($browser, "bsd") ){
	    	$name = 'Unix';
	    }elseif ( stripos($browser, "linux") ){
		    if ( stripos($browser, "Android") ){
			    $name = 'Android';
		    }else{
			    $name = 'linux';
		    }
	    }
	    return  "浏览器：".$visitor_browser.";操作系统：".$name." 版本：".$version;
	}
	/**|----------------------------------------------------------------------
     * @name ip白名单
     * @param Request $request
     * @return json
     * @author dou <2021-07-14 18:18>
     * |----------------------------------------------------------------------
     */
    public static function getIp ( ){
    	return ['111.160.158.70','192.168.1.140','192.168.1.205','192.168.1.98','192.168.1.99','127.0.0.1','49.7.59.227','49.7.59.227'];
    }
}
