Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL0809 committed Jul 1, 2024
1 parent d68931b commit f7e3bd7
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions wx_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,69 +155,3 @@ async def protected_endpoint(current_user: User = Depends(get_current_user)):

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=45628, ssl_keyfile="/etc/nginx/ssl/db.yun.store.key", ssl_certfile="/etc/nginx/ssl/db.yun.store.pem", log_level="debug")

# --------------------
# from fastapi import FastAPI, Request
# from fastapi.middleware.cors import CORSMiddleware
# import requests
# import asyncio
# import logging

# app = FastAPI()
# logger = logging.getLogger("uvicorn.error")

# CORPID = 'ww8447d69cc3208638' # 企业ID
# CORPSECRET = 'epiYFjQgMk9BnJem5rmGNMTQUTlnSK7SRm-uCIbHAPg' # 应用的凭证密钥
# access_token = ''

# app.add_middleware(
# CORSMiddleware,
# allow_origins=["*"], # 可以根据需要限制特定来源
# allow_credentials=True,
# allow_methods=["*"],
# allow_headers=["*"],
# )
# def get_qywx_access_token():
# global access_token
# url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORPID}&corpsecret={CORPSECRET}'
# response = requests.get(url)
# data = response.json()
# if data['errcode'] == 0:
# access_token = data['access_token']
# logger.info(f"Successfully obtained access_token: {access_token}")
# else:
# logger.error(f"Failed to obtain access_token: {data['errmsg']}")

# @app.on_event("startup")
# async def startup_event():
# get_qywx_access_token()
# asyncio.create_task(refresh_access_token())

# async def refresh_access_token():
# while True:
# await asyncio.sleep(7000) # 提前刷新 access_token,避免因过期导致调用失败
# get_qywx_access_token()

# @app.post("/qw/user")
# async def wechat_callback(request: Request):
# data = await request.json()
# code = data.get('code')
# # state = data.get('state')

# get_user_info_url = f'https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token={access_token}&code={code}'
# # user_detail_url = f'https://qyapi.weixin.qq.com/cgi-bin/auth/getuserdetail?access_token={access_token}'
# user_info = requests.get(get_user_info_url).json()
# user_id = user_info['userid']
# print(user_info)
# # user_ticket = user_info['user_ticket']

# get_user_detail_url = f'https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={access_token}&userid={user_id}'
# user_detail = requests.get(get_user_detail_url).json()
# print(user_detail)
# return user_detail

# if __name__ == "__main__":
# import uvicorn
# uvicorn.run(app, host="0.0.0.0", port=45628, ssl_keyfile="/etc/nginx/ssl/db.yun.store.key", ssl_certfile="/etc/nginx/ssl/db.yun.store.pem", log_level="debug")


0 comments on commit f7e3bd7

Please sign in to comment.