Ejemplo n.º 1
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     ThreadPool.QueueUserWorkItem(o =>
     {
         SetControlEnabled(this.toolStrip1, false);
         try
         {
             var config = ConfigStorage.GetInstance().GetConfigInfo();
             ClearListView(this.listView1);
             for (int i = 0; i < config.HistoryCookies.Count; i++)
             {
                 var info = config.HistoryCookies[i];
                 AddListViewmItem(this.listView1, new object[]
                 {
                     (i + 1).ToString(),
                     info.Name,
                     info.Id == null ? string.Empty : info.Id.ToString(),
                     info.Cookie,
                     CertificateUtil.GetCertSubjectName(info.CertPath)
                 });
                 SetListViewItemTag(this.listView1, i, info);
                 SetListViewItemChecked(this.listView1, i, true);
             }
         }
         catch (Exception ex)
         {
         }
         SetControlEnabled(this.toolStrip1, true);
     });
 }
Ejemplo n.º 2
0
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count < 1)
            {
                MsgBox.ShowInfo("请勾选账号!");
                return;
            }

            if (MsgBox.ShowOkCancel("确定要删除勾选的账号?", "提示") == DialogResult.Cancel)
            {
                return;
            }

            for (int i = this.listView1.CheckedItems.Count - 1; i >= 0; i--)
            {
                int    index  = this.listView1.CheckedItems[i].Index;
                string cookie = GetListViewItemValue(this.listView1, index, 3);
                string name   = GetListViewItemValue(this.listView1, index, 1);
                ConfigStorage.GetInstance().RemoveCookieInfo(new CookieInfo()
                {
                    Cookie = cookie
                });
                this.listView1.Items.RemoveAt(index);
            }

            // 重新排序
            for (var i = 0; i < this.listView1.Items.Count; i++)
            {
                this.listView1.Items[i].SubItems[0].Text = (i + 1).ToString();
            }
        }
Ejemplo n.º 3
0
        private void button2_MouseClick(object sender, MouseEventArgs e)
        {
            var configInfo       = ConfigStorage.GetInstance().GetConfigInfo();
            ContextMenuStrip cms = new ContextMenuStrip();

            configInfo.HistoryCookies.ForEach(action =>
            {
                var item = cms.Items.Add(action.Name, null, (o, args) =>
                {
                    var menuItem   = o as ToolStripItem;
                    var cookieInfo = menuItem.Tag as CookieInfo;
                    try
                    {
                        //打开证书
                        System.Security.Cryptography.X509Certificates.X509Certificate2 x509 = new System.Security.Cryptography.X509Certificates.X509Certificate2(
                            cookieInfo.CertPath,
                            PapdHelper.DEFAULT_PFX_PASSWORD, X509KeyStorageFlags.Exportable);
                        MsgBox.ShowInfo("证书是别名:" + x509.SubjectName.Name);
                        //x509.Thumbprint;
                        //x509.PublicKey.Key.ToXmlString(false);
                        GlobalContext.CurrentPfxPrivateKey = x509.PrivateKey.ToXmlString(true);
                    }
                    catch (Exception ex)
                    {
                        MsgBox.ShowInfo("证书无效," + ex.Message);
                    }
                });
                item.Tag = action;
            });
            cms.Show(this.button2, e.Location);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 窗体载入函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmStepDataGen_Load(object sender, EventArgs e)
        {
            // 初始化步数
            var configInfo = ConfigStorage.GetInstance().GetConfigInfo();

            this.textBox1.Text = new Random().Next(configInfo.RandomMinStep, configInfo.RandomMaxStep) + "";
            this.textBox1.Select(this.textBox1.TextLength, 1);
        }
Ejemplo n.º 5
0
        public static ConfigStorage GetInstance()
        {
            if (_instance == null)
            {
                _instance = new ConfigStorage();
            }

            return(_instance);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 读取配置信息
        /// </summary>
        static void ReadConfig()
        {
            var        config     = new ConfigStorage(GlobalContext.ConfigFileName);
            ConfigInfo configInfo = config.GetConfigInfo();

            GlobalContext.HistoryCookies    = configInfo.HistoryCookies;
            GlobalContext.IsTestMode        = configInfo.IsTestMode;
            GlobalContext.CurrentConfigInfo = configInfo;
            PapdHelper.DEFAULT_TIMEOUT      = configInfo.RequestTimeoutInSeconds;
        }
Ejemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            var configInfo = ConfigStorage.GetInstance().GetConfigInfo();

            configInfo.IsAutoUploadWalkData      = this.checkBox1.Checked;
            configInfo.IsAutoGrabGold            = this.checkBox2.Checked;
            configInfo.IsAutoFetchYesterdayBonus = this.checkBox3.Checked;
            configInfo.IsAutoGrabTreasure        = this.checkBox4.Checked;
            configInfo.RandomMinStep             = Convert.ToInt32(this.numericUpDown1.Value);
            configInfo.RandomMaxStep             = Convert.ToInt32(this.numericUpDown2.Value);
            configInfo.CreateOrderTimespan       = Convert.ToInt32(this.numericUpDown3.Value);
            ConfigStorage.GetInstance().UpdateAutoConfigInfo(configInfo);

            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 8
0
        private void Init()
        {
            var configInfo = ConfigStorage.GetInstance().GetConfigInfo();

            this.checkBox1.Checked      = configInfo.IsAutoUploadWalkData;
            this.checkBox2.Checked      = configInfo.IsAutoGrabGold;
            this.checkBox3.Checked      = configInfo.IsAutoFetchYesterdayBonus;
            this.checkBox4.Checked      = configInfo.IsAutoGrabTreasure;
            this.numericUpDown1.Minimum = 100;
            this.numericUpDown1.Maximum = 100000;
            this.numericUpDown1.Value   = configInfo.RandomMinStep;
            this.numericUpDown2.Minimum = 100;
            this.numericUpDown2.Maximum = 100000;
            this.numericUpDown2.Value   = configInfo.RandomMaxStep;
            this.numericUpDown3.Value   = configInfo.CreateOrderTimespan;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 窗体关闭时,保存证书路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmStepManager_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!base.IsLogin())
            {
                return;
            }

            // 保存证书路径
            var config = new ConfigStorage(GlobalContext.ConfigFileName);

            if (GlobalContext.CurrentCertPath != null)
            {
                config.UpdateCookieInfo(new CookieInfo()
                {
                    Id = GlobalContext.CurrentUserInfo.id, CertPath = GlobalContext.CurrentCertPath
                });
            }
            else
            {
                config.ClearUserCert(GlobalContext.CurrentUserInfo.id);
            }
        }
Ejemplo n.º 10
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count < 1)
            {
                MsgBox.ShowInfo("请勾选账号!");
                return;
            }

            List <int> checkedRows = new List <int>();

            for (int i = 0; i < this.listView1.CheckedItems.Count; i++)
            {
                checkedRows.Add(this.listView1.CheckedItems[i].Index);
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                var configInfo = ConfigStorage.GetInstance().GetConfigInfo();
                SetControlEnabled(this.toolStrip1, false);
                for (int i = 0; i < checkedRows.Count; i++)
                {
                    int index             = checkedRows[i];
                    CookieInfo cookieInfo = GetListViewItemTag <CookieInfo>(this.listView1, index);
                    string cookie         = cookieInfo.Cookie;
                    string id             = cookieInfo.Id.ToString();
                    string cert           = cookieInfo.CertPath;

                    bool fetchYestodayReward = true;
                    if (configInfo.IsAutoFetchYesterdayBonus)
                    {
                        #region 领取昨日奖励
                        SetListViewItemValue(this.listView1, index, 7, "正在领取奖励");
                        try
                        {
                            var rewardInfo = PH.QueryRewardInfo(cookie, 3000);
                            if (!rewardInfo.IsPreMoneyFetch())
                            {
                                var fetchRewardResult = PH.FetchReward(cookie, rewardInfo.preRewardId);
                                SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取成功!");
                            }
                            else
                            {
                                SetListViewItemValue(this.listView1, index, 7, "昨日奖励已领取。");
                            }
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取失败!");
                            fetchYestodayReward = false;
                        }
                        #endregion
                    }

                    Thread.Sleep(1000);

                    int grabGoldSuccess = 0;
                    if (configInfo.IsAutoGrabGold)
                    {
                        #region 抢金
                        SetListViewItemValue(this.listView1, index, 7, "正在抢金");
                        try
                        {
                            var grabGoldInfo = PH.GetGrabGoldInfo(cookie, 1);
                            for (int j = 0; j < grabGoldInfo.userRankingList.Length; j++)
                            {
                                var user = grabGoldInfo.userRankingList[j];
                                if (!user.IsGrabGoldAvailable())
                                {
                                    continue;
                                }
                                try
                                {
                                    PH.GrabGoldFromFollower(cookie, user.userInfo.userId);
                                    grabGoldSuccess++;
                                }
                                catch (Exception ex)
                                {
                                    SetListViewItemValue(this.listView1, index, 7, "抢金错误");
                                }
                            }
                            SetListViewItemValue(this.listView1, index, 7, "成功抢金" + grabGoldSuccess + "个好友!");
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "抢金失败");
                        }
                        #endregion
                    }

                    int fetchBoxCount = 0;
                    if (configInfo.IsAutoGrabTreasure)
                    {
                        #region 步步夺宝
                        SetListViewItemValue(this.listView1, index, 7, "正在夺宝...");
                        var fetchBoxFuncList = new List <Func <string, PajkResultList <PajkFetchBoxResult> > >();
                        fetchBoxFuncList.Add(PH.FetchBoxByShareReading);
                        fetchBoxFuncList.Add(PH.FetchBoxByWalkMall);
                        fetchBoxFuncList.Add(PH.FetchBoxByInviteFriend);
                        fetchBoxFuncList.Add(PH.FetchBoxByVideo);
                        for (int j = 0; j < fetchBoxFuncList.Count; j++)
                        {
                            try
                            {
                                var fetchResult = fetchBoxFuncList[j](cookie);
                                Thread.Sleep(1200);
                                SetListViewItemValue(this.listView1, index, 7, "得到宝箱:" + fetchResult.Content[0].BoxGiftList[0].GiftName);
                                fetchBoxCount += fetchResult.Content[0].BoxGiftList.Length;
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        #endregion
                    }

                    Thread.Sleep(1000);

                    bool uploadWalkData = true;
                    float sc            = 0f;
                    if (configInfo.IsAutoUploadWalkData)
                    {
                        #region   走步数据

                        SetListViewItemValue(this.listView1, index, 7, "正在上传走步数据");
                        try
                        {
                            var downloadResult = PH.DownloadWalkData(id, cookie, cert);
                            if (downloadResult != null)
                            {
                                PajkWalkDataInfo today = null;
                                if (downloadResult.Content[0].walkDataInfos == null ||
                                    (today = downloadResult.Content[0].walkDataInfos.Find(
                                         match => match.walkDate == DateTime.Now.ToString("yyyyMMdd"))) == null)
                                {
                                    int stepCount = new Random((int)DateTime.Now.Ticks).Next(
                                        GlobalContext.CurrentConfigInfo.RandomMinStep,
                                        GlobalContext.CurrentConfigInfo.RandomMaxStep);
                                    sc         = stepCount;
                                    var result = PH.UploadWalkData(id, cookie, cert, stepCount);
                                    if (result.Content[0].Value)
                                    {
                                        SetListViewItemValue(this.listView1, index, 7, "成功上传走步" + stepCount + "!");
                                    }
                                    else
                                    {
                                        throw new Exception(result.Stat.Code.ToString());
                                    }
                                }
                                else
                                {
                                    sc = today.stepCount;
                                    SetListViewItemValue(this.listView1, index, 7, "今天已上传走步" + today.stepCount + "。");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "上传走步失败");
                            uploadWalkData = false;
                        }
                        #endregion
                    }

                    SetListViewItemValue(this.listView1, index, 7,
                                         string.Format("领取昨日奖励:{0},上传走步:{1},成功抢金:{2}个,得到宝箱:{3}个",
                                                       fetchYestodayReward?"成功":"失败",
                                                       uploadWalkData?sc.ToString():"失败",
                                                       grabGoldSuccess,
                                                       fetchBoxCount));
                }
                SetControlEnabled(this.toolStrip1, true);
            });
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 确定按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string cookie = base.GetControlText(this.textBoxCookie).Trim();

            if (cookie.Length < 1)
            {
                MessageBox.Show("请输入Cookie!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //登录
            this.CookieString = cookie;
            var    config = new ConfigStorage(GlobalContext.ConfigFileName);
            Thread thread = new Thread(() =>
            {
                try
                {
                    ChangeControlState(false);
                    this.MyUserInfo = GlobalContext.PH.GetUserInfo(cookie);

                    if (CertPath == null)
                    {
                        CookieInfo foundCookieInfo;
                        if ((foundCookieInfo = config.GetCookieInfoByUserId(this.MyUserInfo.id)) != null)
                        {
                            CertPath = foundCookieInfo.CertPath;
                        }
                    }

                    // 更新配置文件中的账户信息
                    config.UpdateCookieInfo(new CookieInfo()
                    {
                        Id       = this.MyUserInfo.id,
                        Name     = this.MyUserInfo.nick,
                        Cookie   = cookie,
                        CertPath = CertPath
                    });

                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    GlobalContext.MainForm.Output("登录失败:" + ex.Message);
                    this.CookieString = null;
                    this.CertPath     = null;
                    if (ex.Message.Contains("已过期"))
                    {
                        GlobalContext.Output("Cookie已过期,正在更新Cookie...");
                        string tk      = CookieUtil.GetCookieValue(cookie, "_tk");
                        var cookieInfo = config.GetCookieInfoByCookieUserToken(tk);
                        string id      = null;
                        if (cookieInfo == null || cookieInfo.Id == null)
                        {
                            var frm             = new FrmInputText();
                            frm.Text            = "请输入健康号";
                            frm.FormBorderStyle = FormBorderStyle.Sizable;
                            frm.StartPosition   = FormStartPosition.CenterScreen;
                            if (frm.ShowDialog() != DialogResult.OK)
                            {
                                ChangeControlState(true);
                                return;
                            }
                            id = frm.InputText.Trim();
                        }
                        else
                        {
                            id = cookieInfo.Id.ToString();
                        }

                        string certPath = null;
                        if (cookieInfo == null || !File.Exists(cookieInfo.CertPath))
                        {
                            var ofd         = new OpenFileDialog();
                            ofd.Title       = "请选择证书";
                            ofd.Filter      = "证书文件(*.pfx)|*.pfx";
                            ofd.FilterIndex = 1;
                            ofd.Multiselect = false;
                            if (ofd.ShowDialog() != DialogResult.OK)
                            {
                                ChangeControlState(true);
                                return;
                            }
                            certPath = ofd.FileName;
                        }
                        else
                        {
                            certPath = cookieInfo.CertPath;
                        }

                        try
                        {
                            var result = GlobalContext.PH.RenewUserTokenAndWebToken(id, cookie, certPath);
                            if (result.Stat.Code == 0)
                            {
                                string cookieNew = string.Empty;
                                cookieNew       += "_tk=" + System.Web.HttpUtility.UrlEncode(result.Content[0].Token) + ";"; // 必须进行urlencode
                                cookieNew       += "_wtk=" + result.Content[0].WebToken + ";";
                                SetControlText(this.textBoxCookie, cookieNew);

                                this.CertPath = certPath;

                                // 重新登录
                                buttonOk_Click(null, null);

                                //StringBuilder builder = new StringBuilder();
                                //builder.AppendLine("Uid:" + result.Content[0].Uid);
                                //builder.AppendLine("Tk:" + result.Content[0].Token);
                                //builder.AppendLine("Wtk:" + result.Content[0].WebToken);
                                //builder.AppendLine("Expire:" + result.Content[0].GetExpireTime());
                                //builder.AppendLine("LockTime:" + result.Content[0].LockTime);
                                //builder.AppendLine("请重新点击登录!");

                                //MsgBox.ShowInfo(builder.ToString(), "更新成功");
                            }
                        }
                        catch (Exception ex2)
                        {
                            MsgBox.ShowInfo("更新失败," + ex2.Message);
                        }
                        ChangeControlState(true);
                        return;
                    }
                    else if (ex.Message.Contains("设备上退出"))
                    {
                        config.RemoveCookieInfo(new CookieInfo {
                            Cookie = this.CookieString
                        });
                    }

                    MessageBox.Show("登录失败," + ex.Message);
                    ChangeControlState(true);
                }
                finally
                {
                    //重新读取历史Cookie信息
                    ConfigInfo configInfo        = config.GetConfigInfo();
                    GlobalContext.HistoryCookies = configInfo.HistoryCookies;
                }
            });

            thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 重新读取配置文件
 /// </summary>
 public static void RereadConfig()
 {
     CurrentConfigInfo = ConfigStorage.GetInstance().GetConfigInfo();
     HistoryCookies    = CurrentConfigInfo.HistoryCookies;
     IsTestMode        = CurrentConfigInfo.IsTestMode;
 }