예제 #1
0
        public static Result SendMail(string mailAddress, string dateTime)
        {
            Result result = new Result();

            try
            {
                //实例化一个发送邮件类。
                MailMessage mailMessage = new MailMessage();
                //发件人邮箱地址,方法重载不同,可以根据需求自行选择。
                string platformName = ParameterAPI.GetConfig("PlatformName").ConfigValue;
                string sender       = ParameterAPI.GetConfig("Sender").ConfigValue;
                mailMessage.From = new MailAddress(sender, platformName);
                //收件人邮箱地址。
                mailMessage.To.Add(mailAddress);
                mailMessage.SubjectEncoding = Encoding.UTF8; //标题格式为UTF8
                                                             //邮件标题。
                mailMessage.Subject = platformName;
                //邮件内容。
                string registerBody = ParameterAPI.GetConfig("RegisterBody").ConfigValue;
                mailMessage.Body = registerBody;//"请点击以下链接确认注册\r\n http://172.20.8.24:80/BLL/Login/Hand.aspx" + "?";
                string content = "mailAddress=" + mailAddress + "&dateTime=" + dateTime;
                mailMessage.Body += Common.Encrypt(content);
                //实例化一个SmtpClient类。
                SmtpClient client = new SmtpClient();
                //在这里我使用的是qq邮箱,所以是smtp.qq.com,如果你使用的是126邮箱,那么就是smtp.126.com。
                string mailHost = ParameterAPI.GetConfig("MailHost").ConfigValue;
                client.Host = mailHost;
                //使用安全加密连接。
                client.EnableSsl = true;
                //不和请求一块发送。
                client.Port = int.Parse(ParameterAPI.GetConfig("Port").ConfigValue);
                client.UseDefaultCredentials = false;
                //验证发件人身份(发件人的邮箱,邮箱里的生成授权码);
                string pwd = ParameterAPI.GetConfig("SendPWD").ConfigValue;
                client.Credentials = new NetworkCredential(sender, pwd);
                //发送
                client.Send(mailMessage);
                result.IsOK = true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(Common)).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 构造支付请求数据
        /// </summary>
        /// <returns>请求数据集</returns>
        public static AlipayTradePrecreateContentBuilder BuildPrecreateContent(string account, string fileCoverID)
        {
            //线上联调时,请输入真实的外部订单号。
            //string out_trade_no = "";
            //if (String.IsNullOrEmpty(WIDout_request_no.Text.Trim()))
            AlipayTradePrecreateContentBuilder builder = new AlipayTradePrecreateContentBuilder();

            //{
            try
            {
                string out_trade_no = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "0000" + (new Random()).Next(1, 10000).ToString();


                //收款账号
                builder.seller_id = Config.pid;
                //订单编号
                builder.out_trade_no = out_trade_no;

                PCBEntities pCBEntities = new PCBEntities();
                Guid        g           = new Guid(fileCoverID);

                //订单总金额

                var pcbfilecoverTB = pCBEntities.PCB_FileCoverTB.FirstOrDefault(p => p.FileCoverID == g);
                if (pcbfilecoverTB != null)
                {
                    builder.total_amount = pcbfilecoverTB.Price;
                }
                else
                {
                    throw new ArgumentNullException("without the data of fileCover");
                }
                //参与优惠计算的金额
                //builder.discountable_amount = "";
                //不参与优惠计算的金额
                //builder.undiscountable_amount = "";
                //订单名称
                builder.subject = ParameterAPI.GetConfig("Subject").ConfigValue;// "xxxx";// WIDsubject.Text.Trim();
                //自定义超时时间
                builder.timeout_express = ParameterAPI.GetConfig("Timeout").ConfigValue;
                //订单描述
                builder.body = ParameterAPI.GetConfig("BuilderBody").ConfigValue;
                //门店编号,很重要的参数,可以用作之后的营销
                builder.store_id = ParameterAPI.GetConfig("StoreID").ConfigValue;
                //操作员编号,很重要的参数,可以用作之后的营销
                builder.operator_id = ParameterAPI.GetConfig("OperatorID").ConfigValue;

                //传入商品信息详情
                List <GoodsInfo> gList = new List <GoodsInfo>();
                GoodsInfo        goods = new GoodsInfo();
                goods.goods_id   = "goods id";
                goods.goods_name = "goods name";
                goods.price      = "0.01";
                goods.quantity   = "1";
                gList.Add(goods);
                builder.goods_detail = gList;

                //系统商接入可以填此参数用作返佣
                //ExtendParams exParam = new ExtendParams();
                //exParam.sysServiceProviderId = "20880000000000";
                //builder.extendParams = exParam;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message);
            }


            return(builder);
        }
예제 #3
0
        /// <summary>
        /// 根据路径获取文件
        /// </summary>
        /// <param name="fileDir">文件目录</param>
        /// <param name="rootPath">根目录</param>
        /// <param name="dt">表</param>
        /// <returns></returns>
        public static Result GetFileList(string subDir, string rootPath, ref DataTable dt)
        {
            Result result = new Result();

            try
            {
                result.IsOK = true;
                string fileDir = "";
                if (string.IsNullOrEmpty(subDir))
                {
                    fileDir = rootPath.TrimEnd('\\') + "\\";
                }
                else
                {
                    fileDir = rootPath.TrimEnd('\\') + "\\" + subDir.TrimEnd('\\') + "\\";
                }

                string[] dirs  = Directory.GetDirectories(fileDir);
                string[] files = Directory.GetFiles(fileDir);
                // string dir = "ClientUpdateFiles";
                //string url = HttpContext.Current.Request.Url.AbsoluteUri;
                //  int length = url.IndexOf('/', 7);
                //string fileUrl = url.Substring(0, length) + @"/" + dir + @"/"; //文件的下载地址
                string fileUrl = ParameterAPI.GetConfig("ClientURLDir").ConfigValue;// "http://172.20.8.24/TIS.ClientUpdateFile";


                foreach (string item in files)
                {
                    DataRow dr = dt.NewRow();
                    //  dr["FileName"] = Path.GetFileName(item);
                    //   dr["FileSize"] = new FileInfo(fileDir + Path.GetFileName(item)).Length;
                    string dir = ParameterAPI.GetConfig("ClientDir").ConfigValue;
                    dr["FilePath"] = Path.GetFullPath(item).Remove(0, dir.Length - 1);//string.IsNullOrEmpty(subDir) ? "" : subDir.TrimEnd('\\') + "\\";// fileDir.Substring(fileDir.IndexOf(rootPath) + rootPath.Length, fileDir.Length - rootPath.Length);//.TrimStart(rootPath.ToCharArray());
                    string p = Path.GetFullPath(item);
                    // LogHelper.Write("xxx"+p, LogHelper.LogMessageType.Error, typeof(ClientUpdateWebService));
                    if (File.Exists(p))
                    {
                        File.SetAttributes(p, FileAttributes.Normal);//将只读文件设置成正常属性
                    }
                    // dr["FileMD5"] = GetMD5Content(p);
                    if (string.IsNullOrEmpty(subDir))
                    {
                        dr["FileURL"] = fileUrl + "/" + Path.GetFileName(item);
                    }
                    else
                    {
                        dr["FileURL"] = fileUrl + "/" + (subDir.TrimEnd('/') + "/").Replace("\\", "/") + Path.GetFileName(item);
                    }

                    dt.Rows.Add(dr);
                }
                foreach (string item in dirs)
                {
                    string str = item.Substring(item.IndexOf(rootPath) + rootPath.Length, item.Length - rootPath.Length);
                    GetFileList(str, rootPath, ref dt);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(Common)).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }