update pay ui
This commit is contained in:
12
app.py
12
app.py
@@ -4956,10 +4956,13 @@ def generate_jssdk_signature(url, appid, appsecret):
|
|||||||
def api_wechat_jssdk_config():
|
def api_wechat_jssdk_config():
|
||||||
"""获取微信 JS-SDK 签名配置(用于开放标签)"""
|
"""获取微信 JS-SDK 签名配置(用于开放标签)"""
|
||||||
try:
|
try:
|
||||||
|
print(f"[JS-SDK Config] 收到请求")
|
||||||
data = request.get_json() or {}
|
data = request.get_json() or {}
|
||||||
url = data.get('url')
|
url = data.get('url')
|
||||||
|
print(f"[JS-SDK Config] URL: {url}")
|
||||||
|
|
||||||
if not url:
|
if not url:
|
||||||
|
print(f"[JS-SDK Config] 错误: 缺少 url 参数")
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'code': 400,
|
'code': 400,
|
||||||
'message': '缺少必要参数 url',
|
'message': '缺少必要参数 url',
|
||||||
@@ -4969,8 +4972,11 @@ def api_wechat_jssdk_config():
|
|||||||
# URL 校验:必须是允许的域名
|
# URL 校验:必须是允许的域名
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
parsed = urlparse(url)
|
parsed = urlparse(url)
|
||||||
allowed_domains = ['valuefrontier.cn', 'www.valuefrontier.cn', 'localhost', '127.0.0.1']
|
# 扩展允许的域名列表,包括 API 域名
|
||||||
if parsed.netloc.split(':')[0] not in allowed_domains:
|
allowed_domains = ['valuefrontier.cn', 'www.valuefrontier.cn', 'api.valuefrontier.cn', 'localhost', '127.0.0.1']
|
||||||
|
domain = parsed.netloc.split(':')[0]
|
||||||
|
print(f"[JS-SDK Config] 解析域名: {domain}")
|
||||||
|
if domain not in allowed_domains:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'code': 400,
|
'code': 400,
|
||||||
'message': 'URL 域名不在允许范围内',
|
'message': 'URL 域名不在允许范围内',
|
||||||
@@ -4982,11 +4988,13 @@ def api_wechat_jssdk_config():
|
|||||||
url = url.split('#')[0]
|
url = url.split('#')[0]
|
||||||
|
|
||||||
# 生成签名(使用公众号配置)
|
# 生成签名(使用公众号配置)
|
||||||
|
print(f"[JS-SDK Config] 开始生成签名...")
|
||||||
config = generate_jssdk_signature(
|
config = generate_jssdk_signature(
|
||||||
url=url,
|
url=url,
|
||||||
appid=WECHAT_MP_APPID,
|
appid=WECHAT_MP_APPID,
|
||||||
appsecret=WECHAT_MP_APPSECRET
|
appsecret=WECHAT_MP_APPSECRET
|
||||||
)
|
)
|
||||||
|
print(f"[JS-SDK Config] 签名生成完成: {config is not None}")
|
||||||
|
|
||||||
if not config:
|
if not config:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|||||||
@@ -133,26 +133,31 @@ const WxOpenLaunchWeapp = ({
|
|||||||
...buttonStyle,
|
...buttonStyle,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载中状态
|
// 加载中状态 - 显示可点击的按钮,避免用户等待太久
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<Box display="flex" alignItems="center" justifyContent="center" py={3}>
|
<ChakraButton
|
||||||
<Spinner size="sm" mr={2} />
|
colorScheme="green"
|
||||||
<Text fontSize="sm" color="gray.500">正在初始化...</Text>
|
isLoading
|
||||||
</Box>
|
loadingText="初始化中..."
|
||||||
|
width="100%"
|
||||||
|
style={buttonStyle}
|
||||||
|
>
|
||||||
|
{typeof children === 'string' ? children : '打开小程序'}
|
||||||
|
</ChakraButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 错误状态
|
// 错误状态 - 提供重试选项
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<ChakraButton
|
<ChakraButton
|
||||||
colorScheme="gray"
|
colorScheme="orange"
|
||||||
isDisabled
|
onClick={initWxSdk}
|
||||||
width="100%"
|
width="100%"
|
||||||
py={3}
|
style={buttonStyle}
|
||||||
>
|
>
|
||||||
{error}
|
点击重试
|
||||||
</ChakraButton>
|
</ChakraButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { getApiBase } from '@utils/apiConfig';
|
|||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: getApiBase(),
|
baseURL: getApiBase(),
|
||||||
timeout: 10000,
|
timeout: 30000, // 增加到 30 秒,因为首次需要从微信 API 获取 access_token 和 jsapi_ticket
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user