forked from BWmelon/qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
long2tiny.php
48 lines (39 loc) · 1.62 KB
/
long2tiny.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
44
45
46
47
48
<?php
if ($_GET['url_long']) {
$url_long = $_GET['url_long'];
} else {
echo "Longurl can not be empty.";
return;
}
// 短网址api接口
// 腾讯 http://shorturl.8446666.sojson.com/qq/shorturl?url=
// 新浪 http://shorturl.8446666.sojson.com/sina/shorturl?url= (备用)
$api = "http://shorturl.8446666.sojson.com/qq/shorturl?url=";
// 请求地址
$url = $api . $url_long;
// 腾讯
if ($api == "http://shorturl.8446666.sojson.com/qq/shorturl?url=") {
$res = json_decode(file_get_contents($url), true);
if ($res["status"] == 200) {
$tinyurl = $res["shorturl"];
} else {
// $tinyurl = 'Short URL generation failed, the reason may be that the request frequency exceeds 300 times / h, and the IP is blocked for one day.';
// 腾讯短网址被限制请求时使用新浪短网址
$res = json_decode(file_get_contents($url), true);
if ($res["status"] == 200) {
$tinyurl = str_replace("http", "https", $res["shorturl"]);
} else {
$tinyurl = 'Short URL generation failed, the reason may be that the request frequency exceeds 300 times / h, and the IP is blocked for one day.';
}
}
}
// 新浪
// if($api == "http://shorturl.8446666.sojson.com/sina/shorturl?url=") {
// $res = json_decode(file_get_contents($url), true);
// if($res["status"] == 200) {
// $tinyurl = str_replace("http", "https", $res["shorturl"]);
// } else {
// $tinyurl = 'Short URL generation failed, the reason may be that the request frequency exceeds 300 times / h, and the IP is blocked for one day.';
// }
// }
echo $tinyurl;