This commit is contained in:
doudou201703
2026-08-21 23:48:29 +08:00
parent 0e2fe60253
commit dd4383130d
20 changed files with 179 additions and 241 deletions
+3 -15
View File
@@ -1,10 +1,12 @@
"""
Author: xiao 792282@qq.com
Date: 2025-08-10 11:36:05
LastEditors: xiao 792282@qq.com
LastEditTime: 2025-08-17 13:38:39
FilePath: django_公共认证接口/微信TOKEN.py
Description: 这是默认设置,可以在设置》工具》File Description中进行配置
"""
import os
@@ -93,7 +95,6 @@ class sixToken:
:return:
:rtype:
"""
print("是不是每次都在调用的吗")
查询对象, 是否存在 = weitoken.objects.get_or_create(token_name="mini_token")
if 查询对象.token_value is None:
创建的新对象 = cls.mini_token()
@@ -115,10 +116,7 @@ class sixToken:
params = {"appid": cls.wechat_appid, "secret": cls.wechat_appsecret, "grant_type": "client_credential", "force_refresh": False, }
token_data = requests.post(url="https://api.weixin.qq.com/cgi-bin/stable_token", json=params)
token: dict = token_data.json()
print(token)
wechat_token服务号 = token.get("access_token")
print("服务 号的token", wechat_token服务号)
# return wechat_token
jsapo_url = f"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={wechat_token服务号}&type=jsapi"
json_data = requests.get(url=jsapo_url).json()
ticket服务号 = pydash.get(obj=json_data, path="ticket", default=None)
@@ -216,17 +214,7 @@ class sixToken:
"grant_type": "authorization_code", # "code": code
"code": code, # 填写第一步获取的code参数
}
# 返回值 = """
# {
# "access_token":"ACCESS_TOKEN",
# "expires_in":7200,
# "refresh_token":"REFRESH_TOKEN",
# "openid":"OPENID",
# "scope":"SCOPE",
# "is_snapshotuser": 1,
# "unionid": "UNIONID"
# }
# """
oauth_token_url = f"https://api.weixin.qq.com/sns/oauth2/access_token"
oauth_token_data = requests.get(url=oauth_token_url, params=params)
# oauth_token: dict = oauth_token_data.json()