短网址生成接口

请求参数(Body)

字段 类型 是否必须 说明
token string 必须 由数字和字母组成的32位字符
longurl string 必须 要缩短的长网址
format string 调用格式,值为json/text/jsonp或不传,不传时返回数据为json
  • PHP
  • JavaScript
<?php
    $geturl = 'https://h5ma.com/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','https://h5ma.com/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 格式
请求:https://h5ma.com/api/create?format=text&token=7535c17a93a7d62bafe67257f516c9d1&longurl=http://www.baidu.com
返回:https://h5ma.com/1c
JSON 格式
请求:https://h5ma.com/api/create?format=json&token=7535c17a93a7d62bafe67257f516c9d1&longurl=http://www.baidu.com
返回:{"code":1,"type":"url","longurl":"http://www.baidu.com","short":"https://h5ma.com/1f","date":"03-10-2020 12:32:25"}
JSONP 格式
请求:https://h5ma.com/api/create?format=jsonp&callback=callbackname&token=7535c17a93a7d62bafe67257f516c9d1&longurl=http://www.baidu.com
返回:callbackname({"code":1,"type":"url","longurl":"http://www.baidu.com","short":"https://h5ma.com/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 格式
请求:https://h5ma.com/api/query?format=text&dwz=https://h5ma.com/d
返回:http://www.pc.com
JSON 格式
请求:https://h5ma.com/api/query?format=json&dwz=https://h5ma.com/d
返回:{"code":"1","longurl":"http://www.pc.com","short":"https://h5ma.com/d"}
JSONP 格式
请求:https://h5ma.com/api/query?format=jsonp&callback=callbackname&dwz=https://h5ma.com/d
返回:callbackname({"code":"1","longurl":"http://www.pc.com","short":"https://h5ma.com/d"})