API开发文档 v3

开始

接口鉴权 API 密钥。 会员开通后,系统会自动为该用户生成 API 密钥。 API 密钥必须随每个请求一起发送(参见下面的完整示例)。 如果 API 密钥未发送或已过期,则会出现错误。 请确保对您的 API 密钥保密,以防止滥用。API 密钥仅向Plus级别会员开放。

授权

要使用 API 系统进行身份验证,您需要将 API 密钥作为授权令牌与每个请求一起发送。 您可以在下面查看示例代码。右侧只是授权示例,并不是完整代码。如果您的服务器无法连接我们的接口,请联系客服添加IP白名单。

curl --location --request POST 'https://urlplus.cn/api/url/add' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' 
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/url/add",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer YOURAPIKEY",
    "Content-Type: application/json",
    ),
));

$response = curl_exec($curl);
请求频率限制

接口限制每 1 分钟最多 30 次请求。

您每天最多可生成1000个短网址。

X-RateLimit-Limit: 30
X-RateLimit-Remaining: 29
X-RateLimit-Reset: TIMESTAMP
响应格式

默认情况下,所有 API 响应都以 JSON 格式返回。 要将其转换为可用数据,需要根据编程语言使用适当的函数。 在 PHP 中,函数 json_decode() 可用于将数据转换为对象(默认)或数组(将第二个参数设置为 true)。

{
    "error": 1,
    "message": "An error ocurred"
}

帐号

获取帐号
GET https://urlplus.cn/api/account

查询当前帐号信息。

curl --location --request GET 'https://urlplus.cn/api/account' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/account",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "data": {
        "id": 1,
        "email": "sample@domain.com",
        "username": "sampleuser",
        "avatar": "https:\/\/domain.com\/content\/avatar.png",
        "status": "pro",
        "expires": "2022-11-15 15:00:00",
        "registered": "2020-11-10 18:01:43"
    }
}
修改帐号
PUT https://urlplus.cn/api/account/update

要更新帐户信息,您可以向此接口发送请求,它将更新帐户数据。

curl --location --request PUT 'https://urlplus.cn/api/account/update' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "newemail@google.com",
    "password": "newpassword"
}'
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/account/update",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    CURLOPT_POSTFIELDS => '{
    "email": "newemail@google.com",
    "password": "newpassword"
}',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "message": "Account has been successfully updated."
}

短网址


二维码

显示所有的二维码
GET https://urlplus.cn/api/qr?limit=2&page=1

要通过 API 获取二维码,您可以使用此端点。 您还可以过滤数据(有关更多信息,请参见表格)。

参数描述
limit (可选) 每页条数
page (可选) 页码
curl --location --request GET 'https://urlplus.cn/api/qr?limit=2&page=1' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/qr?limit=2&page=1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": "0",
    "data": {
        "result": 2,
        "perpage": 2,
        "currentpage": 1,
        "nextpage": 1,
        "maxpage": 1,
        "qrs": [
            {
                "id": 2,
                "link": "https:\/\/urlplus.cn\/qr\/a2d5e",
                "scans": 0,
                "title": "Google",
                "date": "2020-11-10 18:01:43"
            },
            {
                "id": 1,
                "link": "https:\/\/urlplus.cn\/qr\/b9edfe",
                "scans": 5,
                "title": "Google Canada",
                "date": "2020-11-10 18:00:25"
            }
        ]
    }
}
获取单个二维码
GET https://urlplus.cn/api/qr/:id

要通过 API 获取单个二维码的详细信息,您可以使用此端点。

curl --location --request GET 'https://urlplus.cn/api/qr/:id' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/qr/:id",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "details": {
        "id": 1,
        "link": "https:\/\/urlplus.cn\/qr\/b9edfe",
        "scans": 5,
        "title": "Google Canada",
        "date": "2020-11-10 18:00:25"
    },
    "data": {
        "clicks": 1,
        "uniqueClicks": 1,
        "topCountries": {
            "Unknown": "1"
        },
        "topReferrers": {
            "Direct, email and other": "1"
        },
        "topBrowsers": {
            "Chrome": "1"
        },
        "topOs": {
            "Windows 10": "1"
        },
        "socialCount": {
            "facebook": 0,
            "twitter": 0,
            "instagram": 0
        }
    }
}
生成二维码
POST https://urlplus.cn/api/qr/add

要缩短 QR 码,您需要通过 POST 请求以 JSON 格式发送有效数据。 数据必须作为请求的原始主体发送,如下所示。 下面的示例显示了您可以发送的所有参数,但您不需要发送所有参数(有关更多信息,请参见表格)。

参数描述
type (必选)二维码类型: text | vcard | link | email | phone | sms | wifi
data (必选) 包含的数据,可以是字符串或数组
background (可选) 背景色。如 #ffffff
foreground (可选) 前景色。如 #000000
logo (可选) logo地址,支持png和jpg格式
curl --location --request POST 'https://urlplus.cn/api/qr/add' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "type": "link",
    "data": "https:\/\/google.com",
    "background": "#ffffff",
    "foreground": "#000000",
    "logo": "https:\/\/site.com\/logo.png"
}'
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/qr/add",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    CURLOPT_POSTFIELDS => '{
    "type": "link",
    "data": "https:\/\/google.com",
    "background": "#ffffff",
    "foreground": "#000000",
    "logo": "https:\/\/site.com\/logo.png"
}',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "id": 3,
    "link": "https:\/\/urlplus.cn\/qr\/a58f79"
}
更新二维码
PUT https://urlplus.cn/api/qr/:id/update

要更新二维码,您需要通过 PUT 请求以 JSON 格式发送有效数据。 数据必须作为请求的原始主体发送,如下所示。 下面的示例显示了您可以发送的所有参数,但您不需要发送所有参数(有关更多信息,请参见表格)。

参数描述
data (必选) 包含的数据,可以是字符串或数组
background (可选) 背景色。如 #ffffff
foreground (可选) 前景色。如 #000000
logo (可选) logo地址,支持png和jpg格式
curl --location --request PUT 'https://urlplus.cn/api/qr/:id/update' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "type": "link",
    "data": "https:\/\/google.com",
    "background": "#ffffff",
    "foreground": "#000000",
    "logo": "https:\/\/site.com\/logo.png"
}'
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/qr/:id/update",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    CURLOPT_POSTFIELDS => '{
    "type": "link",
    "data": "https:\/\/google.com",
    "background": "#ffffff",
    "foreground": "#000000",
    "logo": "https:\/\/site.com\/logo.png"
}',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "message": "QR has been updated successfully."
}
删除二维码
DELETE https://urlplus.cn/api/qr/:id/delete

要删除二维码,您需要发送 DELETE 请求。

curl --location --request DELETE 'https://urlplus.cn/api/qr/:id/delete' \
--header 'Authorization: Bearer YOURAPIKEY' \
--header 'Content-Type: application/json' \
$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://urlplus.cn/api/qr/:id/delete",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 2,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => "DELETE",
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer YOURAPIKEY",
        "Content-Type: application/json",
    ),
    
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
接口返回
{
    "error": 0,
    "message": "QR Code has been deleted successfully."
}