使用Postman调试雨云API基础教程


· 通过Postman对雨云API进行调试。

调试雨云API有很多种方式,其中一个简便的方法便是使用Postman,使用Postman可以很方便地发送API请求。
下载地址:https://www.postman.com/

  1. 完成Postman的安装。

  2. 新建请求,写入API地址,并在Headers里面增加三个字段,如图


    uid的VALUE写入您的UID,其中VALUE处写为变量,我们需要用到Pre-request Script对其进行设置

  3. 转到Pre-request Script处,写入以下内容
    var unixtime = new Date().getTime() / 1000;
    var hash = CryptoJS.MD5(“请求URL” + CryptoJS.MD5(“您的API密钥”).toString() + unixtime).toString();
    pm.environment.set(“timestamp”, unixtime);
    pm.environment.set(“signature”, hash);

  4. 发送请求并调试

我选择用Python :grin:

自用续费代码(能用就行)
import time
import hashlib
import calendar#需要使用pip安装calendar
import requests
import json
timestamp = str(calendar.timegm(time.gmtime()))#用calendar输出整数
key = '你的API密钥'
md5_key = str(hashlib.md5(key.encode('utf8')).hexdigest())
url = str("请求地址/api开头")#列如 /api/v1/rcs/服务器ID或是其他产品的ID/renew
md5_val = hashlib.md5(url.encode('utf8') + md5_key.encode('utf8') + timestamp.encode('utf8')).hexdigest()
headers = {
    'content-type': 'application/json',
    'uid': '用户ID',
    'timestamp': timestamp,
    'signature': md5_val,
}
url = "https://www.rainyun.com/api/v1/rcs/服务器ID或是其他产品的ID/renew"
pre = {"months": "1", "withip": "1"}#根据实际情况改
res = requests.post(url=url,data=json.dumps(pre),headers=headers)
print(res.text)

弄错了
需要使用pip安装的是requests

1 个赞

太酷了!感谢分享!另外,我们近期可能会有一个改版简化api的使用:)

1 个赞