fix: 迁移码返回完整URL;确认须在目标店;兼容扫码接收
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -980,6 +980,12 @@ def serialize_plan(plan: ClubMigratePlan) -> dict:
|
||||
|
||||
|
||||
def serialize_token(token_row: ClubMigrateToken) -> dict:
|
||||
qr = (token_row.qrcode_url or '').strip()
|
||||
if qr and not qr.startswith('http'):
|
||||
from django.conf import settings
|
||||
cos_domain = getattr(settings, 'COS_DOMAIN', '').rstrip('/')
|
||||
if cos_domain:
|
||||
qr = f'{cos_domain}/{qr.lstrip("/")}'
|
||||
return {
|
||||
'token': token_row.token,
|
||||
'scene': scene_for_token(token_row.token),
|
||||
@@ -987,7 +993,7 @@ def serialize_token(token_row: ClubMigrateToken) -> dict:
|
||||
'from_club_id': token_row.from_club_id,
|
||||
'to_club_id': token_row.to_club_id,
|
||||
'status': token_row.status,
|
||||
'qrcode_url': token_row.qrcode_url or '',
|
||||
'qrcode_url': qr,
|
||||
'expire_at': token_row.expire_at.isoformat() if token_row.expire_at else '',
|
||||
'asset_snapshot': token_row.asset_snapshot or {},
|
||||
}
|
||||
|
||||
@@ -74,16 +74,17 @@ def generate_migrate_qrcode(*, to_club_id: str, token: str) -> Tuple[str, str]:
|
||||
oss_path = f"club_migrate/{club_id}/{filename}"
|
||||
file_obj = io.BytesIO(wx_resp.content)
|
||||
try:
|
||||
full_url = upload_to_oss(file_obj, oss_path)
|
||||
full_url = upload_to_oss(file_obj, oss_path, content_type='image/png')
|
||||
except Exception as e:
|
||||
logger.exception('migrate qr upload fail: %s', e)
|
||||
return '', f'上传小程序码失败: {e}'
|
||||
if not full_url:
|
||||
return '', '上传小程序码失败'
|
||||
|
||||
# 前端保存相册必须用 https 完整链;相对路径在 oss 未就绪时会保存失败
|
||||
if str(full_url).startswith('http'):
|
||||
return str(full_url), ''
|
||||
cos_domain = getattr(settings, 'COS_DOMAIN', '').rstrip('/')
|
||||
if cos_domain and full_url.startswith(cos_domain):
|
||||
relative_path = full_url.replace(f'{cos_domain}/', '', 1)
|
||||
else:
|
||||
relative_path = oss_path
|
||||
return relative_path, ''
|
||||
if cos_domain:
|
||||
return f'{cos_domain}/{str(full_url).lstrip("/")}', ''
|
||||
return str(full_url), ''
|
||||
|
||||
Reference in New Issue
Block a user