This commit is contained in:
doudou201703
2026-08-06 20:39:45 +08:00
parent 046fac6dc1
commit 3ff0faebb9
38 changed files with 1029 additions and 611 deletions
@@ -1,4 +1,7 @@
import time
from datetime import datetime
from typing import Literal, Optional
from zoneinfo import ZoneInfo
import emoji
import orjson
@@ -6,7 +9,6 @@ import pydash
import requests
from django.forms import model_to_dict
from pydantic import BaseModel, Field
from ulid import ULID
from django_celery.message.tasks import mini调用微信小程序交易管理服务录入订单接口
from wechat_token.token工具包 import sixToken
@@ -192,43 +194,43 @@ class ems邮政物流工具(BaseModel):
order当前订单对象.order物流订单号 = order订单对象.order物流订单号
order当前订单对象.order物流公司订单编号 = waybill_id
order当前订单对象.save()
print(data.json())
print("生成运单成功时的打印", data.json())
# 这里的作用是, 当订单生成了 就调用 小程序交易管理的发货管理接口, 自动录入订单号
mini调用微信小程序交易管理服务录入订单接口.apply_async(kwargs={"order支付商家侧订单号": order当前订单对象.order支付商家侧订单号}, countdown=30)
def 模拟更新订单状态(self, order物流商家侧订单号):
def 模拟更新订单状态(self, order物流公司订单编号, action_type, action_msg):
""""""
order物流对象 = order订单.objects.get(order物流公司订单编号=order物流公司订单编号)
mini_token = sixToken.get_mini_token()
milliseconds_int = ULID().milliseconds
模拟更新物流状态 = f"https://api.weixin.qq.com/cgi-bin/express/business/test_update_order?access_token={mini_token}"
utc_unix_timestamp = int(datetime.now(tz=ZoneInfo("utc")).timestamp())
模拟数据 = {
"biz_id": self.ems_biz_id,
"order_id": order物流商家侧订单号, # 商家生成的订单号
"order_id": order物流对象.order物流订单号, # 商家生成的订单号
"delivery_id": self.ems_delivery_id, #
"waybill_id": "", # 物流订单号
"action_time": milliseconds_int, # 这里是更新发的时间戳
"action_type": 100001,
"action_msg": "揽件成功",
"waybill_id": order物流公司订单编号, # 物流订单号
"action_time": utc_unix_timestamp, # 这里是更新发的时间戳
"action_type": action_type,
"action_msg": action_msg,
}
print("打印 一下模拟的数据,主要就是看一下时间戳的问题", 模拟数据)
data = requests.post(url=模拟更新物流状态,
data=orjson.dumps(模拟数据, option=orjson.OPT_SORT_KEYS, ).decode(encoding="utf-8"))
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json())
def 查询运单轨迹(self, order物流商家侧订单号):
""""""
查询对象 = order订单.objects.get(order物流订单号=order物流商家侧订单号, )
print(查询对象)
mini_token = sixToken.get_mini_token()
def 更新物流快递数据(self, order物流公司订单编号, order物流订单号):
def 更新物流快递数据(self, order物流公司订单编号, ):
""""""
查询对象 = order订单.objects.get(order物流公司订单编号=order物流公司订单编号, order物流订单号=order物流订单号)
查询对象 = order订单.objects.get(order物流公司订单编号=order物流公司订单编号, )
mini_token = sixToken.get_mini_token()
emsGetPathData = requests.post(url="https://api.weixin.qq.com/cgi-bin/express/business/path/get",
params={"access_token": mini_token, },
json={
"openid": 查询对象.order支付者openid,
"delivery_id": self.ems_delivery_id, "waybill_id": 查询对象.order物流公司订单编号,
"delivery_id": self.ems_delivery_id, "waybill_id": order物流公司订单编号,
},
)
resData = orjson.loads(emsGetPathData.content.decode(encoding="utf-8"))
@@ -299,4 +301,11 @@ class ems邮政物流工具(BaseModel):
if __name__ == "__main__":
# 当脚本直接运行时执行的代码
ems邮政物流工具().生成运单(out_trade_no商家侧支付订单号="")
# ems邮政物流工具().生成运单(out_trade_no商家侧支付订单号="")
ems邮政物流工具().模拟更新订单状态(order物流公司订单编号="EMS01KZAH47JZA3HCY2R5NS0WD3VN_waybill_id", action_type=100001, action_msg="揽件成功")
time.sleep(30)
ems邮政物流工具().模拟更新订单状态(order物流公司订单编号="EMS01KZAH47JZA3HCY2R5NS0WD3VN_waybill_id", action_type=300002, action_msg="开始派送")
time.sleep(30)
ems邮政物流工具().模拟更新订单状态(order物流公司订单编号="EMS01KZAH47JZA3HCY2R5NS0WD3VN_waybill_id", action_type=300003, action_msg="签收成功")
# ems邮政物流工具().更新物流快递数据(order物流公司订单编号="EMS01KZAD94RDQFQBVVX705YNH6SE_waybill_id")