电商项目接口
# mall.lemonban.com (opens new window) 项目
# 接口分析
- 界面
- fiddler / F12
- Postman 导入 HAR
# 后台验证码接口
- 接口地址:GET /captcha.jpg?uuid=4be63349-544a-4f09-8dc2-2cc14c7d2841
- 测试目标:能得到一张验证码图片
- 测试数据生成:生成 uuid
- 验证码处理: 万能验证码、数据库获取 、OCR、 图鉴
uid = gen_uuid()
url = "http://mall.lemonban.com:8108/captcha.jpg?uuid=" + str(uid)
ret = visit_lemon_api(url)
with open("captcha.png", "wb") as f:
f.write(ret)
# 验证码识别
从图鉴的的官网中下载实例:
def base64_api(uname, pwd, img, typeid):
with open(img, 'rb') as f:
base64_data = base64.b64encode(f.read())
b64 = base64_data.decode()
data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
return ""
if __name__ == "__main__":
img_path = "C:/Users/Administrator/Desktop/file.jpg"
result = base64_api(uname='simple', pwd='yuan5311645', img=img_path, typeid=3)
print(result)
先获取验证码,再识别。
def get_img() -> bytes:
"""获取验证码"""
url = config.host + '/captcha.jpg'
resp = requests.get(url, params=str(uuid.uuid4()))
return resp.content
def tujian_api(uname, pwd, img, typeid):
"""图鉴的验证码识别"""
base64_data = base64.b64encode(img)
b64 = base64_data.decode()
data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
return ""
if __name__ == '__main__':
data = tujian_api('simple', 'yuan5311645', get_img(), 3)
print(data)
# 后台登录接口
- 接口地址:POST /adminLogin
- 测试目标:参数、响应 token
- 接口参数,分别代表时间戳、用户名、密码、sessionuuid、验证码
{
"t":1649494204983,
"principal":"student",
"credentials":"123456a",
"sessionUUID":"4be63349-544a-4f09-8dc2-2cc14c7d2841",
"imageCode":"lemon"
}
# 后台图片上传接口
- 接口地址: POST http://mall.lemonban.com:8108/admin/file/upload/img (opens new window)
- 测试目标:返回数据、图片地址能访问
- 携带 token : {"Authorization": "bearer2da12ea3-ec8c-46f3-b117-ac3a79b5d2c1"}
- 数据依赖:前置为登录
import requests
def upload_img(url, file_path):
"""发送请求,上传文件"""
try:
headers = {"Authorization": "bearer2da12ea3-ec8c-46f3-b117-ac3a79b5d2c1"}
files = {"file": open(file_path, "rb")}
response = requests.post(url, files=files, headers=headers)
if response.status_code == 200:
return response.json()
except Exception as e:
print(e)
return None
a = upload_img("http://mall.lemonban.com:8108/admin/file/upload/img", "captcha.jpg")
# 后台新增商品接口
- 接口地址: POST http://mall.lemonban.com:8108/prod/prod (opens new window) HTTP/1.1
- 测试目标:参数、响应
- 数据依赖:前置为登录、图片上传
{
"t":1649503962366,
"prodName":"好东西",
"brief":"",
"video":"",
"prodNameEn":"好东西",
"prodNameCn":"好东西",
"contentEn":"",
"contentCn":"",
"briefEn":"",
"briefCn":"",
"pic":"2022/04/f414d8d9df274b909b959b579d67f88a.jpg",
"imgs":"2022/04/f414d8d9df274b909b959b579d67f88a.jpg",
"preSellStatus":0,
"preSellTime":null,
"categoryId":380,
"skuList":[
{
"price":0.01,
"oriPrice":0.01,
"stocks":0,
"skuScore":1,
"properties":"",
"skuName":"",
"prodName":"",
"weight":0,
"volume":0,
"status":1,
"prodNameCn":"好东西",
"prodNameEn":"好东西"
}
],
"tagList":[
2
],
"content":"",
"deliveryTemplateId":1,
"totalStocks":0,
"price":0.01,
"oriPrice":0.01,
"deliveryModeVo":{
"hasShopDelivery":true,
"hasUserPickUp":false,
"hasCityDelivery":false
}
}
aaa
本文完,感谢你的耐心阅读,如有需要可加我微信,备注「博客」并说明原因,我们一起进步,下次见。
编辑 (opens new window)
上次更新: 2022/06/01, 08:59:38