1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php function fixEncoding( $in_str )
{ $cur_encoding = mb_detect_encoding( $in_str ) ;
if ( $cur_encoding == "UTF-8" && mb_check_encoding( $in_str , "UTF-8" ))
return $in_str ;
else
return utf8_encode( $in_str );
} function getSign( $data , $key )
{ $dataList = array_keys ( $data );
sort( $dataList );
$a = array ();
foreach ( $dataList as $value )
{
$b = "$value=$data[$value]" ;
array_push ( $a , $b );
}
$s = join( "&" , $a );
$s1 = $s . $key ;
$s2 = fixEncoding( $s1 );
$sign = md5( $s2 );
return $sign ;
} function doPost( $url , $postData ){
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL, $url );
curl_setopt ( $ch , CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt ( $ch , CURLOPT_HEADER, 0 );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch , CURLOPT_POSTFIELDS, $postData );
$arr =curl_exec( $ch );
curl_close( $ch );
return $arr ;
} $username =******
$key =***********************
$cache_url = 'http://agent.webluker.com/api/cacherefresh/' ;
if ( $_SERVER [ 'REQUEST_METHOD' ]== 'POST' ){
$get_url =trim( $_POST [ 'url' ]);
$a = str_replace ( "\n" , " ," , $get_url );
$c = array (
"username" => "$username" ,
"refresh_url" => "['$a']" ,
"refresh_type" => "0" ,
);
$sign =getSign( $c , $key );
$reurl = $c [ 'refresh_url' ];
$postData = "username=$username&refresh_type=0&refresh_url=" . $reurl . "&sign=" . $sign ;
$result =doPost( $cache_url , $postData );
} ?> |
写这个脚本纯粹是为了减少工作量。公司目前在使用webluker这块CDN加速软件。当页面更新时,需要到webluker中刷新下页面。如果把刷新页面的工作给非技术部门同事去做的话必须提供webluker的账号密码才行。于是就出现了上面这段代码,提供个页面给他们使用且不提供密码。
本文转自 irow10 51CTO博客,原文链接:http://blog.51cto.com/irow10/1787211,如需转载请自行联系原作者