您好,我在配置第三方平台授权时遇到了问题。
**问题描述:**
- 在第三方平台开发配置中,我设置了:
- 授权入口页面域名:dev.streamhost.app
- 授权回调域名:dev.streamhost.app
- 但是系统一直提示"授权入口页面域名:Empty"
**我已经尝试的解决方案:**
1. 确保域名格式正确(不包含https://和路径)
2. 检查服务器响应正常
3. 等待配置生效时间
4. 清除浏览器缓存
**技术细节:**
- 我的授权入口页面:https://dev.streamhost.app/wechat/auth-page/
- 回调地址:https://dev.streamhost.app/wechat/auth/callback/
- 两个域名都使用相同的dev.streamhost.app
**问题:**
为什么系统仍然显示授权入口页面域名为空?是否有其他配置需要检查?
感谢您的帮助!
你好,请参考 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/troubleshooting/authorization_troubleshooting.html 排查下,也可以将配置的开发资料全网发布后再重试下
https://dev.streamhost.app/wechat/auth-page/
从这个网页里,打开授权链接,即可。(可直接redirect到授权链接)
记得需要把origin带过去。
"""
Simple authorization page for testing
URL: /wechat/auth-page/
"""
print("=" * 50)
print("🔐 WECHAT AUTHORIZATION PAGE")
print(f"Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 50)
# Get parameters
client_id = request.GET.get('client_id', 'test_client')
redirect_uri = request.GET.get('redirect_uri', f'{WECHAT_PROTOCOL}://{WECHAT_DOMAIN}/wechat/auth/callback/')
ticket = request.GET.get('ticket', '') # Get ticket from URL parameter
print(f"Client ID: {client_id}")
print(f"Redirect URI: {redirect_uri}")
print(f"Ticket provided: {'Yes' if ticket else 'No'}")
# Generate authorization URL
auth_url = generate_wechat_authorization_url(client_id, redirect_uri, None, request, ticket)
if auth_url:
# Return a simple HTML page with the authorization link
html_content = f"""
<!DOCTYPE html>
<html>
<head>
<title>WeChat Authorization</title>
<style>
body {{ font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }}
.container {{ background: #f5f5f5; padding: 30px; border-radius: 10px; }}
.btn {{ background: #07C160; color: white; padding: 15px 30px; text-decoration: none; border-radius: 5px; display: inline-block; margin: 20px 0; }}
.info {{ background: #e3f2fd; padding: 15px; border-radius: 5px; margin: 20px 0; }}
.ticket-info {{ background: #fff3cd; padding: 15px; border-radius: 5px; margin: 20px 0; border-left: 4px solid #ffc107; }}
</style>
</head>
<body>
<div class="container">
<h1>🔐 WeChat Official Account Authorization</h1>
<div class="info">
<p><strong>Client ID:</strong> {client_id}</p>
<p><strong>Redirect URI:</strong> {redirect_uri}</p>
<p><strong>Domain:</strong> {WECHAT_DOMAIN}</p>
<p><strong>Origin URL:</strong> {WECHAT_PROTOCOL}://{WECHAT_DOMAIN}/wechat/auth-page/</p>
<p><strong>Status:</strong> Ready to authorize</p>
</div>
<div class="ticket-info">
<p><strong>Component Verify Ticket:</strong> {'✅ Provided via URL' if ticket else '❌ Not provided'}</p>
<p><small>To provide a ticket manually, add ?ticket=YOUR_TICKET to the URL</small></p>
</div>
<p>Click the button below to authorize your WeChat Official Account with StreamHost:</p>
<a href="{auth_url}" class="btn">🔗 Authorize WeChat Official Account</a>
<p><small>This will redirect you to WeChat's authorization page. After authorization, you'll be redirected back to your application.</small></p>
</div>
</body>
</html>
"""
return HttpResponse(html_content, content_type='text/html')
else:
return HttpResponse("Failed to generate authorization URL", status=500)
def generate_wechat_authorization_url(client_id, redirect_uri, state, request=None, ticket=None):
"""
Generate WeChat authorization URL
"""
try:
# WeChat authorization URL
base_url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage"
# Generate state parameter if not provided
if not state:
state = f"streamhost_{client_id}_{int(time.time())}"
# Store state for verification
AUTHORIZATION_STATES[state] = {
'client_id': client_id,
'redirect_uri': redirect_uri,
'timestamp': time.time()
}
# Get pre-auth code
pre_auth_code = get_pre_auth_code(ticket)
if not pre_auth_code:
print("❌ Failed to get pre-auth code")
return None
# Build callback URL - always use dev.streamhost.app for consistency
callback_url = f"{WECHAT_PROTOCOL}://{WECHAT_DOMAIN}/wechat/auth/callback/"
# Origin parameter is CRITICAL for WeChat to track the authorization source
origin_url = f"{WECHAT_PROTOCOL}://{WECHAT_DOMAIN}/wechat/auth-page/"
params = {
'component_appid': WECHAT_COMPONENT_APPID,
'pre_auth_code': pre_auth_code,
'redirect_uri': callback_url,
'origin': origin_url, # CRITICAL: This tells WeChat where the request originated
'auth_type': '3', # 3 = Both Official Account and Mini Program
'state': state
}
# Build URL
param_str = '&'.join([f"{k}={v}" for k, v in params.items() if v])
auth_url = f"{base_url}?{param_str}"
print(f"🔗 Generated authorization URL: {auth_url}")
return auth_url
except Exception as e:
print(f"❌ Error generating authorization URL: {e}")
return None
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0;url=<%= link %>">
</head>
<body>
<div>
</div>
</body>
</html>
是的,我已经放了