Files

66 lines
3.1 KiB
Python
Raw Permalink Normal View History

2026-08-02 14:07:04 +08:00
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)