/// <summary> /// 更新下载完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (Bas.GetFileHash(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\update.zip") == updateinfo.hash) { SendMsg("Q"); if (Bas.UnZip(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\update.zip", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\", "")) { version = updateinfo.version; version_str = updateinfo.version_str; Save(); NeedUpdate = false; updateinfo = null; MsgBoxPushHelper.RaisePushMsg($"插件{name}更新成功!"); } else { MsgBoxPushHelper.RaisePushMsg($"插件{name}更新失败,解压或文件错误!"); } } else { MsgBoxPushHelper.RaisePushMsg($"插件{name}更新失败,文件校验失败!"); } }
/// <summary> /// 刷新数据 /// </summary> /// <returns>刷新数据后的实例</returns> public Article Refresh() { GetRealTime(); string str = Bas.GetHTTPBody("https://member.bilibili.com/x/h5/data/article", Account.Instance.Cookies, "https://member.bilibili.com/studio/gabriel/data-center/overview"); if (!string.IsNullOrEmpty(str)) { try { Article_Data_Template obj = JsonConvert.DeserializeObject <Article_Data_Template>(str); if (obj.code == 0) { coin = obj.data.stat.coin; coin_incr = obj.data.stat.incr_coin; fav = obj.data.stat.fav; fav_incr = obj.data.stat.incr_fav; like = obj.data.stat.like; like_incr = obj.data.stat.incr_like; reply = obj.data.stat.reply; reply_incr = obj.data.stat.incr_reply; share = obj.data.stat.share; share_incr = obj.data.stat.incr_share; view = obj.data.stat.view; view_incr = obj.data.stat.incr_view; } } catch { } } return(this); }
/// <summary> /// 获得充电数据 /// </summary> /// <returns>电池数</returns> private double GetCharge() { string str = Bas.GetHTTPBody("https://member.bilibili.com/x/web/elec/balance", Account.Instance.Cookies); if (!string.IsNullOrEmpty(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { return((double)obj["data"]["wallet"]["sponsorBalance"]); } else { return(-1); } } catch { return(-1); } } else { return(-1); } }
private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { Status = "正在校验..."; if (Bas.GetFileHash(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip") == jobj["data"]["hash"].ToString()) { Status = "正在解压..."; if (Bas.UnZip(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp\\", "")) { Status = "正在安装..."; File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip"); File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.bat", "@echo off\r\n" + "choice /t 5 /d y /n >nul\r\n" + //等待5s开始 "xcopy \"" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp" + "\" \"" + Application.StartupPath + "\" /s /e /y\r\n" + //覆盖程序 "rmdir /s /q \"" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp\\" + "\"\r\n" + //删除更新缓存 "start \"\" \"" + Application.ExecutablePath + "\" -s\r\n" + //启动程序 "del %0", Encoding.Default); Process p = new Process(); p.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.bat"; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.Verb = "runas";//管理员启动 p.Start(); Environment.Exit(2); } } else { MsgBoxPushHelper.RaisePushMsg("校验错误,请稍后再试!"); IsFinished = true; } (sender as WebClient).Dispose(); }
/// <summary> /// 获取用户信息 /// </summary> public void GetInfo(object o = null) { if (Islogin) { string str = Bas.GetHTTPBody("https://api.bilibili.com/x/space/myinfo", Cookies); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { Pic = obj["data"]["face"].ToString(); UName = obj["data"]["name"].ToString(); Desc = obj["data"]["sign"].ToString(); Level = (int)obj["data"]["level_exp"]["current_level"]; if ((double)obj["data"]["level_exp"]["next_exp"] != -1) { ExpProgress = ((double)obj["data"]["level_exp"]["current_exp"] - (double)obj["data"]["level_exp"]["current_min"]) / ((double)obj["data"]["level_exp"]["next_exp"] - (double)obj["data"]["level_exp"]["current_min"]); str_ExpProgress = $"{obj["data"]["level_exp"]["current_exp"].ToString()}/{obj["data"]["level_exp"]["next_exp"].ToString()}"; } else { ExpProgress = 1; str_ExpProgress = $"{obj["data"]["level_exp"]["current_exp"].ToString()}/{obj["data"]["level_exp"]["current_min"].ToString()}"; } } } } }
/// <summary> /// 刷新数据 /// </summary> /// <returns>刷新数据后的实例</returns> public Article Refresh() { GetRealTime(); string str = Bas.GetHTTPBody("https://member.bilibili.com/x/h5/data/article", Bas.account.Cookies, "https://member.bilibili.com/studio/gabriel/data-center/overview"); if (!string.IsNullOrEmpty(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { coin = (int)obj["data"]["stat"]["coin"]; coin_incr = (int)obj["data"]["stat"]["incr_coin"]; fav = (int)obj["data"]["stat"]["fav"]; fav_incr = (int)obj["data"]["stat"]["incr_fav"]; like = (int)obj["data"]["stat"]["like"]; like_incr = (int)obj["data"]["stat"]["incr_like"]; reply = (int)obj["data"]["stat"]["reply"]; reply_incr = (int)obj["data"]["stat"]["incr_reply"]; share = (int)obj["data"]["stat"]["share"]; share_incr = (int)obj["data"]["stat"]["incr_share"]; view = (int)obj["data"]["stat"]["view"]; view_incr = (int)obj["data"]["stat"]["incr_view"]; } } catch { } } return(this); }
private void Refresh(object state) { string str = Bas.GetHTTPBody("https://member.bilibili.com/x/app/h5/activity/videoall?platform=ios", Account.Instance.Cookies); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { Dispatcher?.Invoke(() => { EventList.Children.Clear(); }); foreach (JToken i in obj["data"]) { Dispatcher.Invoke(() => { EventList.Children.Add(new EventItem(new EventItem.EventInfo() { Title = i["name"].ToString(), Desc = i["protocol"].ToString(), Link = i["act_url"].ToString(), Start_Time = i["stime"].ToString(), End_Time = "-" })); }); } } } }
/// <summary> /// 安装插件 /// </summary> /// <param name="packet">插件包位置</param> /// <returns>插件信息</returns> public void Install(string packet) { if (File.Exists(packet)) { if (Bas.UnZip(packet, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\", "")) { if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\mainfirst.json")) { try { string str = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\mainfirst.json"); PluginInfo plugin = JsonConvert.DeserializeObject <PluginInfo>(str); if (string.IsNullOrEmpty(plugin.name) || string.IsNullOrEmpty(plugin.launch_file) || string.IsNullOrEmpty(plugin.version_str) || plugin.version == null) { throw new Exception("参数错误!"); } Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{plugin.name}\\"); MsgBoxPushHelper.RaisePushMsg("安装插件成功!"); Plugins.Add(plugin); } catch (Exception ex) { MsgBoxPushHelper.RaisePushMsg($"安装插件错误!{ex.Message}"); if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\")) { Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"); } } } else { MsgBoxPushHelper.RaisePushMsg("安装插件失败,插件包不完整!"); if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\")) { Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"); } } } else { MsgBoxPushHelper.RaisePushMsg("安装插件失败,解压包失败!"); if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\")) { Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"); } } } else { MsgBoxPushHelper.RaisePushMsg("安装插件失败,插件包不存在!"); } }
/// <summary> /// 刷新数据 /// </summary> /// <returns>刷新后的实例</returns> public Video Refresh() { GetRealTime(); string str = Bas.GetHTTPBody("https://member.bilibili.com/x/h5/data/overview?type=0", Bas.account.Cookies, "https://member.bilibili.com/studio/gabriel/data-center/overview"); if (!string.IsNullOrEmpty(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { coin = (int)obj["data"]["stat"]["coin"]; coin_incr = (int)obj["data"]["stat"]["coin"] - (int)obj["data"]["stat"]["coin_last"]; comment = (int)obj["data"]["stat"]["comment"]; comment_incr = (int)obj["data"]["stat"]["comment"] - (int)obj["data"]["stat"]["comment_last"]; dm = (int)obj["data"]["stat"]["dm"]; dm_incr = (int)obj["data"]["stat"]["dm"] - (int)obj["data"]["stat"]["dm_last"]; fav = (int)obj["data"]["stat"]["fav"]; fav_incr = (int)obj["data"]["stat"]["fav"] - (int)obj["data"]["stat"]["fav_last"]; like = (int)obj["data"]["stat"]["like"]; like_incr = (int)obj["data"]["stat"]["like"] - (int)obj["data"]["stat"]["like_last"]; play = (int)obj["data"]["stat"]["play"]; play_incr = (int)obj["data"]["stat"]["play"] - (int)obj["data"]["stat"]["play_last"]; share = (int)obj["data"]["stat"]["share"]; share_incr = (int)obj["data"]["stat"]["share"] - (int)obj["data"]["stat"]["share_last"]; } fan = (int)obj["data"]["stat"]["fan"]; fan_incr = (int)obj["data"]["stat"]["fan"] - (int)obj["data"]["stat"]["fan_last"]; double tmp1 = GetCharge(); if (tmp1 != -1) { elec = tmp1; elec_incr = (double)obj["data"]["stat"]["elec"] - (double)obj["data"]["stat"]["elec_last"]; } } catch { } } double[] tmp = GetGrowUp(); if (tmp != new double[2] { -1, -1 }) { growup_incr = tmp[0]; growup = tmp[1]; } return(this); }
/// <summary> /// 刷新数据 /// </summary> /// <returns>刷新后的实例</returns> public Video Refresh() { GetRealTime(); string str = Bas.GetHTTPBody("https://member.bilibili.com/x/h5/data/overview?type=0", Account.Instance.Cookies, "https://member.bilibili.com/studio/gabriel/data-center/overview"); if (!string.IsNullOrEmpty(str)) { try { Video_Data_Template obj = JsonConvert.DeserializeObject <Video_Data_Template>(str); if (obj.code == 0) { coin = obj.data.stat.coin; coin_incr = obj.data.stat.coin - obj.data.stat.coin_last; comment = obj.data.stat.comment; comment_incr = obj.data.stat.comment - obj.data.stat.comment_last; dm = obj.data.stat.dm; dm_incr = obj.data.stat.dm - obj.data.stat.dm_last; fav = obj.data.stat.fav; fav_incr = obj.data.stat.fav - obj.data.stat.fav_last; like = obj.data.stat.like; like_incr = obj.data.stat.like - obj.data.stat.like_last; play = obj.data.stat.play; play_incr = obj.data.stat.play - obj.data.stat.play_last; share = obj.data.stat.share; share_incr = obj.data.stat.share - obj.data.stat.share_last; fan = obj.data.stat.fan; fan_incr = obj.data.stat.fan - obj.data.stat.fan_last; double tmp1 = GetCharge(); elec = tmp1 == -1 ? obj.data.stat.elec : tmp1; elec_incr = obj.data.stat.elec - obj.data.stat.elec_last; elec_total = obj.data.stat.elec; } } catch { } } double[] tmp = GetGrowUp(); if (tmp != new double[2] { -1, -1 }) { growup_incr = tmp[0]; growup = tmp[1]; } return(this); }
public static void Main(string[] args) { if (RunningInstance() != null && Environment.CommandLine.ToLower().IndexOf("-m") == -1) { System.Windows.Forms.MessageBox.Show("已经有一个实例在运行!"); Environment.Exit(0); } //用户统计 Bas.User_Statistics(); _ = NotifyIconHelper.Instance; if (Settings.Instance.IsFirstRun) { //首次运行执行 if (WindowsManager.Instance.GetWindow <LisenceWindow>().ShowDialog() != true) { Environment.Exit(-2); } Settings.Instance.IsFirstRun = false; } //初始化WPF为25帧 Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 25 }); if (Settings.Instance.IsAutoCheckUpdate) { Update.Instance.CheckUpdate(false); } if (Environment.CommandLine.ToLower().IndexOf("-s") == -1) { WindowsManager.Instance.GetWindow <MainWindow>().Show(); } Application app = new Application(); app.ShutdownMode = ShutdownMode.OnExplicitShutdown; Thread DesktopWnd_Monitor = new Thread(DesktopWnd_Monitor_Handler); DesktopWnd_Monitor.Name = "DesktopWnd_Monitor"; DesktopWnd_Monitor.IsBackground = false; DesktopWnd_Monitor.Start(app); app.Run(); }
/// <summary> /// 修改简介 /// </summary> /// <param name="NewDesc">新简介文本</param> public void ChangeDesc(string NewDesc) { string str = Bas.PostHTTPBody("https://api.bilibili.com/x/member/web/sign/update", "user_sign=" + NewDesc + "&jsonp=jsonp&csrf=" + Csrf_Token, Cookies); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { MsgBoxPushHelper.RaisePushMsg("修改简介成功!"); return; } } MsgBoxPushHelper.RaisePushMsg("修改简介失败!" + str); }
/// <summary> /// 注销账号 /// </summary> public void SignOut() { Bas.GetHTTPBody("https://passport.bilibili.com/login?act=exit", Cookies, ""); Islogin = false; if (ST.IsSavePassword) { ST = new AccountTable(ST.UserName, ST.PassWord); } else { ST = new AccountTable(ST.UserName); } Save(); }
/// <summary> /// 获取登陆二维码并显示 /// </summary> private void GetQrcode() { re: //获取二维码要包含的url string str = Bas.GetHTTPBody("https://passport.bilibili.com/qrcode/getLoginUrl", "", "https://passport.bilibili.com/login"); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { // 生成二维码的内容 string strCode = obj["data"]["url"].ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); //生成二维码位图 Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 0, 6, false); qrcodeBox.Dispatcher.Invoke(delegate() { IntPtr myImagePtr = qrCodeImage.GetHbitmap(); //创建GDI对象,返回指针 BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); //创建imgSource WinAPIHelper.DeleteObject(myImagePtr); qrcodeBox.Source = imgsource; }); Monitor = new Timer(MonitorCallback, obj["data"]["oauthKey"].ToString(), 1000, 1000); Refresher = new Timer(RefresherCallback, null, 180000, Timeout.Infinite); } } else { goto re; } }
public void CheckUpdate(bool IsGUI = true) { IsFinished = false; string str = Bas.GetHTTPBody("https://cloud.api.zhangbudademao.com/117/Update"); if (!string.IsNullOrEmpty(str)) { try { jobj = JObject.Parse(str); if ((int)jobj["code"] == 0) { if (jobj["data"]["version"].ToString() == System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()) { if (IsGUI) { MessageBox.Show("当前版本已是最新"); } return; } else { if (IsGUI) { UpdateText = "当前版本:" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\r\n最新版本:" + jobj["data"]["version"].ToString() + "(" + jobj["data"]["updatetime"].ToString() + "更新)\r\n\r\n更新内容:\r\n" + jobj["data"]["content"].ToString(); uw = (uw == null || uw.IsVisible == false) ? new UpdateWindow() : uw; uw.Show(); } else { Bas.notifyIcon.ShowToolTip("检查到新版本!请通过“检查更新”屏幕更新。"); } } } } catch { } } }
public void CheckUpdate(bool IsGUI = true) { IsFinished = false; string str = Bas.GetHTTPBody("https://cloud.api.zhangbudademao.com/117/Update"); if (!string.IsNullOrEmpty(str)) { try { jobj = JObject.Parse(str); if ((int)jobj["code"] == 0) { if ((int)jobj["data"]["build"] <= Bas.Build) { if (IsGUI) { MessageBox.Show("当前版本已是最新"); } return; } else { if (IsGUI) { UpdateText = "当前版本:" + Bas.Version + "\r\n最新版本:" + jobj["data"]["version"].ToString() + "(" + jobj["data"]["updatetime"].ToString() + "更新)\r\n\r\n更新内容:\r\n" + jobj["data"]["content"].ToString(); WindowsManager.Instance.GetWindow <UpdateWindow>().Show(); } else { NotifyIconHelper.Instance.ShowToolTip("检查到新版本!请通过“检查更新”屏幕更新。"); } } } } catch { } } }
/// <summary> /// 检查更新 /// </summary> public void CheckUpdate() { if (Plugins.Count > 0) { foreach (PluginInfo i in Plugins) { string str = Bas.GetHTTPBody(i.update_url); if (!string.IsNullOrEmpty(str)) { PluginInfo.UpdateInfo info = JsonConvert.DeserializeObject <PluginInfo.UpdateInfo>(str); if (info.code == 0) { if (info.data.version > i.version) { i.NeedUpdate = true; i.updateinfo = info.data; } } } } } }
/// <summary> /// 获得激励计划数据 /// </summary> /// <returns>[0]:前天收入;[1]:本月收入</returns> private double[] GetGrowUp() { string str = Bas.GetHTTPBody("https://api.bilibili.com/studio/growup/web/up/summary", Account.Instance.Cookies); if (!string.IsNullOrWhiteSpace(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { return(new double[2] { (double)obj["data"]["day_income"], (double)obj["data"]["income"] }); } else { return(new double[2] { -1, -1 }); } } catch { return(new double[2] { -1, -1 }); } } else { return(new double[2] { -1, -1 }); } }
/// <summary> /// 获取实时数据 /// </summary> private void GetRealTime() { Data tmp_data; bool IsChangeLast = false, IsError = false; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { IsChangeLast = true; tmp_data = new Data(); } else { tmp_data = new Data(data); } int pn = 1; Article_Real_Data_Template obj = new Article_Real_Data_Template(); do { try { string str = Bas.GetHTTPBodyThrow("https://api.bilibili.com/x/article/creative/article/list?group=0&sort=&pn=" + pn, Account.Instance.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str)) { obj = JsonConvert.DeserializeObject <Article_Real_Data_Template>(str); if (obj.code == 0) { foreach (Article_Real_Data_Template.Data_Template.Article_Template i in obj.artlist.articles) { tmp_data._coin_real += i.stats.coin; tmp_data._fav_real += i.stats.favorite; tmp_data._like_real += i.stats.like; tmp_data._reply_real += i.stats.reply; tmp_data._share_real += i.stats.share; tmp_data._view_real += i.stats.view; if (IsChangeLast) { tmp_data._coin_real_last += i.stats.coin; tmp_data._fav_real_last += i.stats.favorite; tmp_data._like_real_last += i.stats.like; tmp_data._reply_real_last += i.stats.reply; tmp_data._share_real_last += i.stats.share; tmp_data._view_real_last += i.stats.view; } } } } } catch { IsError = true; } } while (++pn * obj.artlist.page.ps <= obj.artlist.page.total && !IsError); //丢弃错误数据 if (!IsError) { data = tmp_data; if (IsChangeLast) { LastTime = DateTime.Compare(DateTime.Now.Date.AddHours(12), DateTime.Now) <= 0 ? DateTime.Now.Date.AddHours(12) : DateTime.Now.Date.AddDays(-1).AddHours(12);//设定为当天12点数据 } } }
/// <summary> /// 获取实时数据 /// </summary> private void GetRealTime() { Data tmp_data; bool IsChangeLast = false, IsError = false; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { tmp_data = new Data(); IsChangeLast = true; } else { tmp_data = new Data(data); } if (ChargeLastTime == null || DateTime.Compare(((DateTime)ChargeLastTime).AddDays(1), DateTime.Now) < 0) { tmp_data._elec_last = GetCharge(); ChargeLastTime = DateTime.Now.Date;//设定为当天0点数据 } int pn = 1; Video_Real_Data_Template obj = new Video_Real_Data_Template(); do { try { string str = Bas.GetHTTPBodyThrow("https://member.bilibili.com/x/web/archives?status=pubed&pn=" + pn + "&ps=10&coop=1&interactive=1", Account.Instance.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str)) { obj = JsonConvert.DeserializeObject <Video_Real_Data_Template>(str); if (obj.code == 0) { foreach (Video_Real_Data_Template.Data_Template.Video_Template i in obj.data.arc_audits) { tmp_data._coin_real += i.stat.coin; tmp_data._dm_real += i.stat.danmaku; tmp_data._fav_real += i.stat.favorite; tmp_data._like_real += i.stat.like; tmp_data._play_real += i.stat.view; tmp_data._share_real += i.stat.share; tmp_data._comment_real += i.stat.reply; if (IsChangeLast) { tmp_data._coin_real_last += i.stat.coin; tmp_data._dm_real_last += i.stat.danmaku; tmp_data._fav_real_last += i.stat.favorite; tmp_data._like_real_last += i.stat.like; tmp_data._play_real_last += i.stat.view; tmp_data._share_real_last += i.stat.share; tmp_data._comment_real_last += i.stat.reply; } } } } } catch { IsError = true; } } while (++pn * obj.data.page.ps <= obj.data.page.count && !IsError); if (!IsError) { data = tmp_data; if (IsChangeLast) { LastTime = DateTime.Compare(DateTime.Now.Date.AddHours(12), DateTime.Now) <= 0 ? DateTime.Now.Date.AddHours(12) : DateTime.Now.Date.AddDays(-1).AddHours(12);//设定为当天12点数据 } } }
/// <summary> /// 监视器回调 /// </summary> /// <param name="o">oauthKey</param> private void MonitorCallback(object o) { string oauthKey = o.ToString(); string str = Bas.PostHTTPBody("https://passport.bilibili.com/qrcode/getLoginInfo", "oauthKey=" + oauthKey + "&gourl=https%3A%2F%2Fwww.bilibili.com%2F", "", "https://passport.bilibili.com/login"); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if (obj.Property("code") != null) { if ((int)obj["code"] == 0)//登陆成功 { //关闭监视器 Monitor.Change(Timeout.Infinite, Timeout.Infinite); Refresher.Change(Timeout.Infinite, Timeout.Infinite); string Querystring = Regex.Split(obj["data"]["url"].ToString(), "\\?")[1]; string[] KeyValuePair = Regex.Split(Querystring, "&"); string cookies = ""; for (int i = 0; i < KeyValuePair.Length - 1; i++) { cookies += KeyValuePair[i] + "; "; string[] tmp = Regex.Split(KeyValuePair[i], "="); switch (tmp[0]) { case "bili_jct": Bas.account.Csrf_Token = tmp[1]; break; case "DedeUserID": Bas.account.Uid = tmp[1]; break; default: break; } } cookies = cookies.Substring(0, cookies.Length - 2); DateTime expires = DateTime.Now.AddDays(29); Bas.account.Cookies = cookies; Bas.account.Expires = expires; Bas.account.Save(); Dispatcher.Invoke(delegate() { DialogResult = true; Close(); }); } } else { switch ((int)obj["data"]) { case -4: //未扫描 break; case -5: //已扫描 lbl_stauts.Dispatcher.Invoke(delegate() { lbl_stauts.Visibility = Visibility.Visible; }); break; case 0: //登陆成功 break; } } } }
/// <summary> /// 获取实时数据 /// </summary> private void GetRealTime() { //清除旧数据 _coin_real = 0; _fav_real = 0; _like_real = 0; _reply_real = 0; _share_real = 0; _view_real = 0; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last = 0; _fav_real_last = 0; _like_real_last = 0; _reply_real_last = 0; _share_real_last = 0; _view_real_last = 0; } bool IsChangeLast = false; string str = Bas.GetHTTPBody("https://api.bilibili.com/x/article/creative/article/list?group=0&sort=&pn=1", Bas.account.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { foreach (JToken i in obj["artlist"]["articles"]) { _coin_real += (int)i["stats"]["coin"]; _fav_real += (int)i["stats"]["favorite"]; _like_real += (int)i["stats"]["like"]; _reply_real += (int)i["stats"]["reply"]; _share_real += (int)i["stats"]["share"]; _view_real += (int)i["stats"]["view"]; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last += (int)i["stats"]["coin"]; _fav_real_last += (int)i["stats"]["favorite"]; _like_real_last += (int)i["stats"]["like"]; _reply_real_last += (int)i["stats"]["reply"]; _share_real_last += (int)i["stats"]["share"]; _view_real_last += (int)i["stats"]["view"]; IsChangeLast = true; } } if ((int)obj["artlist"]["page"]["pn"] * (int)obj["artlist"]["page"]["ps"] > (int)obj["artlist"]["page"]["total"]) { int pn = 2; while (pn * (int)obj["artlist"]["page"]["ps"] <= (int)obj["artlist"]["page"]["total"]) { string str1 = Bas.GetHTTPBody("https://api.bilibili.com/x/article/creative/article/list?group=0&sort=&pn=" + pn, Bas.account.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str1)) { try { JObject obj1 = JObject.Parse(str1); if ((int)obj1["code"] == 0) { foreach (JToken i in obj1["artlist"]["articles"]) { _coin_real += (int)i["stats"]["coin"]; _fav_real += (int)i["stats"]["favorite"]; _like_real += (int)i["stats"]["like"]; _reply_real += (int)i["stats"]["reply"]; _share_real += (int)i["stats"]["share"]; _view_real += (int)i["stats"]["view"]; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last += (int)i["stats"]["coin"]; _fav_real_last += (int)i["stats"]["favorite"]; _like_real_last += (int)i["stats"]["like"]; _reply_real_last += (int)i["stats"]["reply"]; _share_real_last += (int)i["stats"]["share"]; _view_real_last += (int)i["stats"]["view"]; } } } } catch { } } pn++; } } } if (IsChangeLast) { LastTime = DateTime.Now.Date.AddHours(12); //设定为当天12点数据 } } catch { } } }
/// <summary> /// 获取实时数据 /// </summary> private void GetRealTime() { //清除旧数据 _coin_real = 0; _dm_real = 0; _fav_real = 0; _like_real = 0; _play_real = 0; _share_real = 0; _comment_real = 0; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last = 0; _dm_real_last = 0; _fav_real_last = 0; _like_real_last = 0; _play_real_last = 0; _share_real_last = 0; _comment_real_last = 0; _elec_last = GetCharge(); } bool IsChangeLast = false; string str = Bas.GetHTTPBody("https://member.bilibili.com/x/web/archives?status=is_pubing%2Cpubed%2Cnot_pubed&pn=1&ps=10&coop=1", Bas.account.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str)) { try { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { foreach (JToken i in obj["data"]["arc_audits"]) { _coin_real += (int)i["stat"]["coin"]; _dm_real += (int)i["stat"]["danmaku"]; _fav_real += (int)i["stat"]["favorite"]; _like_real += (int)i["stat"]["like"]; _play_real += (int)i["stat"]["view"]; _share_real += (int)i["stat"]["share"]; _comment_real += (int)i["stat"]["reply"]; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last += (int)i["stat"]["coin"]; _dm_real_last += (int)i["stat"]["danmaku"]; _fav_real_last += (int)i["stat"]["favorite"]; _like_real_last += (int)i["stat"]["like"]; _play_real_last += (int)i["stat"]["view"]; _share_real_last += (int)i["stat"]["share"]; _comment_real_last += (int)i["stat"]["reply"]; IsChangeLast = true; } } if ((int)obj["data"]["page"]["pn"] * (int)obj["data"]["page"]["ps"] > (int)obj["data"]["page"]["count"]) { int pn = 2; while (pn * (int)obj["data"]["page"]["ps"] > (int)obj["data"]["page"]["count"]) { string str1 = Bas.GetHTTPBody("https://member.bilibili.com/x/web/archives?status=is_pubing%2Cpubed%2Cnot_pubed&pn=" + pn + "&ps=10&coop=1", Bas.account.Cookies, "https://member.bilibili.com/v2"); if (!string.IsNullOrEmpty(str1)) { try { JObject obj1 = JObject.Parse(str1); if ((int)obj1["code"] == 0) { foreach (JToken i in obj["data"]["arc_audits"]) { _coin_real += (int)i["stat"]["coin"]; _dm_real += (int)i["stat"]["danmaku"]; _fav_real += (int)i["stat"]["favorite"]; _like_real += (int)i["stat"]["like"]; _play_real += (int)i["stat"]["view"]; _share_real += (int)i["stat"]["share"]; _comment_real += (int)i["stat"]["reply"]; if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0) { _coin_real_last += (int)i["stat"]["coin"]; _dm_real_last += (int)i["stat"]["danmaku"]; _fav_real_last += (int)i["stat"]["favorite"]; _like_real_last += (int)i["stat"]["like"]; _play_real_last += (int)i["stat"]["view"]; _share_real_last += (int)i["stat"]["share"]; _comment_real_last += (int)i["stat"]["reply"]; IsChangeLast = true; } } } } catch { } } pn++; } } } if (IsChangeLast) { LastTime = DateTime.Now.Date.AddHours(12); //设定为当天12点数据 } } catch { } } }