|
注册
首页
联系我们

快速开始

注册账号

当前已开放自助注册。您可以通过微信扫码或者手机号短信验证的方式登录。登录成功后,会自动赠送您自注册套餐包,您可以在我的接口菜单调试接口、浏览接口文档。

接口凭证

如果您购买了接口的使用权限,登录成功后,跳转到 个人中心 页面。可以看到您的接口凭证是:Client IDClient Secret。您还可以在此页面上,监控到您的接口使用量情况。

权限令牌

1、通过Client IDClient Secret,生成基于Base64编码规则的Authorization;
2、携带Authorization作为请求头,请求获得token;
3、请注意:token有效期为30分钟。

 

Client ID是: b4562e4188asd4cb486a19c6971515c66(样例)
Client Secret是: N1eOgd8sOk4z1vaWQfB18P4AbSk70lGs(样例)
你可以在代码中使用POST方法获取权限令牌。
例如:
  • Curl
  • NodeJS
  • Python
  • Java
curl -X "POST" "https://connect.zhihuiya.com/oauth/token" \
    -H "Content-Type: application/x-www-form-urlencoded " \
    -u b4562e4188asd4cb486a19c6971515c66:N1eOgd8sOk4z1vaWQfB18P4AbSk70lGs \
    -d "grant_type=client_credentials"
const request = require('request');
request.post(
    {
        // eslint-disable-next-line no-template-curly-in-string
        url: 'https://b4562e4188asd4cb486a19c6971515c66:N1eOgd8sOk4z1vaWQfB18P4AbSk70lGs@connect.zhihuiya.com/oauth/token',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        form: 'grant_type=client_credentials',
    },
    (err, res, body) => {
        if (!err) {
            console.log(body);
        } else {
            console.log('error authenticate', err);
        }
    }
);
import requests
url = "https://b4562e4188asd4cb486a19c6971515c66:N1eOgd8sOk4z1vaWQfB18P4AbSk70lGs@connect.zhihuiya.com/oauth/token"
payload = "grant_type=client_credentials"
headers = {
    "content-type": "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
public static void main(String[] args) {
    String host = "https://b4562e4188asd4cb486a19c6971515c66:N1eOgd8sOk4z1vaWQfB18P4AbSk70lGs@connect.zhihuiya.com";
    String path = "/oauth/token";
    Map headers = new HashMap();
    headers.put("Content-Type", "application/x-www-form-urlencoded");

    Map requestbody = new HashMap();
    requestbody.put("grant_type", "client_credentials");

    try {
        /**
        * Important Tips:
        * Please Download HttpUtils From
        * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
        *
        * Please refer to the corresponding dependence:
        * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
        */
        HttpResponse response = HttpUtils.doPost(host, path, null, headers, null, requestbody);
        System.out.println(EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
复制

得到的响应体如下:

  • json
{
    "token": "token_example",
    "token_type": "BearerToken",
    "expires_in": 1799,
    "status": "approved",
    "issued_at":"1692347672874"
}
复制

业务接口

在您获得权限令牌以后,您可以通过令牌来调用您购买的业务接口。

例如:您希望通过某个专利的唯一标识获取专利详情,你可以发起GET方法,并带上请求参数apikeyAuthorization,其中apikey是您的客户端ID,Authorization为权限验证内容,其组成为:Bearer [令牌]

例如:Bearer token_example(注意 Bearer 与令牌之间有一个空格)

响应码

error_codedescription
67200000
服务内部错误!
67200001
API整体限流错误!
67200002
当前调用速率过快,超过当前配置限制QPS!
67200003
申请token的key和secret传参不正确或者客户端已被禁用!
67200004
请求的接口无权限请联系我们的支持人员!
67200005
账户余额/调用次数不足!
67200006
客户端超过开通有效期!
67200007
当前调用超过当天配置使用额度!
67200008
请检查query参数中必填的apikey是否传输!
67200009
apikey与所传的bearerToken不匹配,请检查是否使用在有效期内的token!
67200012
请求不合法!
67200100
当前服务器状态正忙,请求响应超时!
67200101
当前请求的Api不存在请检查请求Path!
68300004
请求参数异常!
68300005
查询Api失败!
68300006
解析基本存取错误!
68300007
存在错误的请求!
68300008
服务中断异常,请稍后再试!
68300010
文件不符合上传规范!