zoukankan      html  css  js  c++  java
  • 站点防火墙api,增加黑名单IP接口,增加用post,修改用put,php案例

    <?php
    $apiHost = "http://192.168.1.198/api2/site/index.php";
    $router = "token";
    $url = $apiHost."/".$router;
    $uid = 1004;
    $skey = "test";
    $vhost = "four.com";
    
    $t = time();
    $sign = md5(md5($uid.$skey).$t);
    
    $param = sprintf("uid=%d&t=%d&sign=%s&vhost=%s",$uid,$t,$sign,$vhost);
    
    function httpRequest($url,$param,$method="POST")
    {
    	$ch = curl_init($url);
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
    	
    	curl_setopt($ch, CURLOPT_HEADER, true);
    	curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    	$response = curl_exec($ch);
    	
    	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    	$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    	$err =  curl_error($ch);
    	curl_close($ch);
    	$body = substr($response,$headerSize);
    	if($httpCode > 400){
    		return false;
    	}
    	return  $body; 
    }
    //获取token
    $response = httpRequest($url,$param);
    $responseArray = json_decode($response,true);
    if ($responseArray['status']['code'] != 1) {
    	die("token request failed error=".$responseArray['status']['message']);
    }
    $token = $responseArray['token'];
    echo "token=".$token."<br>";
    
    //调用增加黑名单IP接口,增加用post,修改用put
    $siteRouter = "firewall/blackip";
    
    $url = $apiHost."/".$siteRouter;
    $ip = "192.168.1.21";
    $param = sprintf('token=%s&uid=%d&vhost=%s&ip=%s',$token,$uid,$vhost,$ip);
    
    $response = httpRequest($url, $param);
    $responseArray = json_decode($response,true);
    if ($responseArray['status']['code'] != 1) {
    	die("firewall blackip  request failed error=".$responseArray['status']['message']);
    }
    echo "add firewall black ip success id=".$responseArray['id'];
    
  • 相关阅读:
    从 0 配置 webpack(一)
    Redux
    React Hooks 全解(二)
    日本人要把核污水排进大海,我突然想到几个问题
    突然发现,我的代码还花花绿绿的,挺好看的
    Ghidra ,改道吧,我也准备改道这玩意了
    语音控制?这,看起来很眼熟。
    winafl 工具的编译
    关于 TX 的 WeGame 的一点疑问
    新年的第一个随笔,随便写写吧
  • 原文地址:https://www.cnblogs.com/kangleweb/p/9456168.html
Copyright © 2011-2022 走看看