Azalea\LocationModel

LocationModel Location 地區(qū)信息服務(wù)模塊類

?? 要使用 Azalea\LocationModel 必須在配置中聲明使用 $config['node-beauty']['location'] = 1


?? LocationModel 構(gòu)造函數(shù)已私有,無(wú)法通過(guò) new 方式實(shí)例化,僅通過(guò) 控制器模塊getModel 方法獲得

// in controller-action
$locationModel = $this->getModel('location');
$info = $locationModel->ip();  // get current ip info

LocationModel::get


獲取地區(qū)信息

array LocationModel::get ( string ...$id )
  • 參數(shù)
    $id - 地區(qū)代碼,可一次傳入多個(gè)地區(qū)代碼

  • 返回值
    地區(qū)信息數(shù)組

  • 范例

$result = $locationModel->get('440106', '440100', '000000');
// 返回
[
    '000000' => null,  // 不存在返回 null
    '440100' => [
      'name' => '廣州市',
      'fullname' => '廣東省廣州市'
      'post' => '',
      'tele' => '',
    ],
    '440106' => [
      'name' => '天河區(qū)',
      'fullname' => '廣東省廣州市天河區(qū)',
      'post' => '510000',
      'tele' => '020',
    ]
]

LocationModel::children


獲取下級(jí)地區(qū)

array LocationModel::children ( string $id = null )
  • 參數(shù)
    $id - 地區(qū)代碼,默認(rèn)為 null,即返回省份列表

  • 返回值
    子地區(qū)數(shù)組

  • 范例

$result = $locationModel->children();
// 返回
[
    '110000' => '北京市',
    '120000' => '天津市',
    ...
    '810000' => '香港特別行政區(qū)',
    '820000' => '澳門特別行政區(qū)'
]
$result = $locationModel->children('440100');
// 返回
[
    '440101' => '市轄區(qū)',
    '440102' => '東山區(qū)',
    ...
    '440183' => '增城市',
    '440184' => '從化市'
]

LocationModel::ip


獲取 IP 信息

array LocationModel::ip ( string $ip = null )
  • 參數(shù)
    $ip - IP,默認(rèn)為 當(dāng)前 IP 地址

  • 返回值
    IP 信息

  • 范例

$result = $locationModel->ip();  // 返回當(dāng)前 IP 信息
$result = $locationModel->ip('183.61.215.98');
// 返回
[
    'int' => '3074283362',
    'ip' => '183.61.215.98',
    'country' => '廣東省廣州市',
    'area' => '電信',
    'province' => '440000'
]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容