llj
昨天 7ffc405f1ec85b0afff09e4f2aa2d81d7c03ed5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import {
    CommonUtils
} from "./common";
 
class getuiInstance {
    constructor() {
        this.cid = ""
    }
 
    getClientID(Userbm, UserName) {
        // #ifdef APP-PLUS
        // 定义重试参数:最多重试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({
                url: "/Web/SetGy_UserClientIdConnection",
                method: "POST",
                data: {
                    HUserbm: Userbm,
                    HUserName: UserName,
                    HClientID: ClientID,
                    HOnline: Online
                }
            })
            
 
            let {
                data,
                count,
                Message
            } = res.data
            
            if(count != 1) {
                CommonUtils.showTips({
                    title: "温馨提示",
                    message: Message
                })
            }
        }catch(err) {
            CommonUtils.showTips({
                title: "温馨提示",
                message: err
            })
        }
 
    }
}
 
 
 
 
export default new getuiInstance()