Ejemplo n.º 1
0
        private static void Begin(string mobile)
        {
            Console.WriteLine(mobile);
            var           m       = new MopData.Mop(mobile, url);
            List <string> temp    = new List <string>();
            List <string> headers = new List <string>();
            List <string> items   = new List <string>();

            headers.Add("手机号");
            items.Add(mobile);

            #region Base Info

            var res = Encoding.GetEncoding("GBK").GetString(m.GetBaseInfo().RawBytes);
            if (res.Contains("false"))
            {
                return;
            }
            var   userInfo = JsonConvert.DeserializeObject <UserBaseInfoJson.RootObject>(res);
            int[] arr      = { 0, 3, 4, 5, 6, 7, 10, 11, 14 };
            foreach (int i in arr)
            {
                headers.Add(userInfo.userBaseInfo.basicinfo[i].title);
                items.Add(userInfo.userBaseInfo.basicinfo[i].context);
            }

            #endregion

            #region Business Info

            headers.Add("业务信息");
            var businessInfo = Encoding.GetEncoding("GBK").GetString(m.GetBusinessInfo().RawBytes);
            var mc           = Regex.Matches(businessInfo, "secondvalue\":\"(.*?)\"");
            temp.Clear();
            foreach (Match match in mc)
            {
                temp.Add($"'{match.Groups[1]}'");
            }
            items.Add(string.Join(" ", temp.ToArray()));

            #endregion

            #region Consume Info

            var      consumeInfo = Encoding.GetEncoding("GBK").GetString(m.GetConsumeInfo().RawBytes);
            string[] MONTH       = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
            Match    ma;

            headers.Add("余额");
            ma = Regex.Match(consumeInfo, @"当前余额/(\d+\.\d+)");
            items.Add(ma.Success ? ma.Groups[1].Value : "0");

            for (int i = 1; i < 13; i++)
            {
                ma = Regex.Match(consumeInfo, $"{i} 月消费/(.*?)\"");
                headers.Add($"{MONTH[i - 1]}月消费");
                items.Add(ma.Success ? ma.Groups[1].Value : "0");

                ma = Regex.Match(consumeInfo, $@"201\d0?{i}/已使用优惠额度.*?/(\d+\.\d+) ");
                headers.Add($"{MONTH[i - 1]}月流量");
                items.Add(ma.Success ? ma.Groups[1].Value : "0");
            }

            #endregion

            #region Recommend Info

            headers.Add("推荐信息");
            var recommendInfo = Encoding.GetEncoding("GBK").GetString(m.GetRecomendInfo().RawBytes);
            mc = Regex.Matches(recommendInfo, "prog_name\":\"(.*?)\"");
            temp.Clear();
            foreach (Match match in mc)
            {
                var name = match.Groups[1].ToString();
                if (!string.IsNullOrEmpty(name))
                {
                    temp.Add(name);
                }
            }
            items.Add(string.Join(" ", temp.ToArray()));

            headers.Add("终端类型");
            ma = Regex.Match(recommendInfo, "terminal_type\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("绑定终端");
            ma = Regex.Match(recommendInfo, "is_bound_terminal\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("换机时长(月)");
            ma = Regex.Match(recommendInfo, "terminal_change_time\":\"(.*?)\"");
            items.Add($"{ma.Groups[1].Value}");

            headers.Add("是否办理宽带");
            ma = Regex.Match(recommendInfo, "is_broad_band\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否实名用户");
            ma = Regex.Match(recommendInfo, "is_realname_user\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否智能机用户");
            ma = Regex.Match(recommendInfo, "is_sphone_user\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value.Contains("是") ? "是" : "否");

            headers.Add("是否USIM卡用户");
            ma = Regex.Match(recommendInfo, "is_usim_user\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否4G终端");
            ma = Regex.Match(recommendInfo, "is_4g_client\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否4G套餐");
            ma = Regex.Match(recommendInfo, "is_4g_base_product\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否4G客户");
            ma = Regex.Match(recommendInfo, "is_4g_client\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否VoTLE终端用户");
            ma = Regex.Match(recommendInfo, "is_votle_terminal\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("是否开通VoTLE服务");
            ma = Regex.Match(recommendInfo, "is_votle_function\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value.Contains("9") ? "未开通" : ma.Groups[1].Value);

            headers.Add("是否宽带用户");
            ma = Regex.Match(recommendInfo, "is_broad_band\":\"(.*?)\"");
            items.Add(ma.Groups[1].Value);

            headers.Add("卡槽类型");
            ma = Regex.Match(recommendInfo, "is_double_card_slot\":\"(.*?)\"");
            string str = ma.Groups[1].Value;
            switch (str)
            {
            case "0":
                str = "非双槽客户";
                break;

            case "1":
                str = "双槽双卡移动客户";
                break;

            case "2":
                str = "双槽双卡移动异网客户";
                break;

            case "3":
                str = "双槽单卡移动客户";
                break;
            }
            items.Add(str);

            #endregion

            if (!first)
            {
                sw.WriteLine(string.Join("\t", headers));
                first = true;
            }
            lock (sw)
            {
                sw.WriteLine(string.Join("\t", items));
                sw.Flush();
            }
        }
Ejemplo n.º 2
0
        private void btn_begin_Click(object sender, EventArgs e)
        {
            Sql = new SqliteHelper();
            progressBar1.Maximum = File.ReadAllLines(txt_load.Text).Length;

            Task.Factory.StartNew(() =>
            {
                int num = 0;
                foreach (var mobile in File.ReadAllLines(txt_load.Text))
                {
                    while (num > 10)
                    {
                        Thread.Sleep(1000);
                    }
                    Invoke(new Action(() =>
                    {
                        num++;
                        lab_num.Text = num.ToString();
                    }));
                    Task.Factory.StartNew(() =>
                    {
                        var m = new Mop(mobile, url);
                        using (var cmd = new SQLiteCommand(Sql.Conn))
                        {
                            cmd.CommandText = $"SELECT * FROM MobileInfo WHERE 手机号={mobile}";
                            var reader      = cmd.ExecuteReader();
                            if (!reader.HasRows)
                            {
                                using (var cmd1 = new SQLiteCommand(Sql.Conn))
                                {
                                    cmd1.CommandText = $"INSERT INTO MobileInfo (手机号) VALUES({mobile})";
                                    cmd1.ExecuteNonQuery();
                                }
                            }
                        }

                        string res = Encoding.GetEncoding("GBK").GetString(m.GetBaseInfo().RawBytes);
                        if (res.Contains("false"))
                        {
                            return;
                        }
                        var userInfo =
                            JsonConvert.DeserializeObject <UserBaseInfoJson.RootObject>(
                                res);
                        using (var cmd = new SQLiteCommand(Sql.Conn))
                        {
                            //开打时间 出账类型 集团信息 最晚捆绑时间
                            cmd.CommandText =
                                $"UPDATE MobileInfo SET " +
                                $"姓名='{userInfo.userBaseInfo.basicinfo[0].context}'," +
                                $"归属='{userInfo.userBaseInfo.basicinfo[3].context}'," +
                                $"开打时间='{userInfo.userBaseInfo.basicinfo[4].context}'," +
                                $"在用套餐='{userInfo.userBaseInfo.basicinfo[5].context}'," +
                                $"用户状态='{userInfo.userBaseInfo.basicinfo[6].context}'," +
                                $"出账类型='{userInfo.userBaseInfo.basicinfo[7].context}'," +
                                $"集团信息='{userInfo.userBaseInfo.basicinfo[11].context}'," +
                                $"最晚捆绑时间='{userInfo.userBaseInfo.basicinfo[14].context}'" +
                                $"  WHERE 手机号={mobile}";
                            cmd.ExecuteNonQuery();
                        }


                        var businessInfo = Encoding.GetEncoding("GBK").GetString(m.GetBusinessInfo().RawBytes);
                        var mc           = Regex.Matches(businessInfo, "secondvalue\":\"(.*?)\"");
                        var info         = new List <string>();
                        foreach (Match match in mc)
                        {
                            info.Add(match.Groups[1].ToString());
                        }
                        using (var cmd = new SQLiteCommand(Sql.Conn))
                        {
                            cmd.CommandText =
                                $"UPDATE MobileInfo SET 业务信息='{string.Join("\n", info.ToArray())}' WHERE 手机号={mobile}";
                            cmd.ExecuteNonQuery();
                        }



                        var consumeInfo = Encoding.GetEncoding("GBK").GetString(m.GetConsumeInfo().RawBytes);
                        mc             = Regex.Matches(consumeInfo, "secondvalue\":\"(.*?)\"");
                        string[] MONTH = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
                        foreach (Match match in mc)
                        {
                            var str = match.Groups[1].Value;
                            var m1  = Regex.Match(str, @"(\d+) 月消费/(\d+\.\d+)");
                            if (m1.Success)
                            {
                                var month = Convert.ToInt32(m1.Groups[1].Value);
                                using (var cmd = new SQLiteCommand(Sql.Conn))
                                {
                                    cmd.CommandText =
                                        $"UPDATE MobileInfo SET {MONTH[month - 1]}月消费={m1.Groups[2].Value} WHERE 手机号={mobile}";
                                    cmd.ExecuteNonQuery();
                                }

                                continue;
                            }
                            //secondvalue=201706/已使用优惠额度/2097.15 MB
                            m1 = Regex.Match(str, @"201\d(\d+)/已使用优惠额度.*?/(\d+\.\d+) ");
                            if (m1.Success)
                            {
                                var month = Convert.ToInt32(m1.Groups[1].Value);
                                using (var cmd = new SQLiteCommand(Sql.Conn))
                                {
                                    cmd.CommandText =
                                        $"UPDATE MobileInfo SET {MONTH[month - 1]}月流量={m1.Groups[2].Value} WHERE 手机号={mobile}";
                                    cmd.ExecuteNonQuery();
                                }
                            }
                        }


                        var recommendInfo = Encoding.GetEncoding("GBK").GetString(m.GetRecomendInfo().RawBytes);
                        mc   = Regex.Matches(recommendInfo, "prog_name\":\"(.*?)\"");
                        info = new List <string>();
                        foreach (Match match in mc)
                        {
                            var name = match.Groups[1].ToString();
                            if (!string.IsNullOrEmpty(name))
                            {
                                info.Add(name);
                            }
                        }
                        using (var cmd = new SQLiteCommand(Sql.Conn))
                        {
                            cmd.CommandText =
                                $"UPDATE MobileInfo SET 推荐信息='{string.Join("\n", info.ToArray())}' WHERE 手机号={mobile}";
                            cmd.ExecuteNonQuery();
                        }
                    }).ContinueWith((task) =>
                    {
                        Invoke(new Action(() =>
                        {
                            num--;
                            progressBar1.PerformStep();
                            lab_pro.Text = $@"{progressBar1.Value} / {progressBar1.Maximum}";
                        }));
                    });
                }
            });
        }