至少使用五个API编写模拟订单号生成
时间: 2024-02-21 14:49:35 浏览: 63
1. 阿里云API
```python
import requests
url = "https://api.jisuapi.com/express/generate"
payload = {
"appkey": "your_appkey",
"type": "auto",
"size": "10"
}
response = requests.get(url, params=payload)
if response.status_code == 200:
data = response.json()
if data["status"] == "0":
for order_no in data["result"]:
print(order_no)
else:
print("Error: " + data["msg"])
else:
print("Error: " + response.text)
```
2. 随机字符串API
```python
import requests
url = "https://www.random.org/strings/"
payload = {
"num": "10",
"len": "15",
"digits": "on",
"upperalpha": "on",
"loweralpha": "on",
"unique": "on",
"format": "plain",
"rnd": "new"
}
response = requests.get(url, params=payload)
if response.status_code == 200:
order_nos = response.text.splitlines()
for order_no in order_nos:
print(order_no)
else:
print("Error: " + response.text)
```
3. 企业级随机数API
```python
import requests
import hashlib
import time
url = "https://api.qianxin.com/data/random"
timestamp = str(int(time.time()))
appkey = "your_appkey"
appsecret = "your_appsecret"
nonce = "1234567890"
to_sign = appkey + nonce + timestamp + appsecret
sign = hashlib.md5(to_sign.encode("utf-8")).hexdigest()
payload = {
"appkey": appkey,
"nonce": nonce,
"timestamp": timestamp,
"type": "string",
"length": "15"
}
headers = {
"Authorization": sign
}
response = requests.get(url, params=payload, headers=headers)
if response.status_code == 200:
data = response.json()
if data["code"] == "200":
order_nos = data["data"]
for order_no in order_nos:
print(order_no)
else:
print("Error: " + data["message"])
else:
print("Error: " + response.text)
```
4. 央视新闻随机数API
```python
import requests
url = "https://api.cctv.cn/other/randStr"
payload = {
"num": "10",
"len": "15"
}
response = requests.get(url, params=payload)
if response.status_code == 200:
data = response.json()
if data["result"] == "success":
order_nos = data["list"]
for order_no in order_nos:
print(order_no)
else:
print("Error: " + data["msg"])
else:
print("Error: " + response.text)
```
5. 彩云小译随机数API
```python
import requests
url = "https://api.interpreter.caiyunai.com/v1/translator"
payload = {
"source": "en",
"target": "zh",
"trans_type": "random",
"request_id": "test"
}
headers = {
"X-Authorization": "token your_token"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
data = response.json()
if data["message"] == "success":
order_nos = data["translate"]["result"]
for order_no in order_nos:
print(order_no)
else:
print("Error: " + data["message"])
else:
print("Error: " + response.text)
```
以上是五个不同的API,可以生成模拟订单号。其中,阿里云API和企业级随机数API需要在对应的官网上申请AppKey和AppSecret,替换代码中的相应字段。彩云小译随机数API需要在官网上申请Token,并替换代码中的相应字段。
阅读全文