forked from soxft/UrlShorting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
63 lines (60 loc) · 1.38 KB
/
api.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once "app/core.php";
require_once "app/ip.php";
$domain = $_POST['url'];
$passmessage = $_POST['message'];
$shorturl = $_POST['shorturl'];
$passwd = $_POST['passwd'];
//替换原网址中的&&防止出错
if (empty($domain) && empty($passmessage)) {
$data = array(
'code' => '1001'
);
} else {
if (!empty($domain)) {
//如果判断为短域 (短域优先)
$arr = Urlshorting($domain, "shorturl", $passwd,$shorturl);
if ($arr[0] !== 200) {
$data = array(
'code' => $arr[0]
);
} elseif ($arr[0] == 200) {
if (empty($arr[2])) {
$data = array(
'code' => '200',
'shorturl' => $arr[1]
);
} else {
$data = array(
'code' => '200',
'shorturl' => $arr[1],
'passwd' => $arr[2]
);
}
}
} else {
//如果判断为密语
$arr = Urlshorting($passmessage, "passmessage", $passwd, $shorturl);
if ($arr[0] !== 200) {
$data = array(
'code' => $arr[0]
);
} elseif ($arr[0] == 200) {
if (empty($arr[2])) {
$data = array(
'code' => '200',
'shorturl' => $arr[1]
);
} else {
$data = array(
'code' => '200',
'shorturl' => $arr[1],
'passwd' => $arr[2]
);
}
}
}
}
header('Content-type:text/json');
echo json_encode($data);
exit;