<?php $uid = 28; $vhost = 'asdfw'; $token = getToken($uid, $vhost); print_r($token); //获取token function getToken($uid, $vhost){ $skey = 'wEBxca5X9NArc5Hq'; $time = time(); $vdata = array( 'uid'=>$uid, 't'=>$time, 'skey'=>$skey, 'sign'=>md5(md5($uid.$skey).$time), 'vhost'=>$vhost ); $url = 'http://192.168.1.210/api2/site/index.php/token'; //sfvft3jdsutl7sebsa0d95padn return curlCall($url, $vdata)['token']; } // $domainlist = getDomainList($uid, $vhost, $token); // print_r($domainlist); //获取域名列表 function getDomainList($uid, $vhost, $token){ $vdata = array( 'uid' => $uid, 'vhost'=>$vhost, 'token'=>trim($token) ); $url = 'http://192.168.1.210/api2/site/index.php/domain/list'; return curlCall($url, $vdata); } // $domainlist = addNewDomain($uid, $vhost, $token, 'test.com', '4.3.2.1'); // print_r($domainlist); //添加新域名 function addNewDomain($uid, $vhost, $token, $domain, $host){ $vdata = array( 'uid' => $uid, 'vhost'=>$vhost, 'token'=>trim($token), 'domain'=>$domain, 'host'=>$host ); $url = 'http://192.168.1.210/api2/site/index.php/domain'; return curlCall($url, $vdata); } // $ret = delDomainById($uid, $vhost, $token,1); // print_r($ret); //删除域名 function delDomainById($uid, $vhost, $token, $id){ $vdata = array( 'uid' => $uid, 'vhost'=>$vhost, 'token'=>trim($token) ); $url = 'http://192.168.1.210/api2/site/index.php/domain/'.$id; return curlCall($url, $vdata, "DELETE"); } // $ret = editDomain($uid, $vhost, $token, "b.com", "3.3.3.3"); // print_r($ret); //修改域名 function editDomain($uid, $vhost, $token, $domain, $host){ $vdata = array( 'uid' => $uid, 'vhost'=>$vhost, 'token'=>trim($token), 'domain'=>$domain, 'host'=>$host ); $url = 'http://192.168.1.210/api2/site/index.php/domain/2'; return curlCall($url, $vdata, "PUT"); } $value = '[{"id":1,"or":1,"revers":1,"name":"url","value":{"url":"asdfww"}},{"id":2,"or":1,"revers":1,"name":"meth","value":{"val":"DELETE"}}]'; $ret = addAdvance($uid, $vhost, $token, $host, 1, 0, $value); print_r($ret); //添加高级设置 function addAdvance($uid, $vhost, $token, $host, $id, $jump_type, $value){ $vdata = array( 'uid' => $uid, 'vhost'=>$vhost, 'token'=>trim($token), 'host'=>$host, 'id'=>$id, 'jump_type'=>$jump_type, 'value'=>$value ); $url = 'http://192.168.1.210/api2/site/index.php/firewall/advanced'; return curlCall($url, $vdata, "post"); } function curlCall(String $url, array $vdata, String $method="post"){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $param = array(); foreach ($vdata as $key=>$val) { $arr = array_push($param, $key."=".$val); } $param = join("&",$param);//拼接后的参数原始字符串示例:uid=28&vhost=asdfw&token=o9b1fuccgurb7l6m5benjopase&domain=b.com&host=2.2.2.2 switch(strtolower($method)) { case 'get': curl_setopt($ch, CURLOPT_POSTFIELDS, $param); //设置请求体,提交数据包 break; case 'post': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); //设置请求体,提交数据包 break; case 'put': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); //设置请求体,提交数据包 break; case 'delete': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); //设置请求体,提交数据包 break; } curl_setopt($ch,CURLOPT_HEADER,0); $output = curl_exec($ch); if($output === FALSE ){ echo "CURL Error:".curl_error($ch); } curl_close($ch); return json_decode($output, true); }