import time
from dingtalkchatbot.chatbot import DingtalkChatbot
import requests
webhook ='https://oapi.dingtalk.com/robot/send?access_token=b7527b37d578d1e244b9b08609e61d209b4170a7acc1d95f2da75e22c62728e9'
bot = DingtalkChatbot(webhook)
session_wms = requests.Session()
这个url是登陆入口
login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"
headers = {
# 'accept': 'application/json, text/plain, /',
# 'accept-encoding': 'gzip, deflate, br',
# 'accept-language': 'zh-CN,zh;q=0.9',
# 'content-length': '46',
# 'content-type': 'application/json',
'grpc-metadata-application-code': 'VENUS',
# 'grpc-metadata-user-auth-token': 'null',
# 'origin': 'https://mercury.xtw-tech.com',
# 'referer': 'https://mercury.xtw-tech.com/',
# 'sec-fetch-mode': 'cors',
# 'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'
}
登陆wms
data = {
登录wms
response_wms = session_wms.post(url=login_url, headers=headers, json=data)
tenant_id= '3'
for asn_id in ['743021']:
asn_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}?tenant_id={tenant_id}'
headers = {
'authority': 'titan-api.xtw-tech.com',
'method': 'GET',
'path': f'/v1/asn/by_id/{asn_id}?tenant_id={tenant_id}',
'scheme': 'https',
'accept': 'application/json, text/plain, /',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': "macOS",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36',
}
response_asn = session_wms.get(headers=headers, url=asn_url)
respon = response_asn.json()['asnWithDetails']
url_start =f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/start'
header = {
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/inspection/start',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '35',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
data ={'asnId': f"{asn_id}", 'tenantId': f"{tenant_id}"}
re_start = session_wms.post(headers=header,url=url_start,json=data)
k = re_start.json()['asnWithDetails']['inventories']
n =0
dic = {}
for i in k:
expectedQuantity = i['expectedQuantity']
inventoryRelationId = i['reportItem'][0]['inventoryRelationId']
try:
productionTime = i['reportItem'][0]['lot']['productionTime']
lotId = i['reportItem'][0]['lot']['id']
status= i['reportItem'][0]['lot']["status"]
except:
productionTime = ''
lotId =''
status =''
sp = i['standardProductTenantMapping']['standardProduct']['code']
name= i['standardProductTenantMapping']['standardProduct']['name']
report_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/report/temp_item_record/create_or_update'
header ={
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/inspection/report/temp_item_record/create_or_update',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '177',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
if lotId !="":
data = {'inventoryRelationId': f"{inventoryRelationId}",'tenantId': f"{tenant_id}",'reportItem':[{'actualQuantity': f"{expectedQuantity}",'inventoryRelationId': f"{inventoryRelationId}",'lotId': f"{lotId}",'productionTime': f"{productionTime}"}]}
else:
data = {'inventoryRelationId': f"{inventoryRelationId}",'tenantId': f"{tenant_id}",'reportItem':[{'actualQuantity': f"{expectedQuantity}",'inventoryRelationId': f"{inventoryRelationId}"}]}
if status =='LOT_STATUS_EXPIRED':
dic[f"{inventoryRelationId}"]={'inventoryRelationId': f"{inventoryRelationId}",'putawayQuantity':f"{expectedQuantity}", 'locationId': "205548",'lotId': f"{lotId}"}
elif status =='LOT_STATUS_CLOSE_TO_EXPIRY':
dic[f"{inventoryRelationId}"]= {'inventoryRelationId': f"{inventoryRelationId}", 'putawayQuantity': f"{expectedQuantity}",
'locationId': "2434", 'lotId': f"{lotId}"}
else:
dic[f"{inventoryRelationId}"]={'inventoryRelationId': f"{inventoryRelationId}", 'putawayQuantity': f"{expectedQuantity}",
'locationId': "260835", 'lotId': f"{lotId}"}
kk = session_wms.post(headers=header,url=report_url,json=data)
print(n, kk.status_code, asn_id, sp, status)
n +=1
time.sleep(0.1)
try:
url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/inspection/report'
header = {
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/inspection/report',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '177',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
data ={
'actualArrivalTime': "2022-11-01T23:58:16+08:00",
'asnId': f"{asn_id}",
'pictures': [],
'tenantId': f"{tenant_id}",
}
status = session_wms.post(headers=header,url=url,json=data)
if status.status_code==400:
str = status.json()['message']
f =bot.send_markdown(title=f'验收上架异常:',
text=f"### {str}&{asn_id}",
at_mobiles=['18620332090'])
print('检测到异常了')
break
else:
pass
except:
bot.send_markdown(title=f'验收上架异常:',
text=f"### 验收,请及时核查。。",
at_mobiles=['18620332090'])
putaway_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/start'
header ={
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/putaway/start',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '35',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
data = {'asnId': f"{asn_id}", 'tenantId': f"{tenant_id}"}
session_wms.post(url=putaway_url,headers=header,json=data)
location_url = f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/location'
header ={
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/putaway/location',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '35',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
for key,value in dic.items():
try:
if value['lotId'] =='':
data ={'tenantId': f"{tenant_id}",'inventoryPutawayLocationRelation': [{'inventoryRelationId': f"{key}", 'putawayQuantity': f"{value['putawayQuantity']}", 'locationId': f"{value['locationId']}"}]}
s1 = session_wms.post(url=location_url,headers=header,json=data)
else:
data ={'tenantId': f"{tenant_id}",'inventoryPutawayLocationRelation': [{'inventoryRelationId': f"{key}", 'putawayQuantity': f"{value['putawayQuantity']}", 'locationId': f"{value['locationId']}",'lotId': f"{value['lotId']}"}]}
s2 = session_wms.post(url=location_url,headers=header,json=data)
except:
print('出现异常了')
finish =f'https://titan-api.xtw-tech.com/v1/asn/by_id/{asn_id}/putaway/finish'
header ={
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': f'/v1/asn/by_id/{asn_id}/putaway/finish',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '35',
'content-type': 'application/json',
'grpc-metadata-application-code': 'MERCURY',
'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
'origin': 'https://mercury.xtw-tech.com',
'referer': 'https://mercury.xtw-tech.com/',
'sec-ch-ua-platform': "Windows",
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
data = {'tenantId': f"{tenant_id}"}
code = session_wms.post(url=finish,headers=header,json=data)
if code.status_code == 200:
t = f'https://mercury.xtw-tech.com/asn/{asn_id}/?tenant_id=3'
bot.send_markdown(title=f'完成上架:',
text=f"### [深圳中心仓{n}个sp已完成验收上架,点我跳转至ASN页面]({t})",
at_mobiles=['18620332090'])
else:
pass
__EOF__
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)