six_001
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
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.routers import DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
from ulid import ULID
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.洗衣液商品数据库.六果洗衣液商品 import Goods, goods商品, goods商品Choices
|
||||
|
||||
|
||||
class 商品接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="filter_query_goods")
|
||||
def 根据条件查询商品接口(self, request: Request):
|
||||
""""""
|
||||
# 2. 创建一个新的、按键排序后的字典
|
||||
goodsDataList = goods商品.objects.filter(goods商品类型=goods商品Choices.商城商品.value).values(
|
||||
"id_主键_goods商品", "goods商品数据", "id_str")
|
||||
print("商城查询所有的商品数据", goodsDataList)
|
||||
httpResData = BaseResponse(resData=ResData(listData=goodsDataList, dictData={}), ).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
|
||||
赢免单商品数据 = Goods.objects.filter(goods_商品销售场景=goods商品Choices.赢免单.value).first()
|
||||
data = model_to_dict(instance=赢免单商品数据, fields=None, exclude=None)
|
||||
return Response(data=data)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="query")
|
||||
def 返回商城所有的销售商品信息数据(self, request: Request):
|
||||
"""返回所有的商品信息数据"""
|
||||
data = Goods.objects.filter(goods_商品销售场景=goods商品Choices.商城商品.value).values()
|
||||
httpResData = BaseResponse(resData=ResData(listData=data, dictData={}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="current_goods")
|
||||
def 分享商品查询接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
goodID = request.data.get("goodID", None)
|
||||
goodsDdata = goods商品.objects.get(id_主键_goods商品=goodID)
|
||||
data = model_to_dict(instance=goodsDdata, fields=None)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=data), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="add_goods")
|
||||
def 添加商品接口(self, request: Request):
|
||||
""""""
|
||||
return
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
Goods.objects.update_or_create(
|
||||
goods_商品品牌="六果泡泡",
|
||||
goods_商品信息={
|
||||
"品牌": "六果泡泡",
|
||||
"净重": "20斤装/桶",
|
||||
"香型": "熏衣草",
|
||||
"洁净": "源自天然酵素迅速渗入衣物,去除99种污渍",
|
||||
"除菌": "99%除菌🦠,污渍菌螨,一洗即净,守护健康",
|
||||
},
|
||||
goods_商品标题="六果泡泡 (超划算) 源自天然酵素迅速渗入衣物,99%除菌🦠一洗即净,守护健康",
|
||||
goods_商品标签=["99%除菌🦠", "99种污渍", ],
|
||||
# goods_商品销售场景=goods商品Choices.商城商品.value,
|
||||
goods_商品销售场景=goods商品Choices.赢免单.value,
|
||||
goods_商品搜索标签=["20"],
|
||||
goods_商品销售规格=[
|
||||
{
|
||||
"goods_商品标题": "六果泡泡 (超划算) 源自天然酵素迅速渗入衣物,99%除菌🦠一洗即净,守护健康",
|
||||
"零售价格": 15200, "会员价": 14200, "销售规格": "20斤装/桶",
|
||||
"单个商品订单数量": 1, "单个商品订单总金额": 14200, "商品条码": "", "单个商品实际支付价格": 14200,
|
||||
"成本价": 12000, "净利润": 12200, "可选参数": ["苹果香", "熏衣草"], "商品ID": f"GOOD{ULID()}",
|
||||
"推荐积分": {"企微员工": 200, "推广员": 1000},
|
||||
"goods_商品详情图片": {
|
||||
"主图": ["https://hudie.xiao.band/icon/six.png"],
|
||||
"详情图": ["https://hudie.xiao.band/icon/six.png", "https://hudie.xiao.band/icon/six.png"],
|
||||
},
|
||||
"goods_sku": [
|
||||
{
|
||||
"goods_sku_id": f"{ULID()}",
|
||||
"goods_select_title": "开启衣物芬芳之旅",
|
||||
"goods_sku_list": [
|
||||
{
|
||||
"goods_sku_name": "西瓜", "goods_是否默认选择": True,
|
||||
"goods_sku_主图": ["https://hudie.xiao.band/icon/six.png"],
|
||||
"goods_sku_详情图": ["https://hudie.xiao.band/icon/six.png", "https://hudie.xiao.band/icon/six.png"],
|
||||
},
|
||||
{
|
||||
"goods_sku_name": "桔子", "goods_是否默认选择": False,
|
||||
"goods_sku_主图": ["https://hudie.xiao.band/icon/six.png"],
|
||||
"goods_sku_详情图": ["https://hudie.xiao.band/icon/six.png", "https://hudie.xiao.band/icon/six.png"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
goods_商家推荐标签=["厂家直销", "独家配方", "自产自销", "量大实惠", "品质保证"],
|
||||
)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
商品接口ViewSetsRouter = DefaultRouter()
|
||||
商品接口ViewSetsRouter.register(prefix="", viewset=商品接口ViewSets, basename="")
|
||||
@@ -0,0 +1,26 @@
|
||||
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 DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.支付订单数据库.商品订单数据 import order订单
|
||||
|
||||
|
||||
class 订单管理接口ViewSets(ViewSet):
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="query")
|
||||
def 查询当前用户的订单列表(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
订单查询列表 = order订单.objects.filter(order支付者openid=self_mini_openid, order支付状态="支付成功").values()
|
||||
|
||||
httpResData = BaseResponse(resData=ResData(listData=订单查询列表, dictData={"demo": "11111111111"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
订单管理接口ViewSetsRouter = DefaultRouter()
|
||||
订单管理接口ViewSetsRouter.register(prefix="", viewset=订单管理接口ViewSets, basename="")
|
||||
@@ -0,0 +1,68 @@
|
||||
import jmespath
|
||||
import requests
|
||||
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||
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.routers import DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import weiuser
|
||||
|
||||
|
||||
class 小程序用户头像昵称接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["post"], url_path="chooseAvatar")
|
||||
def 用户头像接口(self, request: Request):
|
||||
""""""
|
||||
chooseAvatar: InMemoryUploadedFile | None = request.FILES.get("chooseAvatar", None)
|
||||
print(chooseAvatar)
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
print(self_user_unionid)
|
||||
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="nickName")
|
||||
def 更新用户昵称(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
nickName = request.data.get("nickName", None)
|
||||
print("获取到的用户昵称", nickName)
|
||||
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="getPhoneNumber")
|
||||
def 获取用户手机号码(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
code = request.data.get("code", None)
|
||||
mini_token = sixToken.get_mini_token()
|
||||
url = f"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={mini_token}"
|
||||
jsonData = {"code": code}
|
||||
resData = requests.post(url=url, json=jsonData).json()
|
||||
print(resData, "❌❌❌❌❌❌❌❌❌❌❌❌")
|
||||
phoneNumber = jmespath.search(data=resData, expression="phone_info.phoneNumber")
|
||||
print(phoneNumber)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"phoneNumber": phoneNumber}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="search")
|
||||
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.get(unionid=self_mini_unionid)
|
||||
resData = model_to_dict(instance=用户头像信息, fields=["avatar", "nickName"])
|
||||
print(self_mini_unionid)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=resData), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
小程序用户头像昵称接口ViewSetsRouter = DefaultRouter()
|
||||
小程序用户头像昵称接口ViewSetsRouter.register(prefix="", viewset=小程序用户头像昵称接口ViewSets, basename="")
|
||||
@@ -0,0 +1,119 @@
|
||||
"""
|
||||
Author: xiao 792282@qq.com
|
||||
Date: 2025-08-10 11:36:05
|
||||
LastEditors: xiao 792282@qq.com
|
||||
LastEditTime: 2025-08-17 13:38:40
|
||||
FilePath: django_小程序/小程序服务端服务接口/小程序用户登陆接口.py
|
||||
Description: 这是默认设置,可以在设置》工具》File Description中进行配置
|
||||
"""
|
||||
|
||||
import jmespath
|
||||
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.routers import SimpleRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import weiuser
|
||||
from wechat_项目工具包.小程序工具包.小程序用户授权数据 import wei小程序服务端工具
|
||||
from wechat_项目工具包.微信支付工具包.微信支付类 import paymentCategory, wechatPay
|
||||
|
||||
上级分享者的默认值 = "六果"
|
||||
|
||||
|
||||
class 六果科技小程序用户登陆(ViewSet):
|
||||
|
||||
def res_obj_data_func(self, self_user: weiuser) -> dict[str, str]:
|
||||
""""""
|
||||
res_obj_data = model_to_dict(instance=self_user, fields=None, exclude=None)
|
||||
return res_obj_data
|
||||
|
||||
@action(detail=False, methods=["post", ], url_path="mini_login")
|
||||
def 小程序用户(self, request: Request, *args, **kwargs):
|
||||
""""""
|
||||
encryptedData = request.data.get("encryptedData", None) # 解密群号所需要的参数
|
||||
iv = request.data.get("iv", None) # 解密群号所需要的参数 iv
|
||||
code: str = request.data.get("code", "")
|
||||
# superior_openid = request.data.get( "superior_openid", ) # 如果上级是默认的值 则说明是没有上级的,
|
||||
superior_unionid = request.data.get("superior_unionid", 上级分享者的默认值) # 如果上级是默认的值 则说明是没有上级的,
|
||||
scene = request.data.get("scene", None) # 微信用户进入小程的场景值
|
||||
shareTicket = request.data.get("shareTicket", None) # 微信用户的shareTicket值
|
||||
res = wei小程序服务端工具.获取OPENID(js_code=code, appid=paymentCategory.appid,
|
||||
secret=paymentCategory.appsecret, )
|
||||
# 代码能往下执行:则说明,已经正确拿到结果;
|
||||
self_openid = jmespath.search(data=res, expression="openid")
|
||||
session_key = jmespath.search(data=res, expression="session_key")
|
||||
self_unionid = jmespath.search(data=res, expression="unionid")
|
||||
# 准备好,需要的数据
|
||||
|
||||
share分享者对象, share分享者对象是新创建 = weiuser.objects.update_or_create(unionid=superior_unionid, )
|
||||
# 首次进来的用户要全部的添加上默认的 用户 角色
|
||||
click点击者对象, self_bool = weiuser.objects.update_or_create(unionid=self_unionid,
|
||||
defaults={"mini_openid": self_openid})
|
||||
|
||||
six六果对象, sixBool = weiuser.objects.get_or_create(unionid="六果")
|
||||
if superior_unionid == 上级分享者的默认值:
|
||||
share分享者对象 = six六果对象
|
||||
print("登陆成功了,同时打印一下上级的用户是谁", superior_unionid)
|
||||
if click点击者对象.parent is not None:
|
||||
# 不为空说明已经有上级存在了
|
||||
res_obj_data = self.res_obj_data_func(self_user=click点击者对象) # 函数调用返回数据
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=res_obj_data), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
if superior_unionid == self_unionid and share分享者对象是新创建 == True:
|
||||
# 说明是自己点了自己
|
||||
print("说明是自己点了自己说明是自己点了自己说明是自己点了自己")
|
||||
click点击者对象.parent = six六果对象
|
||||
click点击者对象.codeConfigId = six六果对象.codeConfigId
|
||||
click点击者对象.codeQrCode = six六果对象.codeQrCode
|
||||
click点击者对象.codeRemark = six六果对象.codeRemark
|
||||
click点击者对象.user_用户当前的等级 = six六果对象.user_用户当前的等级 + 1
|
||||
click点击者对象.user_绑定企微UNIONID = six六果对象.user_绑定企微UNIONID
|
||||
click点击者对象.save()
|
||||
res_obj_data = self.res_obj_data_func(self_user=click点击者对象) # 函数调用返回数据
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=res_obj_data), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
if click点击者对象.parent is None and scene == 1044:
|
||||
openGId, timestamp, appid = wechatPay(payment=paymentCategory).解密群号(iv=iv, encryptedData=encryptedData,
|
||||
sessionKey=session_key, )
|
||||
# TODO 在这里需要完成,对群号数据的添加
|
||||
click点击者对象.parent = share分享者对象
|
||||
click点击者对象.codeConfigId = share分享者对象.codeConfigId
|
||||
click点击者对象.codeQrCode = share分享者对象.codeQrCode
|
||||
click点击者对象.codeRemark = share分享者对象.codeRemark
|
||||
click点击者对象.user_用户当前的等级 = share分享者对象.user_用户当前的等级 + 1
|
||||
click点击者对象.user_绑定企微UNIONID = share分享者对象.user_绑定企微UNIONID
|
||||
click点击者对象.save()
|
||||
res_obj_data = self.res_obj_data_func(self_user=click点击者对象) # 函数调用返回数据
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=res_obj_data), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
if click点击者对象.parent is None:
|
||||
# 说明没有上级存在,更新数据
|
||||
print("说明没有上级存在,更新数据")
|
||||
# use, use_bool = weiuser.objects.update_or_create(
|
||||
# unionid=self_unionid,
|
||||
# defaults={ "mini_openid": self_openid, "user_用户当前的等级": share分享者对象.user_用户当前的等级 + 1, "parent": share分享者对象,
|
||||
# "codeConfigId": share分享者对象.codeConfigId, "codeQrCode": share分享者对象.codeQrCode,
|
||||
# "codeRemark": share分享者对象.codeRemark,
|
||||
# }, )
|
||||
click点击者对象.parent = share分享者对象
|
||||
click点击者对象.codeConfigId = share分享者对象.codeConfigId
|
||||
click点击者对象.codeQrCode = share分享者对象.codeQrCode
|
||||
click点击者对象.codeRemark = share分享者对象.codeRemark
|
||||
click点击者对象.user_用户当前的等级 = share分享者对象.user_用户当前的等级 + 1
|
||||
click点击者对象.user_绑定企微UNIONID = share分享者对象.user_绑定企微UNIONID
|
||||
click点击者对象.save()
|
||||
print("自己点了自已,同时还没有创建数据时的情况", share分享者对象.user_角色权限)
|
||||
res_obj_data = self.res_obj_data_func(self_user=click点击者对象) # 函数调用返回数据
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData=res_obj_data), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
# 在所有的业务判断都不成功时,直接返回
|
||||
return Response(data="", status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
六果科技小程序用户登陆Router = SimpleRouter()
|
||||
六果科技小程序用户登陆Router.register(prefix="", viewset=六果科技小程序用户登陆, basename="六果科技小程序用户登陆")
|
||||
@@ -0,0 +1,106 @@
|
||||
import datetime
|
||||
import secrets
|
||||
|
||||
import orjson
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from requests import get, post
|
||||
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 DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_token.token工具包 import sixToken
|
||||
from wechat_数据库.小程序后端数据库.订阅消息 import miniSub订阅消息模板
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class miniMsg订阅消息(ViewSet):
|
||||
"""miniMsg订阅消息工具"""
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="查询服务卡片状态")
|
||||
def 查询服务卡片状态(self, request: WSGIRequest | Request):
|
||||
"""
|
||||
查询服务卡片状态
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
uri = f"https://api.weixin.qq.com/wxa/get_user_notify"
|
||||
notify_code = secrets.token_hex(10)
|
||||
post_data = {"openid": "o6oV610oYhpoJYaCJ9tDJKehsJTc", # string 是 用户身份标识符
|
||||
"notify_type": "vknIxXIC1O0IMhHI0yiS-zPUt3UvPYO-ihDM_mcHRJw", #
|
||||
"notify_code": notify_code,
|
||||
}
|
||||
mini_token = sixToken.get_mini_token()
|
||||
result_data = post(url=uri, params={"access_token": mini_token}, json=post_data)
|
||||
print(result_data.json())
|
||||
return Response()
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="gettemplate")
|
||||
def 获取消息列表(self, request: WSGIRequest | Request):
|
||||
""""""
|
||||
"""
|
||||
获取个人模板列表
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
print("----------------------------------------")
|
||||
uri = f"https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||
mini_token = sixToken.get_mini_token()
|
||||
print(mini_token)
|
||||
post_data = {}
|
||||
result_data = get(url=uri, params={"access_token": mini_token}, )
|
||||
print(orjson.loads(result_data.content.decode(encoding="utf-8")))
|
||||
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="sendmsg")
|
||||
def 发送模板消息(self, request: WSGIRequest | Request):
|
||||
"""
|
||||
如果不知道模板格式,就需要调用上面的接口
|
||||
{'priTmplId': 'xCfF4yeTlKaEfZ4sh3z9C6r-wG845W4Bst2JO9hWR6A',
|
||||
'title': '卡券到期提醒',
|
||||
'content':
|
||||
'卡券名称:{{thing1.DATA}}\n
|
||||
到期时间:{{time2.DATA}}\n
|
||||
使用规则:{{thing3.DATA}}\n
|
||||
状态:{{phrase4.DATA}}\n', '
|
||||
example': '卡券名称:软件维护服务1次\n到期时间:2020年10月14日 23:59\n使用规则:将有专业服务人员上门服务并核销卡券\n状态:未使用\n', 'type': 2, 'keywordEnumValueList': []},
|
||||
content内的内容就是模板的信息 格式为 thing1:{value:"内容,"},time2:{"value":"时间字符串"}
|
||||
"""
|
||||
pass
|
||||
uri = f"https://api.weixin.qq.com/cgi-bin/message/subscribe/send"
|
||||
datetimd_str = datetime.datetime.now().strftime(format="%Y-%m-%d %H:%M:%S")
|
||||
random_str = generator.generate_str()
|
||||
post_data = {"touser": "ohQkD7A-N93kljcFmkCyG6e_D9vg",
|
||||
"template_id": "RvGf7wyALX4djhBgeIp6jqlfAKNzd_weXRFEd1P54fk",
|
||||
"page": "tabPage/Home/Home",
|
||||
"data": {
|
||||
"thing1": {"value": "100优惠券"},
|
||||
"thing2": {"value": "random_str"},
|
||||
},
|
||||
}
|
||||
mini_token = sixToken.get_mini_token()
|
||||
result_data = post(url=uri, params={"access_token": mini_token}, json=post_data)
|
||||
print(result_data.json(), "订阅消息发送成功了啦")
|
||||
return Response(data={"msg": "订阅消息"})
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="add_messages")
|
||||
def 计数订阅成功的次数(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
|
||||
sub对象, sub对象是否存在 = miniSub订阅消息模板.objects.update_or_create(sub订阅用户ID=self_mini_openid,
|
||||
sub订阅模板ID="RvGf7wyALX4djhBgeIp6jqlfAKNzd_weXRFEd1P54fk",
|
||||
)
|
||||
sub对象.sub订阅次数 = sub对象.sub订阅次数 + 1
|
||||
sub对象.save()
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
miniMsg订阅消息Router = DefaultRouter()
|
||||
miniMsg订阅消息Router.register(prefix="", viewset=miniMsg订阅消息, basename="")
|
||||
@@ -0,0 +1,67 @@
|
||||
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.routers import DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
from wechat_项目工具包.微信支付工具包.微信支付类 import paymentCategory, wechatPay
|
||||
|
||||
|
||||
class 代金券接口ViewSets(ViewSet):
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="send_coupons")
|
||||
def 发放指定代金券接口(self, request: Request):
|
||||
""""""
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
发放接口 = f"https://api.mch.weixin.qq.com/v3/marketing/favor/users/{self_mini_openid}/coupons"
|
||||
out_request_no = generator.generate_str()
|
||||
发放的数据 = {
|
||||
"stock_id": "22512292", # 发放的批次号
|
||||
"out_request_no": out_request_no, # 【商户单据号】商户此次发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性
|
||||
"appid": "wxf612e825377328f0",
|
||||
"stock_creator_mchid": "1700383419", # 创建批次的商户号】批次创建方商户号。
|
||||
# "coupon_value": 100, # 指定面额发券,面额】指定面额发券场景,券面额,其他场景不需要填,单位:分。
|
||||
}
|
||||
返回签名后的 = wechatPay(payment=paymentCategory).构造签名串(uri=发放接口, body_data=发放的数据, method="POST")
|
||||
data = requests.post(url=发放接口, json=发放的数据, headers=返回签名后的)
|
||||
print(data.json())
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"couponsMessages": "发券成功"}), ).model_dump()
|
||||
return Response(data=data.json(), status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="setting_url")
|
||||
def 设置代金券消息通知地址(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
请求接口 = f"https://api.mch.weixin.qq.com//v3/marketing/favor/callbacks"
|
||||
请求数据 = {
|
||||
"mchid": paymentCategory.mchid,
|
||||
"notify_url": "https://xiao.sixgou.com/coupons/coupons_callback/",
|
||||
}
|
||||
headers = wechatPay(payment=paymentCategory).构造签名串(uri=请求接口, body_data=请求数据)
|
||||
data = requests.post(url=请求接口, json=请求数据, headers=headers)
|
||||
print("请求后的结果", data.json()) # 请求后的结果 {'notify_url': 'https://xiao.sixgou.com/coupons/coupons_callback/', 'update_time': '2026-03-25T23:51:54+08:00'}
|
||||
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"couponsMessages": "发券成功"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="coupons_callback")
|
||||
def 代金券的回调接口(self, request: Request):
|
||||
""""""
|
||||
self_user_unionid = request.data.get("self_user_unionid", None)
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
# 回调解密内容 = wechatPay(payment=paymentCategory).callBack回调解密(headers=request.headers, response_body=request.body)
|
||||
# print("回调解密内容", 回调解密内容)
|
||||
wechat_data支付回调数据 = wechatPay(payment=paymentCategory).callBack回调解密(headers=request.headers, response_body=request.data, )
|
||||
print(wechat_data支付回调数据, "wechat_data支付回调数据🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 ")
|
||||
print("🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏")
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
代金券接口ViewSetsRouter = DefaultRouter()
|
||||
代金券接口ViewSetsRouter.register(prefix="", viewset=代金券接口ViewSets, basename="")
|
||||
@@ -0,0 +1,101 @@
|
||||
import pydash
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.db import models
|
||||
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 DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
from wechat_项目工具包.微信支付工具包.微信支付类 import paymentCategory, wechatPay
|
||||
|
||||
|
||||
class six商家转账ViewSets(ViewSet):
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="transfer")
|
||||
def six发起转账(self, request: Request):
|
||||
""" """
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
提取积分值 = request.data.get("提取积分值", None)
|
||||
# 逻辑一: 先比较积分值是否超出提现的金额
|
||||
# 积分值sum = share分享者积分.objects.filter(share分享者unionid=self_mini_unionid).values("share分享者unionid").annotate(xiao_age_sum=models.Sum("share分享积分值"), ) # 只有value(字段1,字段2)二个值完全相同的才会分配为一组
|
||||
# 添加 order_by
|
||||
# result = 积分值sum.order_by("share分享者unionid").first()
|
||||
# print(result)
|
||||
# xiao_age_sum = pydash.get(obj=result, path="xiao_age_sum")
|
||||
# print(xiao_age_sum)
|
||||
# httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": xiao_age_sum}), ).model_dump()
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": {}}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
if xiao_age_sum > 0 and xiao_age_sum >= 提取积分值:
|
||||
pass
|
||||
# 说明这里可以提现
|
||||
# 业务逻辑 第一步.需要判断这个用户是否已经领过 新手红包 如何判断, 查询新手红包数据库,如果对象存在,则直接不能再领取了;
|
||||
out_bill_no = generator.generate_str()
|
||||
transfer_amount = 10 # 必须参数转账的金额
|
||||
transferAccountsBody = {
|
||||
"appid": paymentCategory.appid,
|
||||
"out_bill_no": out_bill_no, # 必填 integer【商户单号】
|
||||
# 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
|
||||
"transfer_scene_id": "1000",
|
||||
# 必填 integer【转账场景ID】 该笔转账使用的转账场景,可前往“商户平台-产品中心-商家转账”中申请。如:1000(现金营销),1006(企业报销)等
|
||||
# "openid":"ohQkD7A-N93kljcFmkCyG6e_D9vg",
|
||||
"openid": self_mini_openid, # 必填 integer【收款用户OpenID】 用户在商户appid下的唯一标识。发起转账前需获取到用户的OpenID,获取方式详见参数说明。
|
||||
# "user_name":"757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45", # 【收款用户姓名】
|
||||
# 收款方真实姓名。需要加密传入,支持标准RSA算法和国密算法,公钥由微信侧提供。
|
||||
"transfer_amount": transfer_amount, # 必填 integer【转账金额】 转账金额单位为“分”。
|
||||
"transfer_remark": "新会员开通有礼", # 必填 string(32)【转账备注】 转账备注,用户收款时可见该备注信息,UTF8编码,最多允许32个字符
|
||||
"notify_url": "https://xiao.sixgou.com/demopay/transfer_back/",
|
||||
# 选填【通知地址】 异步接收微信支付结果通知的回调地址,通知url必须为公网可访问的URL,必须为HTTPS,不能携带参数。
|
||||
"user_recv_perception": "现金奖励", # 选填 【用户收款感知】 用户收款时感知到的收款原因将根据转账场景自动展示默认内容。如有其他展示需求,
|
||||
# 必填 array[TransferSceneReportInfo] 【转账场景报备信息】 各转账场景下需报备的内容,商户需要按照所属转账场景规则传参,详见转账场景报备信息字段说明。
|
||||
"transfer_scene_report_infos": [
|
||||
{
|
||||
"info_type": "活动名称", # 必填 string(15)【信息类型】 不能超过15个字符,商户所属转账场景下的信息类型,此字段内容为固定值
|
||||
"info_content": "新会员有礼", # 必填 【信息内容】 不能超过32个字符,商户所属转账场景下的信息内容,商户可按实际业务场景自定义传参
|
||||
},
|
||||
{
|
||||
"info_type": "奖励说明", "info_content": "注册会员抽奖一等奖",
|
||||
},
|
||||
],
|
||||
}
|
||||
# wechat_data = wechatPay(payment=paymentCategory).transferAccounts商家转账到零钱(transferAccountsBody=transferAccountsBody)
|
||||
# print("返回的数据", wechat_data)
|
||||
# package_info = jmespath.search(data=wechat_data, expression="package_info")
|
||||
# create_time = jmespath.search(data=wechat_data, expression="create_time")
|
||||
# out_bill_no = jmespath.search(data=wechat_data, expression="out_bill_no")
|
||||
# state = jmespath.search(data=wechat_data, expression="state")
|
||||
# transfer_bill_no = jmespath.search(data=wechat_data, expression="transfer_bill_no")
|
||||
# WechatTransferOrder.objects.create(
|
||||
# out_bill_no=out_bill_no, transfer_bill_no=transfer_bill_no, wx_create_time=create_time,
|
||||
# state=state, transfer_amount=transfer_amount, package_info=package_info
|
||||
# )
|
||||
# 前端调用的数据 = {
|
||||
# "mchId": paymentCategory.mchid, "appId": paymentCategory.appid, "package": package_info,
|
||||
# }
|
||||
# # 操作数据库,减掉提取的积分值
|
||||
# share分享者积分.objects.create(share分享者unionid=self_mini_unionid, share分享类型="提取积分", share分享积分=-1)
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
else:
|
||||
pass
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
# 说明这里不能提现
|
||||
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="transfer_back")
|
||||
def six发起转账回调(self, request: WSGIRequest | Request):
|
||||
pass
|
||||
wechat_data = wechatPay(payment=paymentCategory).callBack回调解密(response_body=request.body, headers=request.headers)
|
||||
print(wechat_data)
|
||||
return Response()
|
||||
|
||||
|
||||
six商家转账ViewSetsRouter = DefaultRouter()
|
||||
six商家转账ViewSetsRouter.register(prefix="", viewset=six商家转账ViewSets, basename="")
|
||||
@@ -0,0 +1,189 @@
|
||||
import secrets
|
||||
|
||||
import jmespath
|
||||
import orjson
|
||||
import pydash
|
||||
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 DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import ResData, BaseResponse
|
||||
from wechat_数据库.支付订单数据库.商品订单数据 import order订单
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
from wechat_项目工具包.微信支付工具包.微信支付类 import paymentCategory, wechatPay
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class 微信支付ViewSets( ViewSet ):
|
||||
|
||||
|
||||
@action( detail=False, methods=[ "post" ], url_path="jsapi" )
|
||||
def 小程序支付jsapi( self, request: Request ) -> Response:
|
||||
""""""
|
||||
url_pay = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi" # 发起请求的链接
|
||||
self_mini_openid = request.data.get( "self_mini_openid", False ) #
|
||||
order商品数据 = request.data.get( "order商品数据", None )
|
||||
order用户配送地址 = request.data.get( "order用户配送地址", None )
|
||||
order商品数量 = request.data.get( "order商品数量", None )
|
||||
order商品总价 = request.data.get( "order商品总价", None )
|
||||
order商品ID = request.data.get( "order商品ID", None )
|
||||
share订单分享者ID = request.data.get( "share订单分享者ID", None ) # 当前是否有上级对象
|
||||
order订单类型 = request.data.get( "order订单类型", None )
|
||||
superior_unionid = request.data.get( "superior_unionid", None ) # 当前是否有上级对象
|
||||
out_trade_no = f"{generator.generate_id( )}"
|
||||
print( self_mini_openid, "我的id拿不到了吗", order商品数据 )
|
||||
body = {
|
||||
"mchid": paymentCategory.mchid, # 【直连商户号】 直连商户号
|
||||
"out_trade_no": out_trade_no, # 【商户订单号】 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一。
|
||||
"appid": paymentCategory.appid, # 【公众号 或者 小程序ID】
|
||||
"description": "测试支付接口", # 【商品描述】 商品描述要
|
||||
"notify_url": "https://xiao.sixgou.com/demopay/jsapi_callback/", # 回调地址要
|
||||
"amount": {
|
||||
"total": 1, # 【总金额】 订单总金额,单位为分。
|
||||
"currency": "CNY", # 【货币类型】 CNY:人民币,境内商户号仅支持人民币。
|
||||
}, # 【支付者】 支付者信息。
|
||||
"attach": orjson.dumps( { "share订单分享者ID": share订单分享者ID }, option=orjson.OPT_SORT_KEYS, ).decode( encoding="utf-8" ),
|
||||
"payer": {
|
||||
# "openid": "ohQkD7A-N93kljcFmkCyG6e_D9vg", # 【用户标识】 用户在普通商户AppID下的唯一标识。 下单前需获取到用户的OpenID,详见OpenID获取
|
||||
"openid": self_mini_openid, # 【用户标识】 用户在普通商户AppID下的唯一标识。 下单前需获取到用户的OpenID,详见OpenID获取
|
||||
},
|
||||
} # 请求的数据
|
||||
wechat_data = wechatPay( payment=paymentCategory ).getpay_jsapi( uri=url_pay, body_data=body, method="POST" )
|
||||
print( wechat_data )
|
||||
payData = jmespath.search( data=wechat_data, expression="response" )
|
||||
order订单.objects.create( order支付商家侧订单号=out_trade_no,
|
||||
order商品总价=order商品总价, order商品数据=order商品数据, order商品数量=order商品数量,
|
||||
order商品ID=order商品ID, order支付数据=body, order支付状态="支付中", order订单类型=order订单类型,
|
||||
order支付都ID=self_mini_openid, order用户配送地址=order用户配送地址,
|
||||
)
|
||||
httpResData = BaseResponse( resData=ResData( listData=[ "" ], dictData=payData ), ).model_dump( )
|
||||
return Response( data=httpResData, status=status.HTTP_200_OK )
|
||||
|
||||
|
||||
|
||||
@action( detail=False, methods=[ "post" ], url_path="navite" )
|
||||
def 二维码支付( self, request: WSGIRequest | Request ) -> Response:
|
||||
"""
|
||||
生成收款的二维码链接,可以让用户来扫码支付
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
out_trade_no = f"{generator.generate_id( )}"
|
||||
native_body = {
|
||||
"mchid": paymentCategory.mchid, # 服务商户号
|
||||
"out_trade_no": out_trade_no, # 商户系统内部订单号
|
||||
"appid": paymentCategory.appid, # 服务商应用ID
|
||||
"description": "测试", # 商品的描述信息
|
||||
"notify_url": "https://server.xiao.band/demopay/callback_navite/", # 回调地址
|
||||
"amount": { "total": 1, "currency": "CNY" },
|
||||
}
|
||||
res_data = wechatPay( payment=paymentCategory ).getpay_navite( navite_body=native_body )
|
||||
print( res_data )
|
||||
code_url = jmespath.search( data=res_data, expression="code_url" )
|
||||
print( code_url )
|
||||
import segno
|
||||
|
||||
|
||||
qr = segno.make_qr( content="------", )
|
||||
data = qr.png_data_uri( scale=5 )
|
||||
qr.save( out="myqr.png" )
|
||||
httpResData = BaseResponse( resData=ResData( listData=[ "" ], dictData={ "demo": data } ), ).model_dump( )
|
||||
return Response( data=httpResData, status=status.HTTP_200_OK, )
|
||||
|
||||
|
||||
|
||||
@action( detail=False, methods=[ "post" ], url_path="qrCode" )
|
||||
def 付款码支付( self, request: Request ):
|
||||
"""
|
||||
扫用户付款码的测试接口
|
||||
:param request:
|
||||
"""
|
||||
nonce_str = secrets.token_hex( 10 ) # 随机字符串
|
||||
order_random = f"{generator.generate_id( )}"
|
||||
auth_code = request.data.get( "auth_code", False ) # 前端扫码读取的付款码的数据信息
|
||||
# auth_code = "123497182327333282" # TODO 扫码支付付款码,设备读取用户微信中的条码或者二维码信息(这个值需要小程序端,扫码,将数据传递进来)
|
||||
# fu_kuan_data 是微信官方要求组装的数据类型
|
||||
fu_kuan_data = {
|
||||
"appid": paymentCategory.appid, # 小程序的appid
|
||||
"mch_id": paymentCategory.mchid, # 微信支付分配的商户号
|
||||
"nonce_str": nonce_str, # 随机字符串
|
||||
"out_trade_no": order_random, # 商户订单号
|
||||
"body": "test",
|
||||
"auth_code": auth_code,
|
||||
"total_fee": 1, # 订单总金额,单位为分,只能为整数,详见支付金额(必填)
|
||||
}
|
||||
wechat_data = wechatPay( payment=paymentCategory ).getpay_code扫用户付款码( body_data=fu_kuan_data )
|
||||
print( wechat_data )
|
||||
# return_code 通信返回码:'SUCCESS' 表示与微信服务器通信成功,'FAIL' 表示通信失败(如网络或参数错误)
|
||||
return_code = jmespath.search( data=wechat_data, expression="xml.return_code" )
|
||||
# return_msg 通信返回信息:当 return_code 为 'FAIL' 时,此字段包含错误描述;成功时通常为 'OK'
|
||||
return_msg = jmespath.search( data=wechat_data, expression="xml.return_msg" )
|
||||
# result_code 业务结果码:'SUCCESS' 表示支付成功,'FAIL' 表示支付失败(需结合 err_code 分析,但此处未提取)
|
||||
result_code = jmespath.search( data=wechat_data, expression="xml.result_code" )
|
||||
# mch_id 商户号(MCH ID):微信支付分配给商户的唯一标识
|
||||
mch_id = jmespath.search( data=wechat_data, expression="xml.mch_id" )
|
||||
# appid 公众号或小程序的 AppID:发起支付的应用身份标识
|
||||
appid = jmespath.search( data=wechat_data, expression="xml.appid" )
|
||||
# nonce_str 随机字符串:用于防止重放攻击,由商户生成并随请求发送,微信原样返回
|
||||
nonce_str = jmespath.search( data=wechat_data, expression="xml.nonce_str" )
|
||||
# openid 用户在当前 AppID 下的唯一标识(OpenID):可用于关联用户账户
|
||||
openid = jmespath.search( data=wechat_data, expression="xml.openid" )
|
||||
# total_fee 订单总金额(单位:分):例如 '1' 表示 0.01 元
|
||||
total_fee = jmespath.search( data=wechat_data, expression="xml.total_fee" )
|
||||
# cash_fee_type 现金支付币种:目前微信支付仅支持 'CNY'(人民币)
|
||||
cash_fee_type = jmespath.search( data=wechat_data, expression="xml.cash_fee_type" )
|
||||
# transaction_id 微信支付系统生成的唯一交易单号:用于对账、退款、查询等操作
|
||||
transaction_id = jmespath.search( data=wechat_data, expression="xml.transaction_id" )
|
||||
# 商户系统内部订单号:由商户在调用支付接口时传入,用于关联自身业务订单
|
||||
out_trade_no = jmespath.search( data=wechat_data, expression="xml.out_trade_no" )
|
||||
# 附加数据:商户在支付请求中可自定义传入,微信原样返回(常用于传递门店ID、商品类型等)
|
||||
attach = jmespath.search( data=wechat_data, expression="xml.attach" )
|
||||
# time_end 支付完成时间:格式为 yyyyMMddHHmmss,例如 '20260304233708' 表示 2026年03月04日 23:37:08
|
||||
time_end = jmespath.search( data=wechat_data, expression="xml.time_end" )
|
||||
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="jsapi_callback" )
|
||||
def jsapi支付回调测试接口( self, request: Request ) -> Response:
|
||||
""" 微信支付成功后的回调接口 """
|
||||
dict_body = request.data
|
||||
wechat_data支付回调数据 = wechatPay( payment=paymentCategory ).callBack回调解密( headers=request.headers, response_body=dict_body, )
|
||||
print( "\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n", wechat_data支付回调数据, "\n🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 \n" )
|
||||
out_trade_no = jmespath.search( data=wechat_data支付回调数据, expression="out_trade_no" )
|
||||
trade_state_desc = pydash.get( obj=wechat_data支付回调数据, path="trade_state_desc" )
|
||||
self_mini_openid = pydash.get( obj=wechat_data支付回调数据, path="payer.openid" )
|
||||
# 调用异步方法 : 作用 (发起订单录入接口调用)
|
||||
# 更新 拼团订单的 支付状态
|
||||
生成物流的订单号 = generator.generate_str( )
|
||||
order订单.objects.filter( order支付商家侧订单号=out_trade_no ).update( order支付数据=wechat_data支付回调数据, order支付状态=trade_state_desc,
|
||||
order物流状态=order订单.order订单choosies物流状态.待发货.value, order物流订单号=生成物流的订单号
|
||||
)
|
||||
# 在这里还需要处理是否给上级添加积分
|
||||
share订单分享者ID = pydash.get( obj=orjson.loads( pydash.get( obj=wechat_data支付回调数据, path="attach" ) ), path="share订单分享者ID" )
|
||||
|
||||
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="callback_navite" )
|
||||
def 二维码支付回调( self, request: WSGIRequest | Request ):
|
||||
"""注释"""
|
||||
二维码支付回调数据 = wechatPay( payment=paymentCategory ).callBack回调解密( headers=request.headers, response_body=request.body, )
|
||||
print( "二维码支付回调数据=>::", 二维码支付回调数据 )
|
||||
return Response( data={ "msg": "success" } )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
微信支付ViewSetsRouter = DefaultRouter( )
|
||||
微信支付ViewSetsRouter.register( prefix="", viewset=微信支付ViewSets, basename="" )
|
||||
@@ -0,0 +1,63 @@
|
||||
# from django.core.files.storage import default_storage
|
||||
# from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||
# from django.core.handlers.wsgi import WSGIRequest
|
||||
# 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.routers import SimpleRouter, DefaultRouter
|
||||
# from rest_framework.viewsets import ViewSet
|
||||
#
|
||||
# from sixGuoDjango import ResData, BaseResponse
|
||||
# from wechat_数据库.用户数据库.小程序登陆用户 import weiuser用户角色表choicesStatus
|
||||
#
|
||||
#
|
||||
# class 用户角色管理接口ViewSets(ViewSet):
|
||||
# @action(detail=False, methods=["get", "post", "put", "delete"], url_path="add_role")
|
||||
# def 添加用户角色接口(self, request: Request):
|
||||
# """ angular_permissions。"""
|
||||
# try:
|
||||
# pass
|
||||
# self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
# self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
# weiuser用户角色表.objects.get_or_create(user用户的unionid=self_mini_unionid, user用户角色名称=weiuser用户角色表choicesStatus.推广员.value, )
|
||||
# httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "添加成功了"}), ).model_dump()
|
||||
# return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
# except Exception as e:
|
||||
# pass
|
||||
# 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="delete_role")
|
||||
# def 删除用户角色接口(self, request: Request):
|
||||
# """"""
|
||||
# self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
# self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
# print("🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏🍎 🍏", self_mini_unionid)
|
||||
# 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="query_role")
|
||||
# def 查询用户角色(self, request: Request):
|
||||
# """"""
|
||||
# self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
# self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
#
|
||||
# print("🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 🍊 🍎 🍏 查询进来了")
|
||||
# 用户角色状态 = weiuser用户角色表.objects.filter(user用户的unionid=self_mini_unionid, user用户角色名称=weiuser用户角色表choicesStatus.推广员.value).first()
|
||||
# print(用户角色状态)
|
||||
# if 用户角色状态 is None:
|
||||
# # 这里表示用户角色不存在
|
||||
# httpResData = BaseResponse(resData=ResData(listData=[""], dictData={'idKey': '', 'user用户角色名称': '不是推广员', 'wai键用户表': ''}), ).model_dump()
|
||||
# return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
# if 用户角色状态 is not None:
|
||||
# data = model_to_dict(instance=用户角色状态, fields=None)
|
||||
# httpResData = BaseResponse(resData=ResData(listData=[""], dictData=data), ).model_dump()
|
||||
# return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
# httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
# return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
#
|
||||
#
|
||||
# 用户角色管理接口ViewSetsDemoRouter = DefaultRouter()
|
||||
# 用户角色管理接口ViewSetsDemoRouter.register(prefix="", viewset=用户角色管理接口ViewSets, basename="")
|
||||
@@ -0,0 +1,47 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from sixGuoDjango import BaseResponse, ResData
|
||||
|
||||
|
||||
# 创建一个自定义分页器
|
||||
class CustomPagination(PageNumberPagination):
|
||||
page_size = 10 # 默认每页显示10条
|
||||
page_size_query_param = 'page_size' # 允许客户端通过参数指定每页数量
|
||||
max_page_size = 100 # 最大每页数量限制
|
||||
page_query_param = 'page' # 页码参数名
|
||||
|
||||
|
||||
class 分页接口ViewSets(ViewSet):
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="xio")
|
||||
def 分页器接口(self, request: Request):
|
||||
""""""
|
||||
# page_all = xiaozizi.objects.all( )
|
||||
|
||||
# 创建分页器实例
|
||||
paginator = CustomPagination()
|
||||
|
||||
# 对查询集进行分页
|
||||
# paginated_data = paginator.paginate_queryset( queryset=page_all, request=request )
|
||||
|
||||
# 序列化数据
|
||||
# page_list_data = [ ]
|
||||
# print( paginated_data )
|
||||
# for item in paginated_data:
|
||||
# print( type( item ) )
|
||||
# print( model_to_dict( instance=item, fields=None ) )
|
||||
# page_list_data.append( model_to_dict( instance=item, fields=None ) )
|
||||
# listData = orjson.dumps(paginated_data, option=orjson.OPT_SORT_KEYS, ).decode(encoding="utf-8")
|
||||
httpResData = BaseResponse(
|
||||
resData=ResData(listData=[], dictData={"demo": "xiaozizi"}), ).model_dump()
|
||||
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
分页接口ViewSetsRouter = DefaultRouter()
|
||||
分页接口ViewSetsRouter.register(prefix="", viewset=分页接口ViewSets, basename="")
|
||||
@@ -0,0 +1,16 @@
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
|
||||
|
||||
|
||||
class htmlViewSets( ViewSet ):
|
||||
|
||||
|
||||
def home( self, request: WSGIRequest | Request ):
|
||||
""""""
|
||||
return render( request=request, template_name="xiao.html" )
|
||||
# return HttpResponseRedirect( redirect_to="https://www.qq.com/" )
|
||||
Reference in New Issue
Block a user