请求参数(Body)
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
token | string | 必须 | 由数字和字母组成的32位字符 |
longurl | string | 必须 | 要缩短的长网址 |
format | string | 否 | 调用格式,值为json/text/jsonp或不传,不传时返回数据为json |
<?php $geturl = 'http://kkurl.cn/api/create'; $param = http_build_query([ 'token' => '你的Token' ,'longurl' => '你的长网址' ,'format' => 'text' ]); $opts = [ 'http' => array( 'method' => "POST", 'header' => "Content-type: application/x-www-form-urlencoded\r\n". "Content-length:".strlen($param)."\r\n" . "Cookie: foo=bar\r\n" . "\r\n", 'content' => $param, ), "ssl" => array( "verify_peer" => false, "verify_peer_name" => false, ) ]; $dwz = file_get_contents($geturl, $param, stream_context_create($opts)); echo $dwz; ?>
var ajax = new XMLHttpRequest(); var token = 'd3be719c083dd26e0799ef70461baf36'; var longUrl = 'http://test.com/page/doc.html'; ajax.open('post','http://kkurl.cn/api/create', 'true'); ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); // 发送请求 var Post = 'token='+token+'&longurl='+encodeURIComponent(longUrl)+'&format=text'; ajax.send(Post); ajax.onreadystatechange = function () { if (ajax.readyState === 4 && ajax.status === 200) { //获取缩短后的网址 console.log(ajax.responseText); } }
返回参数(Body)
字段 | 类型 | 说明 |
---|---|---|
code | string | 处理结果:'1'代表成功 |
msg | string | 返回描述 |
short | string | 生成的短链接,如果生成失败,则返回空 |
请求示例
TEXT 格式 |
---|
请求:http://kkurl.cn/api/create?format=text&token=(联系客服索要)&longurl=urlencode('http://www.baidu.com') |
返回:http://kkurl.cn/1c |
JSON 格式 |
---|
请求:http://kkurl.cn/api/create?format=json&token=(联系客服索要)&longurl=urlencode('http://www.baidu.com') |
返回:{"code":1,"type":"url","longurl":"http://www.baidu.com","short":"http://kkurl.cn/1f","date":"03-10-2020 12:32:25"} |
JSONP 格式 |
---|
请求:http://kkurl.cn/api/create?format=jsonp&callback=callbackname&token=(联系客服索要)&longurl=urlencode('http://www.baidu.com') |
返回:callbackname({"code":1,"type":"url","longurl":"http://www.baidu.com","short":"http://kkurl.cn/1f","date":"03-10-2020 12:33:08"}) |
请求参数(Body)
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
dwz | string | 必须 | 由数字和字母组成的32位字符 |
format | string | 否 | 调用格式,值为json/text/jsonp或不传,不传时返回数据为json |
返回参数(Body)
字段 | 类型 | 说明 |
---|---|---|
code | string | 处理结果:'1'代表成功 |
msg | string | 返回描述 |
short | string | 还原的长链接,如果还原失败,则返回空 |
请求示例
TEXT 格式 |
---|
请求:http://kkurl.cn/api/query?format=text&dwz=http://kkurl.cn/d |
返回:http://www.pc.com |
JSON 格式 |
---|
请求:http://kkurl.cn/api/query?format=json&dwz=http://kkurl.cn/d |
返回:{"code":"1","longurl":"http://www.pc.com","short":"http://kkurl.cn/d"} |
JSONP 格式 |
---|
请求:http://kkurl.cn/api/query?format=jsonp&callback=callbackname&dwz=http://kkurl.cn/d |
返回:callbackname({"code":"1","longurl":"http://www.pc.com","short":"http://kkurl.cn/d"}) |