• 网址缩短接口
  • 网址还原接口
  • 批量缩短接口
短网址生成接口
  • 请求地址:

    https://dwz.mk/api/create

  • 请求方式:

    any

  • Content-Type:

    application/x-www-form-urlencoded

    或者

    multipart/form-data

  • 请求参数

    字段 类型 是否必选 说明 示例
    longUrl string 长网址 https://www.alapi.net
  • 请求示例

    • JAVA
    • JavaScript
    • PHP
    • Python
    //在里面存放任意的代码
    
    import com.google.gson.Gson;
    import com.google.gson.annotations.SerializedName;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class DWZMK {
        final static String CREATE_API = "https://dwz.mk/api/create";
    
        /**
         * 创建短网址
         *
         * @param longUrl 长网址:即原网址
         * @return 成功:短网址
         * 返回:错误信息
         *
         */
        public static String createShortUrl(String longUrl) {
            String params = "longUrl="+longUrl;
            BufferedReader reader = null;
            try {
                // 创建连接
                URL url = new URL(CREATE_API);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                connection.setUseCaches(false);
                connection.setInstanceFollowRedirects(true);
                connection.setRequestMethod("POST"); // 设置请求方式
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置发送数据的格式
                // 发起请求
                connection.connect();
                OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码
                out.append(params);
                out.flush();
                out.close();
                // 读取响应
                reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
                String line;
                String res = "";
                while ((line = reader.readLine()) != null) {
                    res += line;
                }
                reader.close();
                // 抽取生成短网址
                UrlResponse urlResponse = new Gson().fromJson(res, UrlResponse.class);
                if (urlResponse.getErrMsg() == "") {
                    return urlResponse.getUrl();
                }
                return urlResponse.getErrMsg(); // TODO:自定义错误信息
            } catch (IOException e) {
                // TODO
                e.printStackTrace();
            }
            return ""; // TODO:自定义错误信息
        }
    
        public static void main(String[] args) {
            String res = createShortUrl("你的长网址");
            System.out.println(res);
        }
    
        class UrlResponse {
            @SerializedName("errMsg")
            private String errMsg;
            @SerializedName("url")
            private String url;
    
            public String getErrMsg() {
                return this.errMsg;
            }
    
            public void setErrMsg(String errMsg) {
                this.errMsg = errMsg;
            }
    
            public String getUrl() {
                return this.url;
            }
    
            public void setUrl(String url) {
                this.url = url;
            }
        }
    }
    var ajax = new XMLHttpRequest();
    var longUrl = '你的长网址';
    
    ajax.open('post','https://dwz.mk/api/create', 'true');
    
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    // 发送请求
    ajax.send(JSON.stringify({
        longUrl: longUrl,
    }));
    
    ajax.onreadystatechange = function () {
        if (ajax.readyState === 4 && ajax.status === 200) {
            // 获取缩短后的网址
            console.log(ajax.responseText);
        }
    }
    $host = 'https://dwz.mk';
    $path = '/api/create';
    $url = $host . $path;
    $method = 'POST';
    $content_type = 'application/x-www-form-urlencoded';
    
    
    // TODO:设置待注册长网址
    $longUrl = "你的长网址";
    $bodys = array('longUrl'=>$longUrl);
    
    // 配置headers
    $headers = array('Content-Type:'.$content_type);
    
    // 创建连接
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
    
    // 发送请求
    $response = curl_exec($curl);
    curl_close($curl);
    
    // 读取响应
    var_dump($response);
                                                            
        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        import requests
        import json
    
        host = 'https://dwz.mk'
        path = '/api/create'
        url = host + path
        method = 'POST'
        content_type = 'application/x-www-form-urlencoded'
    
    
    
        # TODO:设置待创建的长网址
        bodys = {'longUrl':'你的长网址'}
    
        # 配置headers
        headers = {'Content-Type':content_type, 'Token':token}
    
        # 发起请求
        response = requests.post(url=url, data=bodys, headers=headers)
    
        # 读取响应
        print(response.text)
                                                            
  • 响应结果示例:

    
    {
    "url":"https://dwz.mk/xwd1d",
    "errMsg":""
    }
    
     
  • Content-Type:

    字段 类型 说明
    url string 生成的短网址
    errMsg string 错误信息,生成失败才有值,默认为空字符串
短网址还原接口
  • 请求地址:

    https://dwz.mk/api/query

  • 请求方式:

    any

  • Content-Type:

    application/x-www-form-urlencoded

    或者

    multipart/form-data

  • 请求参数

    字段 类型 是否必选 说明 示例
    shortUrl string 短网址 https://dwz.mk/adas
  • 请求示例

    • JAVA
    • JavaScript
    • PHP
    • Python
    //在里面存放任意的代码
    
    import com.google.gson.Gson;
    import com.google.gson.annotations.SerializedName;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class DWZMK {
        final static String CREATE_API = "https://dwz.mk/api/query";
    
        /**
         * 创建短网址
         *
         * @param longUrl 长网址:即原网址
         * @return 成功:短网址
         * 返回:错误信息
         *
         */
        public static String querytLongUrl(String shortUrl) {
            String params = "shortUrl="+shortUrl;
            BufferedReader reader = null;
            try {
                // 创建连接
                URL url = new URL(CREATE_API);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                connection.setUseCaches(false);
                connection.setInstanceFollowRedirects(true);
                connection.setRequestMethod("POST"); // 设置请求方式
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // 设置发送数据的格式
                // 发起请求
                connection.connect();
                OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码
                out.append(params);
                out.flush();
                out.close();
                // 读取响应
                reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
                String line;
                String res = "";
                while ((line = reader.readLine()) != null) {
                    res += line;
                }
                reader.close();
                // 抽取生成短网址
                UrlResponse urlResponse = new Gson().fromJson(res, UrlResponse.class);
                if (urlResponse.getErrMsg() == "") {
                    return urlResponse.getUrl();
                }
                return urlResponse.getErrMsg(); // TODO:自定义错误信息
            } catch (IOException e) {
                // TODO
                e.printStackTrace();
            }
            return ""; // TODO:自定义错误信息
        }
    
        public static void main(String[] args) {
            String res = querytLongUrl("你的长网址");
            System.out.println(res);
        }
    
        class UrlResponse {
            @SerializedName("errMsg")
            private String errMsg;
            @SerializedName("url")
            private String url;
    
            public String getErrMsg() {
                return this.errMsg;
            }
    
            public void setErrMsg(String errMsg) {
                this.errMsg = errMsg;
            }
    
            public String getUrl() {
                return this.url;
            }
    
            public void setUrl(String url) {
                this.url = url;
            }
        }
    }
    var ajax = new XMLHttpRequest();
    var shortUrl = '你的短网址';
    
    ajax.open('post','https://dwz.mk/api/query', 'true');
    
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    // 发送请求
    ajax.send(JSON.stringify({
        shortUrl: shortUrl,
    }));
    
    ajax.onreadystatechange = function () {
        if (ajax.readyState === 4 && ajax.status === 200) {
            // 获取还原后的网址
            console.log(ajax.responseText);
        }
    }
    $host = 'https://dwz.mk';
    $path = '/api/create';
    $url = $host . $path;
    $method = 'POST';
    $content_type = 'application/x-www-form-urlencoded';
    
    
    // TODO:设置待注册长网址
    $shortUrl = "你的短网址";
    $bodys = array('shortUrl'=>$shortUrl);
    
    // 配置headers
    $headers = array('Content-Type:'.$content_type);
    
    // 创建连接
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
    
    // 发送请求
    $response = curl_exec($curl);
    curl_close($curl);
    
    // 读取响应
    var_dump($response);
                                                            
        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        import requests
        import json
    
        host = 'https://dwz.mk'
        path = '/api/create'
        url = host + path
        method = 'POST'
        content_type = 'application/x-www-form-urlencoded'
    
    
    
        # TODO:设置待创建的长网址
        bodys = {'shortUrl':'你的短网址'}
    
        # 配置headers
        headers = {'Content-Type':content_type}
    
        # 发起请求
        response = requests.post(url=url, data=bodys, headers=headers)
    
        # 读取响应
        print(response.text)
                                                            
  • 响应结果示例:

    
    {
    "url":"https://dwz.mk/xwd1d",
    "errMsg":""
    }
    
     
  • Content-Type:

    字段 类型 说明
    url string 还原的长网址
    errMsg string 错误信息,生成失败才有值,默认为空字符串
短网址批量生成接口
  • 请求地址:

    https://dwz.mk/api/multCreate

  • 请求方式:

    any

  • Content-Type:

    application/x-www-form-urlencoded

    或者

    multipart/form-data

  • 请求说明:

    longUrl 是数组,请求的格式为 longUrl=xxx&longUrl=xxx

    或者为

    有序的数组  longUrl[0]=xxx&longUrl[1]=xxx

    或者为

    用英文逗号分隔 longUrl=xxx,xxx,

  • 请求参数

    字段 类型 是否必选 说明 示例
    shortUrl array 短网址 https://dwz.mk/adas
  • 响应结果示例:

    
    {
        "errMsg":"",
        "urls":[
            "http://dwz.mk/maUjqu",
            "http://dwz.mk/7NRzmy"
        ]
    }
    
     
  • Content-Type:

    字段 类型 说明
    urls array 生成的短网址,数组格式
    errMsg string 错误信息,生成失败才有值,默认为空字符串