Exemple #1
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        public bool SendVerificationCode(string VerificationCode, string phoneNumber)
        {
            // 短信模板ID,需要在短信应用中申请
            int templateId = 170466;

            try
            {
                SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
                var             result  = ssender.sendWithParam("86", phoneNumber,
                                                                templateId, new[] { VerificationCode }, "", "", "");
                if (result.result == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (JSONException e)
            {
                RCLog.Error(this, e.ToString());
            }
            catch (HTTPException e)
            {
                RCLog.Error(this, e.ToString());
            }
            catch (Exception e)
            {
                RCLog.Error(this, e.ToString());
            }
            return(false);
        }
Exemple #2
0
        public static string UploadImage(IFormFile file, IHostingEnvironment _env)
        {
            if (file == null)
            {
                return("");
            }
            //判断是否是图片类型
            List <string> imgtypelist = new List <string> {
                "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp"
            };

            if (imgtypelist.FindIndex(x => x == file.ContentType) == -1)
            {
                //return "请上传一张图片!";
                return("");
            }
            string filepath = _env.WebRootPath + "\\userfile\\images";
            string imgname  = DateTime.Now.Ticks.ToString() + Path.GetExtension(file.FileName);

            string fullpath = Path.Combine(filepath, imgname);

            try
            {
                if (!Directory.Exists(filepath))
                {
                    Directory.CreateDirectory(filepath);
                }
                if (file != null)
                {
                    using (FileStream fs = new FileStream(fullpath, FileMode.Create))
                    {
                        //var hash = System.Security.Cryptography.HashAlgorithm.Create();
                        //byte[] hashByte_1 = hash.ComputeHash(fs);
                        file.CopyTo(fs);
                    }
                }
            }
            catch (Exception ex)
            {
                RCLog.Error(nameof(FileHelper), "上传图片失败");
                return("");
            }

            return("/userfile/images/" + imgname);
        }
Exemple #3
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="context"></param>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public bool SendVerificationCode2(string[] context, string phoneNumber)
        {
            var template = GetSMSAppTemplate(SMSTemplateType.verification);

            try
            {
                SmsSingleSender ssender = new SmsSingleSender(Convert.ToInt32(template.Appid), template.Appkey);
                var             result  = ssender.sendWithParam("86", phoneNumber, Convert.ToInt32(template.TemplateId), context, "", "", "");

                Console.WriteLine(result);
                var        lastSendSMSLogs = _context.SendSMSLogs.Where(x => x.Year == DateTime.Now.Year && x.Month == DateTime.Now.Month).OrderByDescending(x => x.CreateTime).FirstOrDefault();
                SendSMSLog log             = new SendSMSLog()
                {
                    Appid              = template.Appid,
                    SMSAppTemplateId   = template.TemplateId,
                    Month              = DateTime.Now.Month,
                    Year               = DateTime.Now.Year,
                    Content            = string.Join(",", context),
                    phoneNumbers       = phoneNumber,
                    QuantityBeforeSend = lastSendSMSLogs == null ? 0 : lastSendSMSLogs.QuantityAfterSend,
                    QuantityAfterSend  = lastSendSMSLogs == null ? 1 : lastSendSMSLogs.QuantityAfterSend + 1,
                    CreateTime         = DateTime.Now
                };
                _context.Add(log);
                _context.SaveChanges();
                return(true);
            }
            catch (JSONException e)
            {
                RCLog.Error(this, e.ToString());
            }
            catch (HTTPException e)
            {
                RCLog.Error(this, e.ToString());
            }
            catch (Exception e)
            {
                RCLog.Error(this, e.ToString());
            }
            return(false);
        }