Files

81 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 通用:认证与调用方式
## 获取 Access Token
**重要:路径和参数都经过实际验证,注意不是 POST**
```
GET https://openapi.77ircloud.com/v2/oauth2/token
```
参数直接在 URL 查询字符串中:
```
https://openapi.77ircloud.com/v2/oauth2/token?userName=112983083&password=77ircloud&client_id=6767358&client_secret=1gk9ApiWV8IA2QrVDnU6Dx7uUo7CLuN2&grant_type=client_credentials&scope=basic
```
返回:
```json
{
"code": 200,
"data": {
"access_token": "194557f72e5594557d796f216ae9f9fe3607084",
"expires_in": 2592000
}
}
```
**注意**
- 是 GET 请求,不是 POST
- 有效期 30 天,可复用,不必每次调用都刷新
- token 过期后会返回非 200重新获取即可
## 调用示例Python
```python
import requests, json
# 获取 token
def get_token():
url = "https://openapi.77ircloud.com/v2/oauth2/token"
params = {
"userName": "112983083",
"password": "77ircloud",
"client_id": "6767358",
"client_secret": "1gk9ApiWV8IA2QrVDnU6Dx7uUo7CLuN2",
"grant_type": "client_credentials",
"scope": "basic"
}
resp = requests.get(url, params=params)
return resp.json()["data"]["access_token"]
# 调用 API
token = get_token()
headers = {"access_token": token}
resp = requests.post(
"https://openapi.77ircloud.com/order-aggregation/organizations/orders/search",
headers=headers,
json={"pageNum": 1, "pageSize": 10, "withDetails": True}
)
print(resp.json())
```
## 通用请求 Header
所有 API 调用都必须包含:
- `access_token: {token}` — 必须
- `Content-Type: application/json` — POST 请求必须
## 通用返回格式
```json
{
"code": 200,
"data": {},
"message": "操作成功"
}
```
- `code=200` 表示成功
- `code≠200` 表示失败,检查 `message` 字段