six_001
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import orjson
|
||||
import pydash
|
||||
import requests
|
||||
from django.forms import model_to_dict
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
from wechat_数据库.支付订单数据库.商品订单数据 import order订单
|
||||
|
||||
|
||||
class 发货信息录入ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="enter_the_order")
|
||||
def 录入用户下单的订单(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None) # 小程序的openid
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None) # 小程序的
|
||||
out_trade_no = request.data.get("out_trade_no", None) # 商家侧的订单号
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", out_trade_no)
|
||||
订单对象 = order订单.objects.get(order支付订单号=out_trade_no, order支付状态="支付成功")
|
||||
商品标题 = pydash.get(obj=model_to_dict(instance=订单对象, fields=None), path="order商品数据.商品标题")
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token={mini_token}"
|
||||
upload_time = datetime.datetime.now(tz=ZoneInfo("Asia/Shanghai")).isoformat(timespec="seconds")
|
||||
录入订单数据 = {
|
||||
"order_key": {
|
||||
"order_number_type": 1, # 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号
|
||||
"mchid": "1700383419",
|
||||
"out_trade_no": out_trade_no,
|
||||
},
|
||||
"logistics_type": 1, # 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
|
||||
"delivery_mode": 1, # 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
|
||||
"shipping_list": [
|
||||
{
|
||||
"express_company": "EMS",
|
||||
"tracking_no": 订单对象.order物流公司订单编号,
|
||||
"item_desc": "元宝零售",
|
||||
# "contact": {"consignor_contact": "18860891975", "receiver_contact": "18860891970"}
|
||||
},
|
||||
],
|
||||
"upload_time": upload_time,
|
||||
# "payer": {"openid": "ohQkD7NJ5EASxdh6ajad4QR_6i78"}
|
||||
"payer": {"openid": self_mini_openid},
|
||||
}
|
||||
json_data = orjson.dumps(录入订单数据, option=orjson.OPT_SORT_KEYS, ).decode(encoding="utf-8")
|
||||
data = requests.post(url=uri, data=json_data)
|
||||
resData = data.json()
|
||||
# 最后更新物流的状态
|
||||
订单对象.order物流状态 = order订单.order订单choosies物流状态.待收货.value
|
||||
订单对象.save()
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=resData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="configure_path")
|
||||
def 消息跳转路径设置(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
data = requests.post(url="https://api.weixin.qq.com/wxa/sec/order/set_msg_jump_path",
|
||||
params={"access_token": mini_token, }, json={"path": "/pages/OrderPages/OrderPages"},
|
||||
)
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", data.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="notifyConfirmReceive")
|
||||
def 确认收货提醒(self, request: Request):
|
||||
"""如你已经从你的快递物流服务方获知到用户已经签收相关商品,可以通过该接口提醒用户及时确认收货,以提高资金结算效率,每个订单仅可调用一次。"""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
requests.post(url="https://api.weixin.qq.com/wxa/sec/order/notify_confirm_receives",
|
||||
params={"access_token": mini_token, })
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,50 @@
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
|
||||
|
||||
class 主页分享页面接口ViewSets(ViewSet):
|
||||
img_主页面分享时的图片 = "https://hudie.sixgou.com/six/aa35a95a5be61ba1bc38f856fabf3978.png"
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="onShareAppMessage")
|
||||
def 主页群分享接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
page_path = request.data.get("page_path", None)
|
||||
# 如果需要携带参数, 需要在路由的后面 ? 添加 key=value的格式;
|
||||
分享参数 = {
|
||||
"superior_unionid": self_mini_unionid,
|
||||
"shareType": "小程序推荐",
|
||||
}
|
||||
print(分享参数)
|
||||
result = "&".join([f"{key}={value}" for key, value in 分享参数.items()])
|
||||
print("================", result, self_mini_openid, "炎什么值拿不到了呢?")
|
||||
messageData = {
|
||||
"title": "🧧🧧🧧无门槛代金券,快来领!!!",
|
||||
"path": f"{page_path}?{result}",
|
||||
"imageUrl": self.img_主页面分享时的图片,
|
||||
}
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=messageData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="onShareTimeline")
|
||||
def 主页朋友圈分享的功能接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
|
||||
page_path = request.data.get("page_path", None)
|
||||
# 如果需要携带参数, 需要在路由的后面 ? 添加 key=value的格式
|
||||
messageData = {
|
||||
"title": "🧧🧧🧧无门槛代金券,快来领!!!",
|
||||
"path": f"{page_path}",
|
||||
"imageUrl": self.img_主页面分享时的图片,
|
||||
"query": f"superior_unionid={self_mini_unionid}&shareType=小程序推荐",
|
||||
}
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=messageData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,65 @@
|
||||
import uuid
|
||||
|
||||
import pydash
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.洗衣液商品数据库.六果洗衣液商品 import Goods
|
||||
|
||||
|
||||
class 商品详情页面分享接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="goods_detaile")
|
||||
def 商品详情页面分享群好友接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
page_path = request.data.get("page_path", None)
|
||||
idKey = request.data.get("idKey", None)
|
||||
my_uuid = uuid.UUID(idKey)
|
||||
goods = Goods.objects.get(idKey=idKey)
|
||||
print(goods.goods_商品销售规格)
|
||||
主图图片链接 = pydash.get(obj=goods, path="goods_商品销售规格.0.goods_商品详情图片.主图.0")
|
||||
分享参数 = {
|
||||
"superior_unionid": self_mini_unionid,
|
||||
"shareType": "好物推荐",
|
||||
"goodID": idKey,
|
||||
}
|
||||
result = "&".join([f"{key}={value}" for key, value in 分享参数.items()])
|
||||
messageData = {
|
||||
"title": "🧧“洗”出好运,免费带走,📢 刚薅到的羊毛!这瓶洗衣液真的不要钱!!!!!",
|
||||
"path": f"{page_path}?{result}",
|
||||
"imageUrl": 主图图片链接,
|
||||
}
|
||||
print(messageData)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=messageData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="timeline_goods_detaile")
|
||||
def 商品详情页面分享朋友圈接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
|
||||
page_path = request.data.get("page_path", None)
|
||||
idKey = request.data.get("idKey", None)
|
||||
goods = Goods.objects.get(idKey=idKey)
|
||||
主图图片链接 = pydash.get(obj=goods, path="goods_商品销售规格.0.goods_商品详情图片.主图.0")
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", 主图图片链接)
|
||||
分享参数 = {
|
||||
"superior_unionid": self_mini_unionid,
|
||||
"shareType": "好物推荐",
|
||||
"goodID": idKey,
|
||||
}
|
||||
result = pydash.join(array=[f"{key}={value}" for key, value in 分享参数.items()], separator="&")
|
||||
messageData = {
|
||||
"title": "🧧“洗”出好运,免费带走,📢 刚薅到的羊毛!这瓶洗衣液真的不要钱!!!!!",
|
||||
"path": f"{page_path}",
|
||||
"imageUrl": 主图图片链接,
|
||||
"query": result,
|
||||
}
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=messageData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,61 @@
|
||||
import pydash
|
||||
from django.forms import model_to_dict
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_数据库.洗衣液商品数据库.六果洗衣液商品 import goods商品
|
||||
|
||||
|
||||
class 幸运拼团分享接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="message_lucky")
|
||||
def 幸运拼团群分享接口奖励积分(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
# 如果需要携带参数, 需要在路由的后面 ? 添加 key=value的格式;
|
||||
page_path = request.data.get("page_path", None)
|
||||
idKey = request.data.get("idKey", None)
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 难道我没有拿到值的吗?", idKey)
|
||||
参团商品对象 = goods商品.objects.get(id_主键_goods商品=idKey)
|
||||
goods数据 = model_to_dict(instance=参团商品对象, fields=None)
|
||||
分享图片链接 = pydash.get(obj=goods数据, path="goods商品数据.商品图片.主图.0")
|
||||
messageData = {
|
||||
"title": "🧧🧧🧧洗衣液,居然还可以这样买!!!!",
|
||||
"path": f"{page_path}?superior_unionid={self_user_unionid}&shareType=幸运拼团",
|
||||
"imageUrl": 分享图片链接,
|
||||
}
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=messageData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="timeline_lucky")
|
||||
def 幸运拼团朋友圈分享的奖励接口(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
page_path = request.data.get("page_path", None)
|
||||
# 如果需要携带参数, 需要在路由的后面 ? 添加 key=value的格式
|
||||
idKey = request.data.get("idKey", None)
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", idKey)
|
||||
# goods = goods商品.objects.get(idKey=idKey)
|
||||
goods = goods商品.objects.get(id_主键_goods商品=idKey)
|
||||
goods数据 = model_to_dict(instance=goods, fields=None)
|
||||
分享图片链接 = pydash.get(obj=goods数据, path="goods商品数据.商品图片.主图.0")
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", 分享图片链接)
|
||||
messageData = {
|
||||
"title": "🧧🧧🧧洗衣液,居然还可以这样买!!!!",
|
||||
"path": f"{page_path}",
|
||||
"imageUrl": "https://hudie.xiao.band/icon/Ll8-7G-3PFWEc6e26d282e20a598c05c15161ea19b5e.png",
|
||||
"query": f"superior_unionid={self_user_unionid}"
|
||||
}
|
||||
积分朋友圈数据 = {
|
||||
"title": "🧧🧧🧧洗衣液,居然还可以这样买!!!!",
|
||||
"path": f"{page_path}",
|
||||
"imageUrl": 分享图片链接,
|
||||
"query": f"superior_unionid={self_user_unionid}&shareType=商品详情分享朋友圈"
|
||||
}
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=积分朋友圈数据), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,63 @@
|
||||
import pydash
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import weiuser
|
||||
from wechat_项目工具包.腾讯地图.腾讯地图工具 import wei地图工具
|
||||
|
||||
|
||||
class 小程序用户的位置接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="locating")
|
||||
def 解析用户的定位(self, request: Request):
|
||||
"""前端用户:发起定位请求的时候, """
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
result = request.data.get("result", None)
|
||||
print("\n🍎 🍏 🍊 获取用户定位的请求进来了🍊 🍎 🍏 \n", self_mini_openid, self_mini_unionid)
|
||||
six六果对象, sixBool = weiuser.objects.get_or_create(unionid=self_mini_unionid) # 拿到当前的用户请求的对象
|
||||
# 判断 当前用户,是否已经拿有位置的信息数据了
|
||||
if six六果对象.user_区县:
|
||||
# 当这里为true的时候就可以直接返回了
|
||||
return Response()
|
||||
else:
|
||||
纬度 = pydash.get(obj=result, path="latitude")
|
||||
经度 = pydash.get(obj=result, path="longitude")
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 用户的定位的数据", result)
|
||||
地图解析结果 = wei地图工具.经纬度转换为地址(location=f"{纬度},{经度}")
|
||||
省 = pydash.get(obj=地图解析结果, path="result.address_component.province")
|
||||
市 = pydash.get(obj=地图解析结果, path="result.address_component.city")
|
||||
区 = pydash.get(obj=地图解析结果, path="result.address_component.district")
|
||||
街道 = pydash.get(obj=地图解析结果, path="result.address_component.street_number")
|
||||
街道号码 = pydash.get(obj=地图解析结果, path="result.address_component.street")
|
||||
# 开始更新数据库
|
||||
six六果对象.user_区县 = 区
|
||||
six六果对象.user_省份 = 省
|
||||
six六果对象.user_城市 = 市
|
||||
six六果对象.user_街道信息 = 街道
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="ip")
|
||||
def 解析用户IP地址接口(self, request: Request):
|
||||
""" """
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', False)
|
||||
ip = pydash.head(x_forwarded_for.split(','))
|
||||
mini_unionid_user = weiuser.objects.get(unionid=self_mini_unionid, )
|
||||
if mini_unionid_user.user_省份 is None or mini_unionid_user.user_区县 is None or mini_unionid_user.user_城市 is None:
|
||||
weiData = wei地图工具.ip地址转为地址(x_forwarded_for=ip, )
|
||||
province_省份 = pydash.get(obj=weiData, path="result.ad_info.province")
|
||||
city_城市 = pydash.get(obj=weiData, path="result.ad_info.city")
|
||||
district_区县 = pydash.get(obj=weiData, path="result.ad_info.district") or None
|
||||
mini_unionid_user.user_省份 = province_省份
|
||||
mini_unionid_user.user_城市 = city_城市
|
||||
mini_unionid_user.user_区县 = district_区县
|
||||
mini_unionid_user.user_IP地址 = ip
|
||||
mini_unionid_user.save()
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,246 @@
|
||||
import jmespath
|
||||
import orjson
|
||||
import pydash
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import BaseChannelLayer, get_channel_layer
|
||||
from django.forms import model_to_dict
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, RedisClientManager, ResData
|
||||
from wechat_数据库.地图定位.用户定位数据库 import weiuser地图定位
|
||||
from wechat_数据库.用户数据库.小程序用户地址 import weiuser微信用户地址
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import weiuser
|
||||
from wechat_项目工具包.腾讯地图.腾讯地图工具 import OriginPointOptional, wei地图工具
|
||||
|
||||
redis_socked = RedisClientManager().get_client(db_name="redis_5")
|
||||
|
||||
example通道层实例: BaseChannelLayer = get_channel_layer(alias="default")
|
||||
|
||||
|
||||
class 用户配送地址ViewSets(ViewSet):
|
||||
def update更新用户头像事件(self, self_mini_unionid):
|
||||
channel_id = redis_socked.get(self_mini_unionid)
|
||||
user_obj = weiuser.objects.get(unionid=self_mini_unionid)
|
||||
user_data = model_to_dict(instance=user_obj, fields=None, exclude=None)
|
||||
async_to_sync(awaitable=example通道层实例.send)(channel=channel_id,
|
||||
message={"type": "update_更新用户头像",
|
||||
"text": orjson.dumps(user_data,
|
||||
option=orjson.OPT_SORT_KEYS).decode(
|
||||
encoding="utf-8")
|
||||
})
|
||||
|
||||
def update更新用户手机号码方法(self, address, self_mini_openid, self_user_unionid):
|
||||
pass
|
||||
用户手机号码 = pydash.get(obj=address, path="telNumber")
|
||||
用户昵称 = pydash.get(obj=address, path="userName")
|
||||
用户所在省 = pydash.get(obj=address, path="provinceName")
|
||||
用户所在市 = pydash.get(obj=address, path="cityName")
|
||||
用户所在区县 = pydash.get(obj=address, path="countyName")
|
||||
用户所在街道 = pydash.get(obj=address, path="detailInfo")
|
||||
weiuser.objects.filter(unionid=self_user_unionid).update(
|
||||
uesr_手机号码=用户手机号码, user_昵称=用户昵称,
|
||||
user_省份=用户所在省, user_城市=用户所在市, user_区县=用户所在区县,
|
||||
user_街道信息=用户所在街道
|
||||
)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="first_add")
|
||||
def 首次添加用户收件地址(self, request: Request):
|
||||
""""""
|
||||
addressData = request.data.get("addressData", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
self.update更新用户手机号码方法(address=addressData, self_mini_openid=self_mini_openid,
|
||||
self_user_unionid=self_mini_unionid)
|
||||
self.update更新用户头像事件(self_mini_unionid=self_mini_unionid)
|
||||
|
||||
a, b = weiuser微信用户地址.objects.update_or_create(
|
||||
address=addressData, mini_unionid=self_mini_unionid, mini_openid=self_mini_openid,
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.是默认地址.value,
|
||||
)
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid, ).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="query_all")
|
||||
def 查询当前用户的全部地址(self, request: Request):
|
||||
"""查询当前用户所有的配置过的配送地址"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress", "mini_unionid", "mini_openid")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "在这里返回的吗"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="add")
|
||||
def 添加用户地址(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
addressData = request.data.get("addressData", None)
|
||||
self.update更新用户手机号码方法(address=addressData, self_mini_openid=self_mini_openid,
|
||||
self_user_unionid=self_mini_unionid)
|
||||
|
||||
self.update更新用户头像事件(self_mini_unionid=self_mini_unionid)
|
||||
|
||||
是否新存在 = weiuser微信用户地址.objects.filter(address=addressData, mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).exists()
|
||||
if 是否新存在:
|
||||
# 这里说明的是用户首次添加新地址成功了,应该更新数据为 默认地址,
|
||||
weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid, mini_unionid=self_mini_unionid).update(
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.不是默认地址.value)
|
||||
print("判断,同时更新的当前所有的地址都为不是默认的值,")
|
||||
weiuser微信用户地址.objects.filter(address=addressData, mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).update(
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.是默认地址.value,
|
||||
)
|
||||
print("将当前的地址更新为默认值")
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress",
|
||||
)
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "地址相同"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
else:
|
||||
# 同时还需要将以前的地址全部更新为非默认地址,
|
||||
创建新对象, 是否首次创建 = weiuser微信用户地址.objects.update_or_create(
|
||||
address=addressData, mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid) # 在这里更新了所有的地址都不是 默认的地址
|
||||
(weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid, mini_unionid=self_mini_unionid)
|
||||
.update(isDefaultAddress=weiuser微信用户地址.choicesAddress.不是默认地址.value))
|
||||
# 创建新对象.isDefaultAddress = weiuser微信用户地址.choicesAddress.是默认地址.value
|
||||
# 创建新对象.save()
|
||||
weiuser微信用户地址.objects.filter(address=addressData, mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).update(
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.是默认地址.value,
|
||||
)
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress",
|
||||
)
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "添加成功"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="delete")
|
||||
def 单独删除地址(self, request: Request):
|
||||
"""删除单个地址"""
|
||||
idKey = request.data.get("idKey", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
a, b = weiuser微信用户地址.objects.filter(id_主键_配送地址=idKey).delete()
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_openid=self_mini_openid,
|
||||
mini_unionid=self_mini_unionid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="all_delete")
|
||||
def 删除当前用户所有的配送地址(self, request: Request):
|
||||
"""删除全部的地址"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid, mini_openid=self_mini_openid).delete()
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="change_default")
|
||||
def 设为默认地址(self, request: Request):
|
||||
""""""
|
||||
idKey = request.data.get("idKey", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
addressData = weiuser微信用户地址.objects.get(id_主键_配送地址=idKey).address
|
||||
self.update更新用户手机号码方法(address=addressData,
|
||||
self_mini_openid=self_mini_openid,
|
||||
self_user_unionid=self_mini_unionid)
|
||||
self.update更新用户头像事件(self_mini_unionid=self_mini_unionid)
|
||||
|
||||
# 将所有的先更新为非默认地址
|
||||
weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid, mini_openid=self_mini_openid).update(
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.不是默认地址.value)
|
||||
weiuser微信用户地址.objects.filter(id_主键_配送地址=idKey, mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).update(
|
||||
isDefaultAddress=weiuser微信用户地址.choicesAddress.是默认地址.value)
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="update")
|
||||
def 更新当前配送地址(self, request: Request):
|
||||
""""""
|
||||
addressData = request.data.get("addressData", None)
|
||||
idkey = request.data.get("idkey", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
self.update更新用户手机号码方法(address=addressData, self_mini_openid=self_mini_openid,
|
||||
self_user_unionid=self_mini_unionid)
|
||||
对象是否存在 = weiuser微信用户地址.objects.filter(address=addressData,
|
||||
mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).exists()
|
||||
self.update更新用户头像事件(self_mini_unionid=self_mini_unionid)
|
||||
if 对象是否存在:
|
||||
# 说明用户当前是存在的啦(说明,addressData)是有相同的值存在的
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "没有更新"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
else:
|
||||
weiuser微信用户地址.objects.filter(id_主键_配送地址=idkey).update(address=addressData)
|
||||
查询当前用户的全部地址 = weiuser微信用户地址.objects.filter(mini_unionid=self_mini_unionid,
|
||||
mini_openid=self_mini_openid).values(
|
||||
"id_主键_配送地址", "id_str", "address", "isDefaultAddress")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=查询当前用户的全部地址, dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="locating")
|
||||
def 解析用户的定位(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
result = request.data.get("result", None)
|
||||
errMsg = jmespath.search(data=result, expression="errMsg")
|
||||
latitude = jmespath.search(data=result, expression="latitude")
|
||||
longitude = jmespath.search(data=result, expression="longitude")
|
||||
speed = jmespath.search(data=result, expression="speed")
|
||||
accuracy = jmespath.search(data=result, expression="accuracy")
|
||||
altitude = jmespath.search(data=result, expression="altitude")
|
||||
verticalAccuracy = jmespath.search(data=result, expression="verticalAccuracy")
|
||||
horizontalAccuracy = jmespath.search(data=result, expression="horizontalAccuracy")
|
||||
res = wei地图工具.经纬度转换为地址(location=f"{latitude},{longitude}")
|
||||
standard_address = jmespath.search(data=res, expression="result.formatted_addresses.standard_address")
|
||||
省 = jmespath.search(data=res, expression="result.address_component.province")
|
||||
市 = jmespath.search(data=res, expression="result.address_component.city")
|
||||
区 = jmespath.search(data=res, expression="result.address_component.district")
|
||||
# 再计算一下距离
|
||||
起点数据: OriginPointOptional = {"经度": f"{longitude}", "纬度": f"{latitude}", }
|
||||
终点数据: OriginPointOptional = {"经度": str(longitude), "纬度": str(latitude)}
|
||||
两地相多少公里 = wei地图工具.腾讯地图计算二点之间的距离(toData终点=终点数据, fromData起点=起点数据)
|
||||
# print(f"两地相距了{两地相多少公里 / 1000}公里", type(两地相多少公里))
|
||||
weiuser地图定位.objects.update_or_create(
|
||||
map用户openid=self_mini_openid, map用户uniond=self_user_unionid, map两点距离=两地相多少公里,
|
||||
map原点经纬度=起点数据, map终点经纬度=终点数据, map纬度latitude=latitude, map经度longitude=longitude,
|
||||
map省=省, map市=市, map区=区)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,27 @@
|
||||
import requests
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
|
||||
class ShortLinkViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="genwxashortlink")
|
||||
def 获取ShortLink(self, request: Request):
|
||||
"""获取小程序 Short Link,适用于微信内拉起小程序的业务场景。目前对所有非个人主体小程序开放。通过该接口,可以选择生成到期失效和永久有效的小程序短链"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
requests.post(url="https://api.weixin.qq.com/wxa/genwxashortlink", params={"access_token": mini_token, },
|
||||
json={
|
||||
"page_url": f"pageTabBar/Home/Home?superior_unionid={self_mini_unionid}",
|
||||
"page_title": "Homework title", # 短链标题,可自定义,不能包含违法信息,超过 20 字符会用... 截断代替
|
||||
"is_permanent": False,
|
||||
}
|
||||
)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,35 @@
|
||||
import requests
|
||||
from django.core.files.storage import default_storage
|
||||
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||
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, DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
|
||||
class URLLinkViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="generate_urllink")
|
||||
def 获取加密URLLink(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
linkData = requests.post(url="https://api.weixin.qq.com/wxa/generate_urllink",
|
||||
params={"access_token": mini_token, },
|
||||
json={
|
||||
"path": "/pageTabBar/Home/Home",
|
||||
"query": f"superior_unionid={self_mini_unionid}",
|
||||
"expire_type": 1, # 类型
|
||||
"expire_interval": 30, # 多少天后失效
|
||||
"env_version": "develop", # 默认值"release"。要打开的小程序版本。正式版为 "release",体验版为"trial",开发版为"develop",仅在微信外打开时生效。
|
||||
},
|
||||
)
|
||||
print(linkData.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,49 @@
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import pydash
|
||||
import requests
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
|
||||
class Scheme接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="queryscheme")
|
||||
def 查询scheme码(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="generatescheme")
|
||||
def 获取加密scheme码(self, request: Request):
|
||||
"""该接口用于获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
expire_time = str(int(datetime.now(tz=ZoneInfo("Asia/Shanghai")).timestamp()))
|
||||
schemeData = requests.post(url="https://api.weixin.qq.com/wxa/generatescheme",
|
||||
params={"access_token": mini_token, },
|
||||
json={
|
||||
"jump_wxa": {
|
||||
"path": "/pageTabBar/Home/Home",
|
||||
"query": f"superior_unionid={self_mini_unionid}",
|
||||
},
|
||||
"is_expire": True, # 这里好像是必须要填的
|
||||
"expire_interval": 30, # 有效天数,1-30天
|
||||
"expire_type": 1
|
||||
}
|
||||
)
|
||||
print(schemeData.json())
|
||||
openlink = pydash.get(obj=schemeData.json(), path="openlink")
|
||||
print("生成的小程序 scheme 码", openlink)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,54 @@
|
||||
import io
|
||||
|
||||
import requests
|
||||
from django.core.files.storage import default_storage
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
|
||||
class 小程序码接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getwxacode")
|
||||
def 获取小程序码(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
requests.post(url="https://api.weixin.qq.com/wxa/getwxacode", params={"access_token": mini_token, },
|
||||
json={
|
||||
"path": "/pageTabBar/Home/Home?superior_unionid=123",
|
||||
"env_version": "develop", # 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版
|
||||
},
|
||||
)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getwxacodeunlimit")
|
||||
def 获取不限制的小程序码(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
miniCode = requests.post(url="https://api.weixin.qq.com/wxa/getwxacodeunlimit", params={"access_token": mini_token, },
|
||||
json={
|
||||
"page": "tabPage/Home/Home",
|
||||
"scene": f"{self_mini_unionid}", # 这里的值最终会显示 "query": {"scene":"self_mini_unionid"}
|
||||
"env_version": "develop", # 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
|
||||
},
|
||||
)
|
||||
default_storage.save(name=f"{self_mini_unionid}.png", content=io.BytesIO(miniCode.content))
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="createwxaqrcode")
|
||||
def 获取小程序二维码(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,22 @@
|
||||
import requests
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
|
||||
class 获取手机号ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="get")
|
||||
def 测试路由接口(self, request: Request):
|
||||
""""""
|
||||
code = request.data.get("code", None) # 前端传递过来的 code的值
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/wxa/business/getuserphonenumber"
|
||||
phoneData = requests.post(url=uri, params={"access_token": mini_token, }, json={"code": code})
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 获取用户手机号", phoneData.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,27 @@
|
||||
import pydash
|
||||
import requests
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_微信支付证书.江苏六果科技有限公司支付证书.江苏六果科技有限公司支付参数 import sixpay六果科技公司
|
||||
|
||||
|
||||
class 获取稳定版接口调用凭据ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getStableAccessToken")
|
||||
def 测试路由接口(self, request: Request):
|
||||
""""""
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/stable_token"
|
||||
json_data = {
|
||||
"grant_type": "client_credential", "appid": sixpay六果科技公司.appid, "secret": sixpay六果科技公司.appsecret,
|
||||
"force_refresh": True
|
||||
}
|
||||
tokenData = requests.post(url=uri, json=json_data)
|
||||
print(tokenData.json())
|
||||
access_token = pydash.get(obj=tokenData.json(), path="access_token")
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", access_token)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,361 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import orjson
|
||||
import pydash
|
||||
import requests
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.db.models import QuerySet
|
||||
from django.forms import model_to_dict
|
||||
from pydantic import BaseModel, Field
|
||||
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.viewsets import ViewSet
|
||||
from ulid import ULID
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
from wechat_数据库.支付订单数据库.商品订单数据 import order订单, order订单商品数据
|
||||
|
||||
|
||||
class ems物流状态更新模型(BaseModel):
|
||||
"""物流状态更新请求模型"""
|
||||
|
||||
biz_id: Literal["test_biz_id", "1100244903172"] = Field(..., description="业务ID,仅允许 xiao 或 zizi")
|
||||
order_id: str = Field(..., description="商家生成的订单号")
|
||||
delivery_id: Literal["EMS"] = Field(..., description="配送商ID(如 TEST、EMS)")
|
||||
waybill_id: str = Field(..., description="物流订单号")
|
||||
action_time: int = Field(..., description="更新时间戳(秒级)")
|
||||
action_type: int = Field(..., description="操作类型编码")
|
||||
action_msg: str = Field(..., description="操作描述")
|
||||
|
||||
|
||||
class EMS物流ViewSets(ViewSet):
|
||||
ems_biz_id = "1100244903172"
|
||||
ems_delivery_id = "EMS"
|
||||
ems_password = "xiao792282"
|
||||
|
||||
def ems发件人信息(self):
|
||||
ems发件人信息数据 = {
|
||||
"name": "六果泡泡", # 否 发/收件人姓名,不超过64字节
|
||||
"tel": "18860891975", # string 否 发/收件人座机号码,若不填写则必须填写 mobile,不超过32字节
|
||||
"mobile": "18860891970", # string 否 发/收件人手机号码,若不填写则必须填写 tel,不超过32字节
|
||||
"company": "江苏六果科技有限公司", # string 否 发/收件人公司名称,不超过64字节
|
||||
"post_code": "225300", # string 否 发/收件人邮编,不超过10字节
|
||||
"country": "中国", # string 否 发/收件人国家,不超过64字节
|
||||
"province": "江苏省", # string 否 发/收件人省份,比如:"广东省",不超过64字节
|
||||
"city": "泰州市", # string 否 发/收件人市/地区,比如:"广州市",不超过64字节
|
||||
"area": "海陵区", # string 否 发/收件人区/县,比如:"海珠区",不超过64字节
|
||||
"address": "", # string 否 发/收件人详细地址,比如:"XX路XX号XX大厦XX",不超过512 字节
|
||||
}
|
||||
return ems发件人信息数据
|
||||
|
||||
def ems收件人信息(self, order订单号):
|
||||
订单对象 = order订单.objects.get(order物流订单号=order订单号)
|
||||
orderData = model_to_dict(instance=订单对象, fields=None)
|
||||
provinceName = pydash.get(obj=orderData, path="order用户配送地址.address.provinceName")
|
||||
cityName = pydash.get(obj=orderData, path="order用户配送地址.address.cityName") # 市
|
||||
countyName = pydash.get(obj=orderData, path="order用户配送地址.address.countyName") # 区
|
||||
detailInfoNew = pydash.get(obj=orderData, path="order用户配送地址.address.detailInfoNew") # 详细地址
|
||||
telNumber = pydash.get(obj=orderData, path="order用户配送地址.address.telNumber") # 详细地址
|
||||
detailInfo = pydash.get(obj=orderData, path="order用户配送地址.address.detailInfo") # 详细地址
|
||||
userName = pydash.get(obj=orderData, path="order用户配送地址.address.userName") # 详细地址
|
||||
nationalCode = pydash.get(obj=orderData, path="order用户配送地址.address.nationalCode") # 详细地址
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", telNumber)
|
||||
return {
|
||||
"name": userName, # 否 发/收件人姓名,不超过64字节
|
||||
"tel": telNumber, # string 否 发/收件人座机号码,若不填写则必须填写 mobile,不超过32字节
|
||||
"mobile": telNumber, # string 否 发/收件人手机号码,若不填写则必须填写 tel,不超过32字节
|
||||
"company": "", # string 否 发/收件人公司名称,不超过64字节
|
||||
"post_code": nationalCode, # string 否 发/收件人邮编,不超过10字节
|
||||
"country": "中国", # string 否 发/收件人国家,不超过64字节
|
||||
"province": provinceName, # string 否 发/收件人省份,比如:"广东省",不超过64字节
|
||||
"city": cityName, # string 否 发/收件人市/地区,比如:"广州市",不超过64字节
|
||||
"area": countyName, # string 否 发/收件人区/县,比如:"海珠区",不超过64字节
|
||||
"address": detailInfoNew, # string 否 发/收件人详细地址,比如:"XX路XX号XX大厦XX",不超过512 字节
|
||||
}
|
||||
|
||||
def cargo包裹信息(self):
|
||||
return {
|
||||
"count": 1, # number 是 包裹数量, 默认为1
|
||||
"weight": 4, # number 是 货物总重量,比如1.2,单位是千克(kg)
|
||||
"space_x": 1, # number 是 货物长度,比如20.0,单位是厘米(cm)
|
||||
"space_y": 1, # number 是 货物宽度,比如15.0,单位是厘米(cm)
|
||||
"space_z": 1, # number 是 货物高度,比如10.0,单位是厘米(cm)
|
||||
"detail_list": [
|
||||
{
|
||||
"name": "商品名称", # string 是 商品名,不超过128字节
|
||||
"count": 1, # number 是 商品数量
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
def shop商品信息(self, order订单号):
|
||||
订单对象 = order订单.objects.get(order物流订单号=order订单号)
|
||||
orderData = model_to_dict(instance=订单对象, fields=None)
|
||||
购物车商品列表: QuerySet[order订单商品数据] = order订单商品数据.objects.filter(wai_订单=订单对象)
|
||||
print(购物车商品列表)
|
||||
detail_list = []
|
||||
for goods in 购物车商品列表:
|
||||
商品数据 = model_to_dict(instance=goods, fields=None, exclude=None)
|
||||
detail_list.append(
|
||||
{
|
||||
"goods_name": pydash.get(obj=商品数据, path="order_商品标题"),
|
||||
"goods_img_url": pydash.get(obj=商品数据, path="order_商品详情图片.主图.0"),
|
||||
"goods_desc": "",
|
||||
},
|
||||
)
|
||||
goods_count = pydash.get(obj=orderData, path="order购物车商品数量")
|
||||
shop商品信息数据 = {
|
||||
"wxa_path": "/pages/OrderPages/OrderPages", # string 否 商家小程序的路径,建议为订单页面
|
||||
# "img_url": "", # string 否 商品缩略图 url;shop.detail_list为空则必传,shop.detail_list非空可不传。
|
||||
# "goods_name": "", # string 否 商品名称, 不超过128字节;shop.detail_list为空则必传,shop.detail_list非空可不传。
|
||||
# goods_count 否 商品详情列表,适配多商品场景,用以消息落地页展示。(新规范,新接入商家建议用此字段)
|
||||
"goods_count": goods_count, # 商品数量;shop.detail_list为空则必传。shop.detail_list非空可不传,默认取shop.detail_list的size
|
||||
"detail_list": detail_list,
|
||||
}
|
||||
return shop商品信息数据
|
||||
|
||||
def insured保价信息(self):
|
||||
insured保价信息数据 = {
|
||||
"use_insured": 0, # number 否 是否保价,0 表示不保价,1 表示保价
|
||||
"insured_value": 0, # number 否 保价金额,单位是分,比如: 10000 表示 100 元
|
||||
}
|
||||
return insured保价信息数据
|
||||
|
||||
def service服务类型(self):
|
||||
service服务类型数据 = {
|
||||
"service_type": 6, # number 是 服务类型ID,详见已经支持的快递公司基本信息
|
||||
"service_name": "标准快递", # string 是 服务名称,详见已经支持的快递公司基本信息
|
||||
}
|
||||
return service服务类型数据
|
||||
|
||||
def 生成最终完整的数据(self, order物流订单号):
|
||||
订单对象 = order订单.objects.get(order物流订单号=order物流订单号)
|
||||
orderData = model_to_dict(instance=订单对象, fields=None)
|
||||
order_id = pydash.get(obj=orderData, path="order物流订单号")
|
||||
收件人openid = pydash.get(obj=orderData, path="order支付者openid")
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", self.ems发件人信息())
|
||||
完整数据 = {
|
||||
"add_source": 0,
|
||||
"order_id": order_id,
|
||||
"openid": 收件人openid,
|
||||
"delivery_id": "TEST",
|
||||
"biz_id": "test_biz_id",
|
||||
"custom_remark": "易碎物品",
|
||||
"sender": self.ems收件人信息(order订单号=order物流订单号), # 收件人的信息
|
||||
"receiver": self.ems发件人信息(), # 发件人的信息
|
||||
"shop": self.shop商品信息(order订单号=order物流订单号), # 商品的信息
|
||||
"cargo": self.cargo包裹信息(), # 包果的信息
|
||||
"insured": self.insured保价信息(), # 保价信息
|
||||
"service": self.service服务类型(), # 服务类型
|
||||
}
|
||||
return 完整数据
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="bindAccount")
|
||||
def 绑定账号(self, request: WSGIRequest | Request):
|
||||
""""""
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/express/business/account/bind?access_token={mini_token}"
|
||||
ems数据 = {
|
||||
"type": "bind",
|
||||
"biz_id": "1100244903172",
|
||||
"delivery_id": "EMS",
|
||||
"password": "xiao@792282",
|
||||
}
|
||||
data = requests.post(url=uri, json=ems数据)
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 绑定账号🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="unbindAccount")
|
||||
def 解绑账号(self, request: WSGIRequest | Request):
|
||||
""""""
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/express/business/account/bind?access_token={mini_token}"
|
||||
ems数据 = {
|
||||
"type": "unbind",
|
||||
"biz_id": "1100244903172",
|
||||
"delivery_id": "EMS",
|
||||
"password": "xiao@792282",
|
||||
}
|
||||
data = requests.post(url=uri, json=ems数据)
|
||||
print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 ", data.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="getAllDelivery")
|
||||
def 获取支持的快递公司列表(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/express/business/delivery/getall?access_token={mini_token}"
|
||||
data = requests.get(url=uri, )
|
||||
emdData = orjson.loads(data.content.decode(encoding="utf-8"))
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=emdData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="getAllAccount")
|
||||
def 获取所有绑定的物流账号(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/express/business/account/getall?access_token={mini_token}"
|
||||
data = requests.get(url=uri)
|
||||
print(orjson.loads(
|
||||
orjson.dumps(data.content.decode(encoding="utf-8"), option=orjson.OPT_SORT_KEYS, ).decode(
|
||||
encoding="utf-8")))
|
||||
返回数据 = orjson.loads(data.content.decode(encoding="utf-8"))
|
||||
print(返回数据, type(返回数据))
|
||||
print(orjson.loads(data.content.decode(encoding="utf-8")))
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=返回数据), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="addOrder")
|
||||
def 生成运单(self, request: Request):
|
||||
""""""
|
||||
# 需要的参数
|
||||
order物流订单号 = request.data.get("order物流订单号", None)
|
||||
print(order物流订单号, "这里没有值的吗")
|
||||
order订单对象 = order订单.objects.get(order物流订单号=order物流订单号)
|
||||
res = self.生成最终完整的数据(order物流订单号=order物流订单号)
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎order物流订单号order物流订单号 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", order物流订单号)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
运单请求接口 = f"https://api.weixin.qq.com/cgi-bin/express/business/order/add?access_token={mini_token}"
|
||||
json_完整的数据 = orjson.dumps(res).decode(encoding="utf-8")
|
||||
data = requests.post(url=运单请求接口, data=json_完整的数据, )
|
||||
print("请求生成运单的接口,生成数据", data.json())
|
||||
waybill_id = pydash.get(obj=data.json(), path="waybill_id")
|
||||
更新订单对象 = order订单.objects.get(order物流订单号=order物流订单号)
|
||||
更新订单对象.order物流公司订单编号 = waybill_id
|
||||
# 更新订单对象.order物流数据 = 物流订单默认数据
|
||||
更新订单对象.save()
|
||||
# print( "🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 运单返回数据", data.json( ) )
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="testUpdateOrder")
|
||||
def 模拟更新订单状态(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
order物流公司订单编号 = request.data.get("order物流公司订单编号", None)
|
||||
order物流订单号 = request.data.get("order物流订单号", None)
|
||||
print(order物流公司订单编号, order物流订单号, "为什么这里没有值啊")
|
||||
mini_token = sixToken.get_mini_token()
|
||||
utcDate = datetime.now(tz=ZoneInfo("utc"))
|
||||
timestamp = int(datetime.now(tz=ZoneInfo("Asia/Shanghai")).timestamp())
|
||||
milliseconds_int = ULID().milliseconds
|
||||
模拟更新物流状态 = f"https://api.weixin.qq.com/cgi-bin/express/business/test_update_order?access_token={mini_token}"
|
||||
模拟数据_揽件成功 = {
|
||||
"biz_id": "test_biz_id",
|
||||
"order_id": order物流订单号, # 商家生成的订单号
|
||||
"delivery_id": "TEST", #
|
||||
"waybill_id": order物流公司订单编号, # 物流订单号
|
||||
"action_time": int(time.time()), # 这里是更新发的时间戳
|
||||
"action_type": 100001,
|
||||
"action_msg": "揽件阶段-揽件成功",
|
||||
}
|
||||
模拟数据_分配业务员 = {
|
||||
"biz_id": "test_biz_id",
|
||||
"order_id": order物流订单号, # 商家生成的订单号
|
||||
"delivery_id": "TEST", #
|
||||
"waybill_id": order物流公司订单编号, # 物流订单号
|
||||
"action_time": int(time.time()), # 这里是更新发的时间戳
|
||||
"action_type": 100003,
|
||||
"action_msg": "揽件阶段-分配业务员",
|
||||
}
|
||||
模拟数据_更新运输轨迹 = {
|
||||
"biz_id": "test_biz_id",
|
||||
"order_id": order物流订单号, # 商家生成的订单号
|
||||
"delivery_id": "TEST", #
|
||||
"waybill_id": order物流公司订单编号, # 物流订单号
|
||||
"action_time": int(time.time()), # 这里是更新发的时间戳
|
||||
"action_type": 200001,
|
||||
"action_msg": "运输阶段-更新运输轨迹",
|
||||
}
|
||||
模拟数据_开始派送 = {
|
||||
"biz_id": "test_biz_id",
|
||||
"order_id": order物流订单号, # 商家生成的订单号
|
||||
"delivery_id": "TEST", #
|
||||
"waybill_id": order物流公司订单编号, # 物流订单号
|
||||
"action_time": int(time.time()), # 这里是更新发的时间戳
|
||||
"action_type": 300002,
|
||||
"action_msg": "派送阶段-开始派送",
|
||||
}
|
||||
模拟数据_签收成功 = {
|
||||
"biz_id": "test_biz_id",
|
||||
"order_id": order物流订单号, # 商家生成的订单号
|
||||
"delivery_id": "TEST", #
|
||||
"waybill_id": order物流公司订单编号, # 物流订单号
|
||||
"action_time": int(time.time()), # 这里是更新发的时间戳
|
||||
"action_type": 300003,
|
||||
"action_msg": "派送阶段-签收成功",
|
||||
}
|
||||
|
||||
data = requests.post(url=模拟更新物流状态,
|
||||
data=orjson.dumps(模拟数据_揽件成功, option=orjson.OPT_SORT_KEYS, ).decode(encoding="utf-8"))
|
||||
print("🍎 🍏 🍊 🍎 🍏 模拟更新物流状态 🍎 ", data.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getpath")
|
||||
def 查询运单轨迹(self, request: Request):
|
||||
"""查询当前物流订单的轨迹"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token={mini_token}"
|
||||
order物流订单号 = request.data.get("order物流订单号", None)
|
||||
order物流公司订单编号 = request.data.get("order物流公司订单编号", None)
|
||||
postData = requests.post(url=uri, json={"openid": self_mini_openid, "delivery_id": self.ems_delivery_id,
|
||||
"waybill_id": order物流公司订单编号})
|
||||
print(postData.json())
|
||||
print("\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊物流订单查询接口", order物流公司订单编号, order物流订单号)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=postData.json()), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="update_logistics_information")
|
||||
def 更新物流快递数据(self, request: Request):
|
||||
"""这个接口:相当于实时查询当前的 物流的轨迹"""
|
||||
waybill_id = request.data.get("waybill_id", "生成的运单号")
|
||||
order物流公司订单编号 = request.data.get("order物流公司订单编号", None)
|
||||
order物流订单号 = request.data.get("order物流订单号", None)
|
||||
print(order物流公司订单编号, "\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", waybill_id)
|
||||
查询对象 = order订单.objects.get(order物流公司订单编号=order物流公司订单编号, order物流订单号=order物流订单号)
|
||||
print("查询对象", 查询对象)
|
||||
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": "TEST", "waybill_id": 查询对象.order物流公司订单编号,
|
||||
},
|
||||
)
|
||||
print(orjson.loads(emsGetPathData.content.decode(encoding="utf-8")), "=================")
|
||||
resData = orjson.loads(emsGetPathData.content.decode(encoding="utf-8"))
|
||||
查询对象.order物流数据 = resData
|
||||
查询对象.save()
|
||||
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="确认收货")
|
||||
def 确认收货(self, request: Request):
|
||||
""""""
|
||||
print(
|
||||
"确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了确认收货请求进来了")
|
||||
order物流公司订单编号 = request.data.get("order物流公司订单编号", None)
|
||||
order物流订单号 = request.data.get("order物流订单号", None)
|
||||
订单更新对象 = order订单.objects.get(order物流公司订单编号=order物流公司订单编号,
|
||||
order物流订单号=order物流订单号)
|
||||
订单更新对象.order物流状态 = order订单.order订单choosies物流状态.待评价.value
|
||||
订单更新对象.save()
|
||||
httpResData = BaseResponse(resData=ResData(listData=[], dictData={}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
@@ -0,0 +1,85 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
from django.forms import model_to_dict
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import weiuser
|
||||
from wechat_项目工具包.数据库的工具包.更新用户积分 import miniUser用户角色
|
||||
|
||||
|
||||
class 用工关系接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="send")
|
||||
def 推送用工消息(self, request: Request):
|
||||
""""""
|
||||
mini_token = sixToken.get_mini_token()
|
||||
|
||||
template_content = {
|
||||
"data": { # ⚠️ 这个外层 "data" 是微信接口强制要求的嵌套结构
|
||||
"thing1": {"value": "aaaaaaa"}, # 替换为模板实际字段名
|
||||
"amount1": {"value": "12"} # 金额建议纯数字(无¥符号)
|
||||
}
|
||||
}
|
||||
|
||||
# 2. 转为JSON字符串(ensure_ascii=False保留中文,但微信要求最终是转义后的字符串)
|
||||
data_string = json.dumps(template_content, ensure_ascii=False)
|
||||
|
||||
msgData = requests.post(url="https://api.weixin.qq.com/cgi-bin/message/wxopen/employeerelationmsg/send",
|
||||
params={"access_token": mini_token, },
|
||||
json={"template_id": "SFFgGF1bN56_KNd_4HicCFBBfu2PCRwCyQ5upr-EVk9Vdyl4wyyQ7B1mJvjceR29", # 推送消息模板
|
||||
"page": "pageTabBar/Home/Home", # 跳转路径
|
||||
"touser": "ohQkD7A-N93kljcFmkCyG6e_D9vg", # 被推送用户openid
|
||||
"data": data_string
|
||||
})
|
||||
print(msgData.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="解绑用工关系")
|
||||
def 解绑用工关系(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
openid_list = request.data.get("openid_list", None)
|
||||
wecom_token = sixToken.get_wecom_token()
|
||||
infoData = requests.post(url="https://api.weixin.qq.com/wxa/business/unbinduserb2cauthinfo", params={"access_token": wecom_token, }, json={"openid_list": ["oL7T268t3zlOb64IvrN64-XXXXXX"]}, )
|
||||
print(infoData.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="绑定用工关系")
|
||||
def 绑定用工关系(self, request: Request):
|
||||
pass
|
||||
"""绑定用工关系, 前端调用成功了, 就会发送请求到本接口,我们只需要更新一下weiuser数据信息就可以了"""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
six六果对象, sixBool = weiuser.objects.get_or_create(unionid=self_mini_unionid)
|
||||
print("开始绑定用工关系了")
|
||||
if six六果对象.user_绑定用工关系 == miniUser用户角色().用工关系已绑定:
|
||||
six_data_user = model_to_dict(instance=six六果对象, fields=None, exclude=None)
|
||||
print("这里的状态为原来已经绑定用工关系了")
|
||||
return Response(data=six_data_user)
|
||||
else:
|
||||
six六果对象.user_绑定用工关系 = miniUser用户角色().用工关系已绑定
|
||||
six六果对象.save()
|
||||
print("绑定用工关系成功了")
|
||||
six_data_user = model_to_dict(instance=six六果对象, fields=None, exclude=None)
|
||||
return Response(data=six_data_user)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="更新用工关系")
|
||||
def 添加商品数据(self, request: Request):
|
||||
pass
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
six六果对象, sixBool = weiuser.objects.get_or_create(unionid=self_mini_unionid)
|
||||
six六果对象.user_绑定用工关系 = miniUser用户角色().用工关系已绑定
|
||||
six六果对象.save()
|
||||
six_currend_当前用户对象的字典数据 = model_to_dict(instance=six六果对象, fields=None, exclude=None)
|
||||
print("更新用工关系更新用工关系更新用工关系更新用工关系更新用工关系更新用工关系", self_mini_unionid, self_mini_openid)
|
||||
return Response(data=six_currend_当前用户对象的字典数据)
|
||||
@@ -0,0 +1,39 @@
|
||||
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.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
|
||||
|
||||
class 附近小程序ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="addNearbyPoi")
|
||||
def 添加地点(self, request: Request):
|
||||
""""""
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="deleteNearbyPoi")
|
||||
def 删除地点(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getNearbyPoiList")
|
||||
def 查看地点(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="setShowStatus")
|
||||
def 设置展示状态(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user