# -*- coding:utf-8 -*-
import json
import requests
# 收藏列表
def collectionListQuery():
jsonData = {
"sceneName":"collected_collocations",
"paramMap": {
"currentPage":1,
"pageSize":20
}
}
return jsonData
""""
# 添加收藏
def addDPQuery(collocationId):
return {
sceneName: 'add_collection',
paramMap: JSON.stringify({
targetId: collocationId,
namespace: 101,
}),
}
# 移除收藏
def removeDPQuery(collocationId):
return {
sceneName: 'remove_collection',
paramMap: JSON.stringify({
targetId: collocationId,
namespace: 101,
}),
}
# 查询某套具体的搭配
def makeDPQuery(collocationId):
return {
sceneName: 'test_tql',
paramMap: JSON.stringify({
op: 'getCollocation',
params: JSON.stringify({collocationId})
}),
}
# 逛一逛列表
def makeGYGQuery(currentPage):
return {
sceneName: 'collocation_recommend',
paramMap: JSON.stringify({
"currentPage": currentPage || 1,
"pageSize": 20,
"bucketIndex":0
})
}
# 换装页面列表
def makeDaPeiList(collocationId,mainSkcId,cursor):
return {
sceneName: 'collocation_change',
paramMap: JSON.stringify({
cursor,
mainSkcId,
pageSize: 10,
collocationId,
})
}
# 查询换装query
def makeHuanZhuangQuery(collocationId,targetSkcId,candidateSkcIds):
return {
sceneName: 'test_tql',
paramMap: JSON.stringify({
op: 'getCollocationChange',
params: JSON.stringify({
collocationId,
targetSkcId,
candidateSkcIds,
})
}),
}
"""
# 生成请求url
def generateUrl(queryParams):
url ="https://acs.wapa.taobao.com/gw/mtop.taobao.xiaofancenter.tql.queryBySceneNameForMtop/1.0/?data=" + json.dumps(queryParams)
print(url)
return url
# 生成请求http header参数的请求参数
def generateSignConfig(queryParams):
return json.dumps({
"username":"fashionai测试账号1",
"password":"taobao1234",
"sid":"",
"loginSite":"",
"env":"2",
"method":"POST",
"signtype":"REQUIRED_SESSION",
"ismirror":"false",
"bizparam": json.dumps(queryParams),
"apiName":"mtop.taobao.xiaofancenter.tql.queryBySceneNameForMtop",
"apiV":"1.0",
"appKey":"21272243",
"protocalV":"5.1",
"secondPrjId":"",
"clientip":"",
"testunit":"center",
"testDomain":"https://acs.wapa.taobao.com",
"bizHeaders": {},
"systemHeaders": {
"ttid":"11320@taobao_android_5.0.0",
"imei":"12323313246",
"imsi":"12323313246",
"devid":"12323313246",
"utdid":"Degarde",
"location":"-12.0,11.1"
}
})
# 获取请求头
def queryHttpHeaders(queryParams) :
url ="http://max.m.taobao.com/mtop/testmodule/genMtopReq?biz_domain=ali"
headers = {"content-type":"application/json"}
data = generateSignConfig(queryParams)
r = requests.post(url=url,headers=headers,data=data)
result = r.json()
print(r.text)
print(json.dumps(result["module"]["systemHeaders"]))
return result["module"]["systemHeaders"]
def queryApi(queryParams):
url ="http://max.m.taobao.com/mtop/testmodule/sendMtopReq?biz_domain=ali"
headers = {"content-type":"application/json"}
data = json.dumps({"requestUrl":generateUrl(queryParams),"reqHeaders":queryHttpHeaders(queryParams),"httpMethod":"POST"})
print(data)
r = requests.post(url=url,headers=headers,data=data)
rs = r.json()
print(rs["module"]["responseResult"])
return rs["module"]["responseResult"]
queryParams={"sceneName":"similar_single","paramMap":"{\"skcId\":\"552251830385_TB2n3gNxrBnpuFjSZFGXXX51pXa_!!2872097227.jpg\",\"collocationId\":30151991}"}
queryApi(queryParams)