ShortURLDemo
代码示列
获取短网址列表(get请求)
<?php
$url = "https://service.mysubmail.com/shorturl";
$appid = "";
$appkey = "";
//GET
$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['short_url'] = "http://suburl.cn/9iLyT4";
$api = $url."?".http_build_query($post_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);
创建短网址(post请求)
<?php
$url = "https://service.mysubmail.com/shorturl";
$appid = "";
$appkey = "";
//POST
$post_data['url'] = "https://www.mysubmail.com";
$post_data['group'] = "f36cb0d3685490e69676d1672b55a0f1";
$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);
更新短链接(put请求)
<?php
$url = "https://service.mysubmail.com/shorturl";
$appid = "";
$appkey = "";
$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['short_url'] = "http://link.wiki/l3/8SSCaH";
$post_data['url'] = "http://www.mysubmail.com/service";
//PUT
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);
删除短网址(delete请求)
<?php
$url = "https://service.mysubmail.com/shorturl";
$appid = "";
$appkey = "";
//DELETE
$post_data['appid'] = $appid;
$post_data['signature'] = $appkey;
$post_data['short_url'] = "http://link.wiki/l3/8SSCaH";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
print_r($output);