103 lines
4.2 KiB
Python
103 lines
4.2 KiB
Python
import datetime
|
|||
|
|
|
||
|
|
import jmespath
|
||
|
|
import orjson
|
||
|
|
import requests
|
||
|
|
from django.core.handlers.wsgi import WSGIRequest
|
||
|
|
from rest_framework import status
|
||
|
|
from rest_framework.decorators import action
|
||
|
|
from rest_framework.request import Request
|
||
|
|
from rest_framework.response import Response
|
||
|
|
from rest_framework.routers import SimpleRouter
|
||
|
|
from rest_framework.viewsets import ViewSet
|
||
|
|
|
||
|
|
from wechat_第三方接口.顺丰物流.顺丰参数 import sfToken
|
||
|
|
|
||
|
|
|
||
|
|
class SF推送ViewSets(ViewSet):
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="push_router")
|
||
|
|
def 路由推送接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
print('路由推送接口', request.data)
|
||
|
|
return Response(data={"xiao": "get_xiao接口被调用了"}, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="pushorderstate")
|
||
|
|
def 订单状态推送接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
print(request)
|
||
|
|
postparams = request.data
|
||
|
|
print(postparams, "订单状态推送接口")
|
||
|
|
return Response(data={"message": "post_xiao接口被调用了啦"}, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="push_fee")
|
||
|
|
def 清单运费推送接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
print("清单运费推送接口", request.data)
|
||
|
|
return Response(data={"message": "post_xiao接口被调用了啦"}, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="push_img")
|
||
|
|
def 图片注册及推送接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
postparams = request.data.get("postparams", False) #
|
||
|
|
print(request.data, "图片注册推送接口")
|
||
|
|
return Response(data={"message": "post_xiao接口被调用了啦"}, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="push_subsidy")
|
||
|
|
def 国补通知推送接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
return Response(data={"message": "post_xiao接口被调用了啦"}, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@action(detail=False, methods=["get", "post", ], url_path="push_register")
|
||
|
|
def 路由注册接口(self, request: WSGIRequest | Request):
|
||
|
|
"""
|
||
|
|
:param request:
|
||
|
|
:return:
|
||
|
|
"""
|
||
|
|
uri = f"https://sfapi-sbox.sf-express.com/std/service"
|
||
|
|
accessToken = sfToken()
|
||
|
|
sftimestamp = str(int(datetime.datetime.now().timestamp()))
|
||
|
|
requestID = datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S%f")
|
||
|
|
msgData = {
|
||
|
|
"attributeNo": "SF7444700293847", # 订单号或者运单号
|
||
|
|
"type": "2", # 1-按订单号注册, 2-按运单号注册
|
||
|
|
"checkPhoneNo": "9784", # 电话号码后四位
|
||
|
|
"orderId": "SFOD20251127113410676181",
|
||
|
|
# "clientIp": "10.118.92.11",
|
||
|
|
"language": "zh-CN", # 响应报文的语言, 缺省值为zh-CN,
|
||
|
|
"country": "CN" # 国家编码
|
||
|
|
}
|
||
|
|
formData = {
|
||
|
|
"serviceCode": "EXP_RECE_REGISTER_ROUTE",
|
||
|
|
"accessToken": accessToken,
|
||
|
|
"timestamp": sftimestamp,
|
||
|
|
"partnerID": "MDSKJJ1KDLJN",
|
||
|
|
"requestID": requestID,
|
||
|
|
"msgData": orjson.dumps(msgData).decode(encoding="utf-8")
|
||
|
|
}
|
||
|
|
response_data = requests.post(url=uri, data=formData,
|
||
|
|
headers={"Content-Type": "application/x-www-form-urlencoded", "charset": "UTF-8"})
|
||
|
|
print(response_data.json(), "=========")
|
||
|
|
res = response_data.json()
|
||
|
|
apiResultData = jmespath.search(data=res, expression="apiResultData")
|
||
|
|
apiResultData = orjson.loads(apiResultData)
|
||
|
|
return Response(data=apiResultData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
|
||
|
|
SF推送ViewSetsRouter = SimpleRouter()
|
||
|
|
SF推送ViewSetsRouter.register(prefix="", viewset=SF推送ViewSets, basename="SF推送ViewSets")
|