six_001
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
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="order_create")
|
||||
def 快递下订单接口(self, request: WSGIRequest | Request):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
print('============')
|
||||
|
||||
requestID = f"SF{datetime.date.strftime(datetime.datetime.now(), format="%Y%m%d%H%M%S%f")}"
|
||||
|
||||
accessToken = sfToken()
|
||||
沙箱环境 = f"https://sfapi-sbox.sf-express.com/std/service"
|
||||
sftimestamp = str(int(datetime.datetime.now().timestamp()))
|
||||
cargoDetails托寄物信息 = [{"name": "物品", "count": 1}]
|
||||
寄件人 = {
|
||||
"contactType": 1,
|
||||
"company": "1",
|
||||
"contact": "元宝",
|
||||
"mobile": "13800138000",
|
||||
"country": "CN",
|
||||
"province": "江苏省",
|
||||
"city": "泰州市",
|
||||
"county": "海陵区",
|
||||
"address": "城西街道任景路603号"
|
||||
}
|
||||
收件人 = {
|
||||
"contactType": 2,
|
||||
"company": "2",
|
||||
"contact": "大帅",
|
||||
"mobile": "13800138001",
|
||||
"country": "CN",
|
||||
"province": "四川省",
|
||||
"city": "成都市",
|
||||
"county": "新都区",
|
||||
"address": "桂湖街道一社16号"
|
||||
}
|
||||
msgData = {
|
||||
# 响应报文的语言,缺省值为zh-CN
|
||||
"language": "zh-CN",
|
||||
"parcelQty": 1,
|
||||
# 客户订单号,重复使用订单号时返回第一次下单成功时的运单信息
|
||||
"orderId": f"SFOD{datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S%f")}",
|
||||
# 托寄物信息
|
||||
"cargoDetails": cargoDetails托寄物信息,
|
||||
"contactInfoList": [寄件人, 收件人],
|
||||
"isReturnRoutelabel": 1,
|
||||
"isGenWaybillNo": 1,
|
||||
"payMethod": 1,
|
||||
"isDocall": 0,
|
||||
"monthlyCard": "7551234567"
|
||||
}
|
||||
formData = {
|
||||
"serviceCode": "EXP_RECE_CREATE_ORDER",
|
||||
"accessToken": accessToken,
|
||||
"timestamp": sftimestamp,
|
||||
"partnerID": "MDSKJJ1KDLJN",
|
||||
"requestID": requestID,
|
||||
"msgData": orjson.dumps(msgData).decode(encoding="utf-8")
|
||||
}
|
||||
response_data = requests.post(
|
||||
url=沙箱环境, data=formData,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", },
|
||||
)
|
||||
apiResultData = jmespath.search(data=response_data.json(), expression="apiResultData")
|
||||
return Response(data=orjson.loads(apiResultData), status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="order_update")
|
||||
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 = {
|
||||
"dealType": 1,
|
||||
"orderId": "SFOD20251126214101523682",
|
||||
# "totalHeight": 29.98,
|
||||
# "totalLength": 29.98,
|
||||
# "totalVolume": 26946.035992000005,
|
||||
# "totalWeight": 2.09,
|
||||
# "totalWidth": 29.98,
|
||||
"waybillNoInfoList": [
|
||||
{
|
||||
"waybillNo": "SF7444700285553",
|
||||
"waybillType": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
formData = {
|
||||
"serviceCode": "EXP_RECE_UPDATE_ORDER",
|
||||
"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)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="order_search_resp")
|
||||
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 = {
|
||||
"searchType": "1",
|
||||
"orderId": "SFOD20251126214101523682",
|
||||
"language": "zh-cn"
|
||||
}
|
||||
formData = {
|
||||
"serviceCode": "EXP_RECE_SEARCH_ORDER_RESP",
|
||||
"accessToken": accessToken,
|
||||
"timestamp": sftimestamp,
|
||||
"partnerID": sfID,
|
||||
"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"},
|
||||
)
|
||||
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="")
|
||||
@@ -0,0 +1,22 @@
|
||||
import pydash
|
||||
import requests
|
||||
from furl import furl
|
||||
|
||||
sfID = "MDSKJJ1KDLJN"
|
||||
sfCode沙箱码 = "ligo0CNwIN8HLP8kmEguzFRJqpLtsvkQ"
|
||||
sfCode生产环境 = "lxfzgUcYCsVbVaZXFCpN2N6jPnfWYjrs"
|
||||
顺风回调路由 = furl(url=f"https://wecom.fujugongxiang.com/sf/sf_callback/").url
|
||||
|
||||
|
||||
def sfToken():
|
||||
tokneUri = f"https://sfapi-sbox.sf-express.com/oauth2/accessToken"
|
||||
|
||||
response_data = requests.post(url=tokneUri, data={"partnerID": sfID, "secret": sfCode沙箱码})
|
||||
print(response_data.json())
|
||||
accessToken = pydash.get(obj=response_data.json(), path="accessToken")
|
||||
apiResponseID = pydash.get(obj=response_data.json(), path="apiResponseID")
|
||||
return accessToken
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
@@ -0,0 +1,102 @@
|
||||
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")
|
||||
Reference in New Issue
Block a user