Exemplo n.º 1
0
        /// <summary>
        /// 兑换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 兑换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count < 1)
            {
                return;
            }

            var item     = this.listView1.SelectedItems[0];
            var itemInfo = item.Tag as PajkGetDepotResultItem;

            if (itemInfo.NeedNum > itemInfo.OwnNum)
            {
                MsgBox.ShowInfo("碎片个数不够,无法兑换!");
                return;
            }

            if (MsgBox.ShowOkCancel("确定要兑换-" + itemInfo.SpuTitle + "?", "提示") != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            DoTask(() =>
            {
                ProductInfo info = new ProductInfo();
                info.name        = itemInfo.SpuTitle;
                info.id          = itemInfo.SkuId;

                var frm          = new FrmCreateOrder(info);
                frm.CreateOrder += (o, args) => {
                    var obj = o as FrmCreateOrder;
                    GlobalContext.Output("正在下单...");
                    PH.CreateOrder2(base.MyCookie, itemInfo.SkuId.ToString(), obj.SelectedMobile, obj.SelectedAddress);
                    GlobalContext.Output("已下单,详情请在【订单信息】中查询!");
                };
                frm.ShowDialog();
            }, "兑换失败");
        }
Exemplo n.º 2
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();
        }