This commit is contained in:
doudou201703
2026-08-02 14:07:04 +08:00
commit 046fac6dc1
339 changed files with 19435 additions and 0 deletions
@@ -0,0 +1,27 @@
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 ResData, BaseResponse
from wechat_token.token工具包 import sixToken
class ShortLinkViewSets(ViewSet):
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="genwxashortlink")
def 获取ShortLink(self, request: Request):
"""获取小程序 Short Link,适用于微信内拉起小程序的业务场景。目前对所有非个人主体小程序开放。通过该接口,可以选择生成到期失效和永久有效的小程序短链"""
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()
requests.post(url="https://api.weixin.qq.com/wxa/genwxashortlink", params={"access_token": mini_token, },
json={
"page_url": f"pageTabBar/Home/Home?superior_unionid={self_mini_unionid}",
"page_title": "Homework title", # 短链标题,可自定义,不能包含违法信息,超过 20 字符会用... 截断代替
"is_permanent": False,
}
)
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
return Response(data=httpResData, status=status.HTTP_200_OK)
@@ -0,0 +1,35 @@
import requests
from django.core.files.storage import default_storage
from django.core.files.uploadedfile import InMemoryUploadedFile
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 SimpleRouter, DefaultRouter
from rest_framework.viewsets import ViewSet
from sixGuoDjango import ResData, BaseResponse
from wechat_token.token工具包 import sixToken
class URLLinkViewSets(ViewSet):
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="generate_urllink")
def 获取加密URLLink(self, request: Request):
""""""
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()
linkData = requests.post(url="https://api.weixin.qq.com/wxa/generate_urllink",
params={"access_token": mini_token, },
json={
"path": "/pageTabBar/Home/Home",
"query": f"superior_unionid={self_mini_unionid}",
"expire_type": 1, # 类型
"expire_interval": 30, # 多少天后失效
"env_version": "develop", # 默认值"release"。要打开的小程序版本。正式版为 "release",体验版为"trial",开发版为"develop",仅在微信外打开时生效。
},
)
print(linkData.json())
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
return Response(data=httpResData, status=status.HTTP_200_OK)
@@ -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)
@@ -0,0 +1,54 @@
import io
import requests
from django.core.files.storage import default_storage
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 ResData, BaseResponse
from wechat_token.token工具包 import sixToken
class 小程序码接口ViewSets(ViewSet):
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="getwxacode")
def 获取小程序码(self, request: Request):
""""""
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()
requests.post(url="https://api.weixin.qq.com/wxa/getwxacode", params={"access_token": mini_token, },
json={
"path": "/pageTabBar/Home/Home?superior_unionid=123",
"env_version": "develop", # 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版
},
)
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="getwxacodeunlimit")
def 获取不限制的小程序码(self, request: Request):
""""""
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()
miniCode = requests.post(url="https://api.weixin.qq.com/wxa/getwxacodeunlimit", params={"access_token": mini_token, },
json={
"page": "tabPage/Home/Home",
"scene": f"{self_mini_unionid}", # 这里的值最终会显示 "query": {"scene":"self_mini_unionid"}
"env_version": "develop", # 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
},
)
default_storage.save(name=f"{self_mini_unionid}.png", content=io.BytesIO(miniCode.content))
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="createwxaqrcode")
def 获取小程序二维码(self, request: Request):
""""""
self_user_unionid = request.data.get("self_user_unionid", None)
self_mini_openid = request.data.get("self_mini_openid", None)
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={"demo": "xiaozizi"}), ).model_dump()
return Response(data=httpResData, status=status.HTTP_200_OK)