rainycode 1.1.2__tar.gz → 1.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {rainycode-1.1.2 → rainycode-1.1.4}/PKG-INFO +1 -1
  2. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/api/auth_api.py +2 -2
  3. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/service/auth_svc.py +12 -10
  4. {rainycode-1.1.2 → rainycode-1.1.4}/pyproject.toml +1 -1
  5. {rainycode-1.1.2 → rainycode-1.1.4}/rainycode.egg-info/PKG-INFO +1 -1
  6. {rainycode-1.1.2 → rainycode-1.1.4}/common_base/aiorequests.py +0 -0
  7. {rainycode-1.1.2 → rainycode-1.1.4}/common_base/consts.py +0 -0
  8. {rainycode-1.1.2 → rainycode-1.1.4}/common_base/exception.py +0 -0
  9. {rainycode-1.1.2 → rainycode-1.1.4}/common_base/logging.py +0 -0
  10. {rainycode-1.1.2 → rainycode-1.1.4}/common_base/response.py +0 -0
  11. {rainycode-1.1.2 → rainycode-1.1.4}/common_depends/auth_depend.py +0 -0
  12. {rainycode-1.1.2 → rainycode-1.1.4}/common_models/__init__.py +0 -0
  13. {rainycode-1.1.2 → rainycode-1.1.4}/common_models/base_model.py +0 -0
  14. {rainycode-1.1.2 → rainycode-1.1.4}/common_models/user_model.py +0 -0
  15. {rainycode-1.1.2 → rainycode-1.1.4}/common_models/wechat_model.py +0 -0
  16. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/api/wechat_api.py +0 -0
  17. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/router.py +0 -0
  18. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/schemas/__init__.py +0 -0
  19. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/schemas/auth_schema.py +0 -0
  20. {rainycode-1.1.2 → rainycode-1.1.4}/common_servers/service/wechat_svc.py +0 -0
  21. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/bcrypt_util.py +0 -0
  22. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/captcha_util.py +0 -0
  23. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/ip_util.py +0 -0
  24. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/jwt_util.py +0 -0
  25. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/snowflake_util.py +0 -0
  26. {rainycode-1.1.2 → rainycode-1.1.4}/common_utils/wechat_util.py +0 -0
  27. {rainycode-1.1.2 → rainycode-1.1.4}/core/base_config.py +0 -0
  28. {rainycode-1.1.2 → rainycode-1.1.4}/core/databases/aiodb.py +0 -0
  29. {rainycode-1.1.2 → rainycode-1.1.4}/core/databases/aioredis.py +0 -0
  30. {rainycode-1.1.2 → rainycode-1.1.4}/core/middleware/http_middleware.py +0 -0
  31. {rainycode-1.1.2 → rainycode-1.1.4}/core/start.py +0 -0
  32. {rainycode-1.1.2 → rainycode-1.1.4}/rainycode.egg-info/SOURCES.txt +0 -0
  33. {rainycode-1.1.2 → rainycode-1.1.4}/rainycode.egg-info/dependency_links.txt +0 -0
  34. {rainycode-1.1.2 → rainycode-1.1.4}/rainycode.egg-info/requires.txt +0 -0
  35. {rainycode-1.1.2 → rainycode-1.1.4}/rainycode.egg-info/top_level.txt +0 -0
  36. {rainycode-1.1.2 → rainycode-1.1.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainycode
3
- Version: 1.1.2
3
+ Version: 1.1.4
4
4
  Summary: FastAPI base modules
5
5
  Requires-Python: >=3.8
6
6
  Requires-Dist: build==1.4.0
@@ -58,7 +58,7 @@ async def login_mini(wechat_in: WechatLogin):
58
58
 
59
59
  @router.get("/wechat/oauth", summary="获取微信网页授权链接 - 回调(/oauth/callback)")
60
60
  async def get_wechat_oauth_url(
61
- app_id: str = Query(..., description="微信 AppID"),
61
+ app_pk: int = Query(..., description="微信应用主键ID"),
62
62
  redirect_uri: str = Query(..., description="授权成功后跳转地址"),
63
63
  state: str | None = Query(default=None, description="自定义状态参数"),
64
64
  ):
@@ -69,5 +69,5 @@ async def get_wechat_oauth_url(
69
69
  - 如果用户已注册,回调后直接返回 token
70
70
  - 如果用户未注册,自动重定向到 snsapi_userinfo 授权
71
71
  """
72
- authorize_url = await AuthService.get_wechat_oauth_url(app_id, redirect_uri, state)
72
+ authorize_url = await AuthService.get_wechat_oauth_url(app_pk, redirect_uri, state)
73
73
  return SuccessReturn(data={"authorize_url": authorize_url})
@@ -146,17 +146,17 @@ class AuthService:
146
146
  logger.info(f"用户登出: user_id={user_id}, username={username}")
147
147
 
148
148
  @classmethod
149
- async def get_wechat_oauth_url(cls, app_id: str, redirect_uri: str, state: str | None = None) -> str:
149
+ async def get_wechat_oauth_url(cls, app_pk: int, redirect_uri: str, state: str | None = None) -> str:
150
150
  """
151
151
  生成微信网页授权链接(snsapi_base)
152
152
 
153
- :param app_id: 微信 AppID
153
+ :param app_pk: 微信应用主键ID
154
154
  :param redirect_uri: 授权成功后跳转的前端地址
155
155
  :param state: 自定义状态参数
156
156
  :return: 微信授权链接
157
157
  """
158
158
  # 验证公众号配置
159
- app_config = await WechatApp.get_or_none(app_id=app_id, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
159
+ app_config = await WechatApp.get_or_none(id=app_pk, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
160
160
  if not app_config:
161
161
  raise CustomException(msg="无效的公众号配置")
162
162
 
@@ -168,12 +168,13 @@ class AuthService:
168
168
  # 生成内部 state
169
169
  internal_state = state or str(uuid.uuid4())
170
170
 
171
- # 缓存 state -> (redirect_uri, app_id) 映射,有效期 5 分钟
172
- cache_value = json.dumps({"redirect_uri": redirect_uri, "app_id": app_id})
171
+ # 缓存 state -> (redirect_uri, app_pk) 映射,有效期 5 分钟
172
+ cache_value = json.dumps({"redirect_uri": redirect_uri, "app_pk": app_pk})
173
173
  await AioRedis.set(f"{REDIS_PREFIX_OAUTH_STATE}{internal_state}", cache_value, ex=300)
174
174
 
175
175
  # 构建回调地址
176
- callback_url = f"{base_config.base_url}/wechat/oauth/callback"
176
+ api_prefix = f"/api/{base_config.app_name}" if base_config.app_name else ""
177
+ callback_url = f"{base_config.base_url}{api_prefix}/wechat/oauth/callback"
177
178
 
178
179
  return WechatUtil.build_oauth_url(
179
180
  appid=app_config.app_id,
@@ -202,11 +203,11 @@ class AuthService:
202
203
  try:
203
204
  cached_data = json.loads(cache_value)
204
205
  redirect_uri = cached_data.get("redirect_uri")
205
- app_id = cached_data.get("app_id")
206
+ app_pk = cached_data.get("app_pk")
206
207
  except (json.JSONDecodeError, TypeError):
207
208
  raise CustomException(msg="授权数据格式错误")
208
209
 
209
- if not redirect_uri or not app_id:
210
+ if not redirect_uri or not app_pk:
210
211
  raise CustomException(msg="授权数据不完整")
211
212
 
212
213
  # 删除已使用的 state
@@ -218,7 +219,7 @@ class AuthService:
218
219
  raise CustomException(msg="授权码已失效,请重新授权")
219
220
 
220
221
  # 获取公众号配置
221
- app_config = await WechatApp.get_or_none(app_id=app_id, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
222
+ app_config = await WechatApp.get_or_none(id=app_pk, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
222
223
  if not app_config:
223
224
  raise CustomException(msg="公众号配置不存在")
224
225
 
@@ -271,7 +272,8 @@ class AuthService:
271
272
  await AioRedis.set(f"{REDIS_PREFIX_OAUTH_STATE}{new_state}", cache_value, ex=300)
272
273
 
273
274
  # 构建 snsapi_userinfo 授权链接
274
- callback_url = f"{base_config.base_url}/wechat/oauth/callback"
275
+ api_prefix = f"/api/{base_config.app_name}" if base_config.app_name else ""
276
+ callback_url = f"{base_config.base_url}{api_prefix}/wechat/oauth/callback"
275
277
  userinfo_auth_url = WechatUtil.build_oauth_url(
276
278
  appid=app_config.app_id,
277
279
  redirect_uri=callback_url,
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rainycode"
7
- version = "1.1.2"
7
+ version = "1.1.4"
8
8
  description = "FastAPI base modules"
9
9
  requires-python = ">=3.8"
10
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainycode
3
- Version: 1.1.2
3
+ Version: 1.1.4
4
4
  Summary: FastAPI base modules
5
5
  Requires-Python: >=3.8
6
6
  Requires-Dist: build==1.4.0
File without changes
File without changes
File without changes