コード例 #1
0
ファイル: RegisterService.cs プロジェクト: tyotann/mailSpider
        public static RegisterInfo getRegisterInfo()
        {
            if (registerInfo.VersionType == null)
            {
                registerInfo.VersionType = "UN_SUPPORT";

                try
                {
                    if (File.Exists(SystemUtils.getCurrentPath() + "\\license.info"))
                    {
                        //0:company_name,1:end_date,2:version_type
                        String[] info = FileUtils.read("license.info").Split('#');

                        registerInfo.CompanyName = info[0];

                        registerInfo.EndDate = info[1];

                        String keyData = FileUtils.read("license.key");

                        if (keyData != null)
                        {
                            HardDiskInfo hardDiskInfo = HardInfoUtils.getDiskInfo(0);

                            if (RegisterService.verify(keyData, RegisterService.getRegisterString(registerInfo.CompanyName, "1900-01-01", registerInfo.EndDate, HardInfoUtils.getCpuSerialNumber(), hardDiskInfo.SerialNumber, Convert.ToString(hardDiskInfo.Capacity), info[2])))
                            {
                                String newDate = DateUtils.getRealSysDate();

                                if (newDate.Length < 10)
                                {
                                    MessageBox.Show("没有取得时间,请在保证网络能连接情况下重启该程序");
                                    registerInfo.VersionType = "CLOSE";
                                }

                                //判断日期
                                DateTime nowDT = Convert.ToDateTime(newDate.Substring(0, 10));
                                DateTime end   = Convert.ToDateTime(registerInfo.EndDate);

                                if (nowDT.Subtract(end).TotalDays <= 0)
                                {
                                    registerInfo.VersionType = info[2];
                                }
                                else
                                {
                                    MessageBox.Show("您的授权日期:" + end + "已过期,~请与销售联系购买新的许可");
                                    registerInfo.VersionType = "CLOSE";
                                }
                            }
                            else
                            {
                                MessageBox.Show("序列号不一致~请与销售联系");
                                registerInfo.VersionType = "CLOSE";
                            }
                        }
                        else
                        {
                            MessageBox.Show("当前目录下无法找到注册文件license.key,请联系销售购买获得序列号!");
                            registerInfo.VersionType = "CLOSE";
                        }
                    }
                }
                catch { MessageBox.Show("检查软件许可时出现异常,请重新启动软件"); }
            }


            return(registerInfo);
        }
コード例 #2
0
ファイル: RegisterForm.cs プロジェクト: tyotann/mailSpider
        private void button1_Click(object sender, EventArgs e)
        {
            if ("".Equals(tb_companyName.Text.Trim()))
            {
                MessageBox.Show("公司名不能为空");
                return;
            }

            if (tb_companyName.Text.Trim().IndexOf("@") > -1 || tb_companyName.Text.Trim().IndexOf("#") > -1 || tb_companyName.Text.Trim().IndexOf("|") > -1)
            {
                MessageBox.Show("公司名不能为特殊字符");
                return;
            }

            if ("".Equals(tb_mailName.Text.Trim()))
            {
                MessageBox.Show("邮箱名与电话不能都为空,后续软件升级信息将通过邮箱发送至您~");
                return;
            }

            if (tb_mailName.Text.Trim().Length > 40)
            {
                MessageBox.Show("邮箱名太长,不符合规范");
                return;
            }

            if (tb_companyName.Text.Trim().IndexOf("#") > -1)
            {
                MessageBox.Show("邮箱名不能含特殊字符#");
                return;
            }

            if ("".Equals(tb_telName.Text.Trim()))
            {
                MessageBox.Show("电话不能都为空");
                return;
            }
            if (tb_telName.Text.Trim().IndexOf("#") > -1)
            {
                MessageBox.Show("电话不能含特殊字符#");
                return;
            }

            if (tb_telName.Text.Trim().Length > 30)
            {
                MessageBox.Show("电话太长,不符合规范");
                return;
            }

            String key = "";

            try
            {
                String versionType = chk_isFull.Checked ? "FULL" : "TRIAL";

                String companyName = tb_companyName.Text.Trim();

                String mail = tb_mailName.Text.Trim();

                String tel = tb_telName.Text.Trim();

                String startDate = "1900-01-01";

                String endDate = null;

                //试用期1天
                if (chk_isFull.Checked)
                {
                    endDate = "2020-01-01";
                }
                else
                {
                    endDate = Convert.ToDateTime(DateUtils.getRealSysDate().Substring(0, 10)).AddDays(1).ToString("yyyy-MM-dd");
                }

                //写入注册信息
                FileUtils.write("license.info", companyName + "#" + endDate + "#" + versionType + "#" + mail + "#" + tel);

                HardDiskInfo hardDiskInfo = HardInfoUtils.getDiskInfo(0);

                key = RegisterService.encode(RegisterService.getRegisterString(companyName, startDate, endDate, HardInfoUtils.getCpuSerialNumber(), hardDiskInfo.SerialNumber, Convert.ToString(hardDiskInfo.Capacity), versionType));

                //发送邮件
                {
                    SmtpClient client = new SmtpClient("smtp.263.net", 25);
                    client.EnableSsl   = false;
                    client.Credentials = new System.Net.NetworkCredential("sta_sales10", "911911ds");

                    String mailContent = "邮箱:" + mail + Environment.NewLine;
                    mailContent += "电话:" + tel + Environment.NewLine;
                    mailContent += "注册信息:" + key;

                    MailMessage mailMessage = new MailMessage("*****@*****.**", "*****@*****.**", tb_companyName.Text, mailContent);

                    //设置邮件的格式
                    mailMessage.IsBodyHtml = false;

                    //设置邮件的发送级别
                    mailMessage.Priority = MailPriority.Normal;
                    //FileUtils.write("license.sign", key);
                    client.Send(mailMessage);
                }

                MessageBox.Show("申请提交成功");
            }
            catch (Exception ex)
            {
                FileUtils.write("license.sign", key);
                MessageBox.Show("申请提交失败:" + ex.Message);
            }

            this.Close();
        }