six_003
This commit is contained in:
+17
-18
@@ -16,6 +16,7 @@ from rest_framework.viewsets import ViewSet
|
||||
|
||||
from django_jwt_token.jwt认证接口 import Jwt身份认证
|
||||
from sixGuoDjango import BaseResponse, ResData, redis_5
|
||||
from wechat_token.token工具包 import sixToken
|
||||
|
||||
default_channel_layer = cast(BaseChannelLayer, get_channel_layer(alias="default"))
|
||||
|
||||
@@ -29,21 +30,21 @@ def sync_lock(lock):
|
||||
def wrapper(*args, **kwargs):
|
||||
with lock:
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class DemoXiaoViewSets(ViewSet):
|
||||
lock = threading.Lock() # 所有请求 共享这一个 lock对象
|
||||
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="zizi")
|
||||
def 只用于初始化项目测试接口(self, request: Request):
|
||||
""""""
|
||||
print("测试接口")
|
||||
# 可以对用户添加某一类型的积分
|
||||
|
||||
|
||||
# with ThreadPoolExecutor( max_workers=3 ) as executor:
|
||||
# 返回值 = executor.map( 请求企微, [ 1, 2, 3 ] )
|
||||
# print( 返回值 )
|
||||
@@ -51,31 +52,31 @@ class DemoXiaoViewSets(ViewSet):
|
||||
# print( item )
|
||||
xiao = request.data.get("xiao", None)
|
||||
print(xiao)
|
||||
|
||||
|
||||
商品数据 = request.data.get("商品数据", "")
|
||||
data = orjson.loads(商品数据)
|
||||
列表 = pydash.get(obj=data, path="列表")
|
||||
print(列表, 商品数据)
|
||||
fileDataList: list[InMemoryUploadedFile] = request.FILES.getlist("fileDataList", None) # 接收多个图片或者文件
|
||||
|
||||
|
||||
for file in fileDataList:
|
||||
default_storage.save(name=file.name, content=file)
|
||||
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="xiao")
|
||||
def xiao(self, request: Request):
|
||||
""""""
|
||||
openid = "oy4Jw6A1T3WkKOOhMxcbQTDSM8rs"
|
||||
channels_name = redis_5.get(name="xiaozizi")
|
||||
async_to_sync(awaitable=default_channel_layer.send)(channel=channels_name,
|
||||
message={"type": "chat_msg",
|
||||
"data": {"xiao": "zizi"},
|
||||
})
|
||||
|
||||
message={"type": "chat_msg",
|
||||
"data": {"xiao": "zizi"},
|
||||
})
|
||||
|
||||
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="eventSource")
|
||||
def sse请求处理接口(self, request: Request):
|
||||
""""""
|
||||
@@ -83,27 +84,25 @@ class DemoXiaoViewSets(ViewSet):
|
||||
"sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口sse请求处理接口")
|
||||
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="xiaozizi",
|
||||
authentication_classes=[Jwt身份认证])
|
||||
authentication_classes=[Jwt身份认证])
|
||||
# @sync_lock_线程锁( lock=lock )
|
||||
def xiaozizi(self, request: Request):
|
||||
pass
|
||||
return Response(data={"xiao": "111111111111111111"})
|
||||
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="redirect")
|
||||
# @sync_lock_线程锁( lock=lock )
|
||||
def redirect(self, request: Request):
|
||||
# 接口是用来测试重定向
|
||||
pass
|
||||
return HttpResponseRedirect(redirect_to="https://six.sixgou.com/")
|
||||
|
||||
|
||||
# @sync_lock(lock=lock)
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="中文", )
|
||||
def 中文(self, request: Request):
|
||||
print("卡异步的请求")
|
||||
xiaozizi = request.data.get("xiaozizi", None)
|
||||
print(xiaozizi)
|
||||
return Response(data={"msg": xiaozizi})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user