Files

28 lines
1.5 KiB
Python
Raw Permalink Normal View History

2026-08-02 14:07:04 +08:00
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)