| | |
| | | |
| | | getClientID(Userbm, UserName) { |
| | | // #ifdef APP-PLUS |
| | | const info = plus.push.getClientInfo() |
| | | this.cid = info["clientid"] |
| | | console.log('cid: ', this.cid); |
| | | this.setUserClientIDRelative(Userbm, UserName, this.cid, 1) |
| | | // #endif |
| | | // 定义重试参数:最多重试5次,每次间隔1.5秒(可根据实际情况调整) |
| | | const maxRetry = 5; |
| | | const retryInterval = 1500; |
| | | let retryCount = 0; |
| | | |
| | | // 封装获取clientid的核心逻辑 |
| | | const tryGetClientId = () => { |
| | | try { |
| | | const info = plus.push.getClientInfo(); |
| | | // 兼容iOS不同SDK版本的字段名(clientid / clientId) |
| | | const clientid = info?.clientid || info?.clientId; |
| | | |
| | | // 成功获取到clientid |
| | | if (clientid) { |
| | | this.cid = clientid; |
| | | console.log('成功获取cid: ', this.cid); |
| | | this.setUserClientIDRelative(Userbm, UserName, this.cid, 1); |
| | | return; |
| | | } |
| | | |
| | | // 未获取到,且还有重试次数 |
| | | if (retryCount < maxRetry) { |
| | | retryCount++; |
| | | console.log(`第${retryCount}次重试获取cid(暂未获取到),剩余重试次数:${maxRetry - retryCount}`); |
| | | setTimeout(tryGetClientId, retryInterval); |
| | | return; |
| | | } |
| | | |
| | | // 重试耗尽仍未获取到 |
| | | console.error('重试次数耗尽,iOS环境下未获取到clientid'); |
| | | this.cid = ''; |
| | | // 可选:此处可添加获取失败的兜底逻辑(比如记录日志、提示用户等) |
| | | this.setUserClientIDRelative(Userbm, UserName, this.cid, 1); |
| | | |
| | | } catch (error) { |
| | | console.error('获取clientid过程中出现异常:', error); |
| | | if (retryCount < maxRetry) { |
| | | retryCount++; |
| | | setTimeout(tryGetClientId, retryInterval); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | // 启动第一次获取 |
| | | tryGetClientId(); |
| | | // #endif |
| | | } |
| | | |
| | | |
| | | |
| | | async setUserClientIDRelative(Userbm, UserName, ClientID, Online) { |
| | | try { |
| | | let res = await CommonUtils.doRequest2Async({ |