利用网易免费短地址接口开发的短网址缩短服务
演示地址:
http://3.tbip.sinaapp.com/
伪静态规则
RewriteEngine on
RewriteRule ^(.*)$ index.php?id=$1 [L]
-
define('REWRITE', '0'); //是否启用伪静态 1为启用0为不启用
- define('IS_SINA', '0'); //是否sina sae 1为启用0为不启用
- define('API_KEY', '2e409ff7a967418aa5e4dd15051702ba'); //API key请自行申请
- $weburl=getenv('SERVER_NAME').dirname(getenv('SCRIPT_NAME'));
- $weblink=REWRITE?"http://".$weburl."/":"http://".$weburl."/?";
- if($_GET['url']){
- $data=duanurl($_GET['url']);
- $shorturls=str_replace('126.am/',$weblink,$data->url);
- }else if(count($_GET)>0){
- $headurl=getenv("QUERY_STRING");echo "";
- }
- ?>?
-
-
- 网易免费短地址
-
-
-
-
-
-
-
-
-
function ob_gzip($content){
- if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
- $content = gzencode($content,9);
- header("Content-Encoding: gzip");
- header("Vary: Accept-Encoding");
- header("Content-Length: ".strlen($content));
- }
- return $content;
- }
- function duanurl($url)
- {
- if(IS_SINA){
- $f = new SaeFetchurl();
- $f->setMethod("post");
- $f->setPostData(array("key"=>API_KEY,"longUrl"=>$url));
- $content=$f->fetch("http://126.am/api!shorten.action");
- if($f->errno() == 0) {
- $return =$content;
- }else{$return = $f->errmsg();}
- }else{
- $ch=curl_init();
- curl_setopt_array(
- $ch,
- array(
- CURLOPT_URL=>'http://126.am/api!shorten.action',
- CURLOPT_RETURNTRANSFER=>true,
- CURLOPT_POST=>true,
- CURLOPT_POSTFIELDS=>'key='.API_KEY.'&longUrl='.$url
- ));
- $content=curl_exec($ch);
- if(curl_errno($ch)) $return=curl_error($ch);
- else $return=$content;
- curl_close($ch);
- }return json_decode($return);
- }ob_end_flush(); ?>
复制代码
|