本帖最后由 Winlin 于 2023-8-4 18:02 编辑
Bash请求示例:https://github.com/ossrs/bt-plugin-dev/blob/main/http-api.sh
- #!/bin/bash
- # See https://www.bt.cn/bbs/thread-20376-1-1.html
- # See https://www.bt.cn/data/api-doc.pdf
- if [[ -z $BT_KEY ]]; then echo "No BT_KEY"; exit 1; fi
- request_time=$(date +%s)
- sk_md5=$(echo -n $BT_KEY |md5sum |awk '{print $1}')
- request_token=$(echo -n "${request_time}${sk_md5}" |md5sum |awk '{print $1}')
- curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \
- -d "request_time=$request_time&request_token=$request_token" \
- "http://localhost:7800/site?action=GetPHPVersion"
- echo ""
复制代码
Python简化示例:https://github.com/ossrs/bt-plugin-dev/blob/main/http-api.py
- #coding: utf-8
- import os, time,hashlib,json,urllib.request
- md5sum = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
- # See https://www.bt.cn/bbs/thread-20376-1-1.html
- # See https://www.bt.cn/data/api-doc.pdf
- BT_KEY= os.getenv('BT_KEY')
- if not BT_KEY:
- print("BT_KEY is not set")
- exit(1)
- now_time = int(time.time())
- request_token = md5sum(str(now_time) + md5sum(BT_KEY))
- req = urllib.request.Request(
- 'http://localhost:7800/site?action=GetPHPVersion',
- urllib.parse.urlencode({
- 'request_token': request_token,
- 'request_time': now_time
- }).encode('utf-8')
- )
- res = urllib.request.urlopen(req)
- result = res.read().decode('utf-8')
- print(f"request_time={now_time}, request_token={request_token}, result={json.loads(result)})")
复制代码
|