添加不同环境的url

This commit is contained in:
kron
2025-08-09 12:16:36 +08:00
parent ca6cb989c7
commit e164d4736e
4 changed files with 29 additions and 4 deletions

View File

@@ -7,7 +7,29 @@ let reconnectTimer = null;
* 建立 WebSocket 连接
*/
function createWebSocket(token, onMessage) {
const url = `wss://api.shelingxingqiu.com/socket?authorization=${token}`;
let url = "wss://api.shelingxingqiu.com/socket";
try {
const accountInfo = uni.getAccountInfoSync();
const envVersion = accountInfo.miniProgram.envVersion;
switch (envVersion) {
case "develop": // 开发版
url = "wss://apitest.shelingxingqiu.com/socket";
break;
case "trial": // 体验版
url = "wss://apitest.shelingxingqiu.com/socket";
break;
case "release": // 正式版
url = "wss://api.shelingxingqiu.com/socket";
break;
default:
// 保持默认值
break;
}
} catch (e) {
console.error("获取环境信息失败,使用默认正式环境", e);
}
url += `?authorization=${token}`;
socket = uni.connectSocket({
url,
success: () => {