zoukankan      html  css  js  c++  java
  • 站点防火墙频率api php案例

    <?php
    $apiHost = "http://35.201.139.124/api2/site/index.php";
    $router = "token";
    $url = $apiHost."/".$router;
    $uid = 	26751;
    $skey = "9rSpuRKTpWxR8Daq";
    $vhost = "test";
    
    $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>";
    
    $siteRouter = "firewall/ipfrequency";
    $url = $apiHost."/".$siteRouter;
    $id = 1;
    $param = sprintf('token=%s&uid=%d&vhost=%s&id=%d',$token,$uid,$vhost,$id);
    $response = httpRequest($url, $param,"DELETE");
    $responseArray = json_decode($response,true);
    if ($responseArray['status']['code'] != 1) {
    	die("delete   request failed error=".$responseArray['status']['message']);
    }
    die("delete success");
    
  • 相关阅读:
    推荐下自己的开源框架:DataMapFramework
    真的能无师自通吗?JAVA学习指导系列
    再回首,工作的第一个十年
    2个DataSet中的数据传递问题,请高手们多多指教。
    数据结构小结
    CDQZ_Training 2012524 词编码
    PowerDesigner显示Comment注释
    DDD基本元素
    使用FluorineFx.NET更新FMS中的SharedObject
    如何取消页面缓存
  • 原文地址:https://www.cnblogs.com/kangleweb/p/9456195.html
Copyright © 2011-2022 走看看