// 静默登录方法
export const silentLogin = () => {
    return new Promise((resolve, reject) => {
        uni.login({
            success(loginRes) {
                let platform = uni.getSystemInfoSync().uniPlatform
                let data = uni.getStorageSync("loginType") || {};
                data.code = loginRes.code;
                data.plat = platform === 'mp-alipay' ? 2 : 1
                data.upsellCode = uni.getStorageSync("upsellCode") || ''
                console.log("登录参数2", data);

                uni.$u.http
                    .post("/user/wxLogin", data)
                    .then((response) => {
                        if (response.code == 200) {
                            console.log("静默登录成功");
                            uni.setStorageSync("token", response.data.token);
                            uni.setStorageSync("loginSuccess", response.data);
                            resolve(response.data);
                        } else {
                            console.log("静默登录失败");
                            uni.removeStorageSync("token");
                            reject(response);
                        }
                    })
                    .catch((error) => {
                        console.log("静默登录异常");
                        uni.removeStorageSync("token");
                        reject(error);
                    });
            },
            fail: (error) => {
                console.log("获取登录code失败");
                uni.removeStorageSync("token");
                reject(error);
            },
        });
    });
};
