-
Notifications
You must be signed in to change notification settings - Fork 9
/
belink.php
44 lines (39 loc) · 1.14 KB
/
belink.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
<?php
/**
* BeLink Shortener Controller
* @url <https://codecanyon.net/item/belink-ultimate-url-shortener/24354590>
* @author Titan Systems
*/
function shortenUrl($url, &$system){
/**
* Implement shortening here
* @return string:Success
* @return false:Failed
*/
$belinkUrl = "https://belink.vebto.com"; // The url of your belink site, don't add ending slash
$accessToken = "C73vOqDLEvOUVAmTF1Ejbm4IkGHcMnIcaSBENvSl"; // Access token from your belink account
$shorten = $system->guzzle->post("{$belinkUrl}/api/v1/link", [
"headers" => [
"accept" => "application/json",
"Content-Type" => "application/json",
"Authorization" => "Bearer {$accessToken}"
],
"json" => [
"type" => "direct",
"active" => true,
"long_url" => $url
],
"allow_redirects" => true,
"http_errors" => false
]);
if($shorten->getStatusCode() == 200):
try {
$decode = json_decode($shorten->getBody()->getContents(), true);
return isset($decode["link"]["short_url"]) ? $decode["link"]["short_url"] : false;
} catch(Exception $e){
return false;
}
else:
return false;
endif;
}