six_001
This commit is contained in:
@@ -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_当前用户对象的字典数据)
|
||||
Reference in New Issue
Block a user