forked from insoxin/API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpand.php
43 lines (39 loc) · 942 Bytes
/
expand.php
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
<?php
$shortUrl=trim($_GET['url']);
// $shortUrl=$_GET['u'];
include "TinyUrl.class.php";
$tu=new TinyUrl();
$tu->url=$shortUrl;
//分辨出 接收的长网址的类型
preg_match('/.*(dwz.cn|t.cn|126.am).*/', $shortUrl, $matche);
if(!isset($matche[1])){
responseMesg(0,'长网址不存在,暂时只支持t.cn,126.am,dwz.cn');
}
switch ($matche[1]){
case 't.cn':
$longUrl=$tu->expandtcn();
break;
case 'dwz.cn':
$longUrl=$tu->expandDwz();
break;
case '126.am':
$longUrl=$tu->expand126am();
break;
default:
responseMesg(0,'长网址不存在,暂时只支持t.cn,126.am,dwz.cn');
break;
}
if(!$longUrl){
responseMesg(0,$tu->error);
}
responseMesg(1,'success',$longUrl);
//返回json信息
function responseMesg($code=0,$message,$data=null){
$arr=array();
$arr['code']=$code;
$arr['message']=$message;
$arr['data']=$data;
echo json_encode($arr);
//结束
exit();
}