six_001
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user