[PHP] 純文本查看 復制代碼
<?php
/*
技術支持 QQ:3188639 QQ交流群:281079920
官方網站 http://www.5566wy.com/
獲取授權 http://www.5566wy.com/plugin.php?id=xinxiuvip_license:accredit
接口開發手冊 http://www.5566wy.com/forum.php?mod=viewthread&tid=574
嚴禁反編譯、逆向等任何形式的侵權行為,違者將追究法律責任!
*/
#========================================
#以下兩行代碼,用于開發環境下代碼錯誤提示,可根據提示信息進行代碼檢查,無誤后即可注釋掉!
//ini_set("display_errors", "on");
//error_reporting(E_ALL);
#========================================
#========================================
#防止游客直接輸入網址進行訪問,權限檢測,勿動!!!
if (! defined('IN_DISCUZ')) {
exit('Access Denied');
}
#========================================
#========================================
#引入核心系統類,勿刪!!!
C::import('class/plugin','plugin/xinxiuvip_network_plugin',false);
require_once DISCUZ_ROOT.'./config/config_ucenter.php';
require_once DISCUZ_ROOT.'./uc_client/client.php';
#========================================
#========================================
#如何引入自定義系統類?
#1、將自定義核心類、第三方核心類上傳至extend文件夾下;
#2、通過 C::import 、 require_once 兩種引入形式引入第三方核心類;
#3、在下方 public function dev_demo1($demo1,$demo2) 方法中實例化后使用 $new-> 進行調用。
#========================================
class function_ip extends class_plugin
{
public $action_all = array('ip_cha','ip_demo');//所有接口必填,用逗號隔開!!!除以下key、adminkey所包含以外,未包含的接口都是通過token令牌進行訪問。
public $function_action_key = array('ip_cha','ip_demo');//使用key密鑰訪問的接口
public $function_action_adminkey = array();//使用管理密鑰adminkey訪問的接口
/**
* 構造方法 __construct() 是在實例化對象時被自動調用
* 用途:可以用于初始化程序(可以給成員屬性賦值,也可以調用成員方法)
*/
public function __construct(){
$this->plugin_status();//判斷插件后臺開啟狀態,勿刪!
parent::__construct();//注意這里和接口二次開發不同
}
#========================================
#此處為標準類方法,可根據DISCUZ、新秀網絡驗證內置函數進行調用,也可使用PHP官方函數進行操作。
public function ip_cha($ip){
#-具體DISCUZ內置函數、新秀網絡驗證內置函數、PHP函數,論壇相應帖子有專門介紹。
$tinyipfile = DISCUZ_ROOT.'./data/ipdata/tinyipdata.dat';
$data = $this->convertip_tiny($ip,$tinyipfile);
$data_array = array(
'ip'=>$ip,
'dizhi'=>$data,
);
$data ? xx_client::json_output(200,'ok',$data_array): $this->json_output(400,'請檢查IP地址是否正確!');
#-具體DISCUZ內置函數、新秀網絡驗證內置函數、PHP函數,論壇相應帖子有專門介紹。
}
#========================================
#========================================
#演示方法設置鉤子
public function ip_demo($ip){
#========================================
#嵌入插件開發鉤子,注意:此擴展方法在應用中心擴展文件中使用‘extend_plugin.php’;
xx_client::class_hook('hook_ip_ip_cha',array('ip'=>$ip));
/*
* 下面是插件拓展對應的方法
* 注意class_hook中的'hook_ip_ip_cha' 就是擴展文件中的方法名!
*
public function hook_ip_ip_cha($data){
var_dump($data,'plugin');
}
*/
#========================================
}
#========================================
function convertip_tiny($ip, $ipdatafile) {//獲取ip地址的方法類
static $fp = NULL, $offset = array(), $index = NULL;
$ipdot = explode('.', $ip);
$ip = pack('N', ip2long($ip));
$ipdot[0] = (int)$ipdot[0];
$ipdot[1] = (int)$ipdot[1];
if($fp === NULL && $fp = @fopen($ipdatafile, 'rb')) {
$offset = @unpack('Nlen', @fread($fp, 4));
$index = @fread($fp, $offset['len'] - 4);
} elseif($fp == FALSE) {
return '- Invalid IP data file';
}
$length = $offset['len'] - 1028;
$start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
$index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "\x0");
$index_length = @unpack('Clen', $index[$start + 7]);
break;
}
}
@fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
if($index_length['len']) {
return '- '.@fread($fp, $index_length['len']);
} else {
return '- Unknown';
}
}
/**
* 析構方法 __destruct() 是在對象被銷毀時自動調用
* 用途:可以進行資源的釋放操作或文件的關閉操作或信息保存操作
*/
public function __destruct()
{
return parent::__destruct(); // TODO: Change the autogenerated stub
}
}