• 微信手机号发送验证码


    #region 微信用户手机号发送验证码
    /// <summary>
    /// 微信用户手机号发送验证码
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [Route("WxPhoneCheck")]
    public ApiResultModel WxPhoneCheck([FromBody]WxUptPhoneDTO wxUpt)
    {
    ApiResultModel apiResult = new ApiResultModel();

    try
    {
    #region 判断手机号是否唯一
    var UserMobileModel = db.User_Index.Where(m => m.Mobile == wxUpt.Mobile && m.IsDelete == 0 && m.UserType == UserTypeDict.Client.Value).FirstOrDefault();
    if (UserMobileModel != null && UserMobileModel.DetailsStates == 1)
    {
    apiResult.Message = "该手机号已注册,请更换其它手机号";
    apiResult.Success = 0;
    return apiResult;
    }
    #endregion

    var Contents = RandomHelper.MakeCode(4);
    Dictionary<string, string> dictionary = new Dictionary<string, string>();
    dictionary.Add("Mobile", wxUpt.Mobile);
    dictionary.Add("Content", Contents);
    var result2 = db.Sys_SMSrecord.Add(new Sys_SMSrecord()
    {
    ID = DataBaseHelper.CreateID(),
    UID = wxUpt.uid,
    Phone = wxUpt.Mobile,
    VerificationCode = Contents,
    CreateBy = wxUpt.uid,
    CreateTime = DateTime.Now,
    IsDelete = 0
    });
    if (db.SaveChanges() > 0)
    {
    #region 将验证码存放Redis
    using (IRedisClient Redis = RedisManager.GetClient())
    {
    //放入内存
    string phone = wxUpt.Mobile;
    Redis.Remove(phone);//将以前的手机号及验证码信息删除
    string value = Contents;
    Redis.Set<string>(phone, value);//将手机号以及验证码存放Redis
    Redis.ExpireEntryAt(phone, DateTime.Now.AddMinutes(10));//10分钟过期
    //Redis.Save(); //保存到硬盘
    }
    #endregion

    var resultarrea = ConfigurationManager.AppSettings["Api_SMS"].ToString();
    var result = HttpHelper.HttpGet(resultarrea + "/Register", dictionary);
    //将其返回的Json 进行加密放到Redis中
    var smsResult = JsonConvert.DeserializeObject<ApiResultModel>(result);
    if (smsResult.Success == 1)
    {
    apiResult.Message = "验证码发送成功";
    apiResult.Success = 1;
    apiResult.Data = dictionary;
    }
    else
    {
    apiResult.Message = smsResult.Message;
    apiResult.Success = 0;
    }
    }
    else
    {
    apiResult.Message = "请重新请求发送";
    apiResult.Success = 0;
    apiResult.ErrorCode = 2;
    }
    }
    catch (Exception ex)
    {
    apiResult.Message = "";
    apiResult.Success = 0;
    apiResult.DebugMessage = ex.Message;
    }

    return apiResult;
    }
    #endregion

  • 相关阅读:
    (二)、一步一步学GTK+之窗口
    phpcms v9 评论的bug.
    为discuz x2.5添加播放附件(mp4)的方法
    code::blocks + C + lua 编译环境
    C语言从声卡录音的一个demo
    泛型集合(.NET 2.0)
    VS2008对ASP.NET引用的外部JS文件不能调试
    for循环和foreach
    CSS之DIV上下左右居中
    GridView控件相关(来自互联网)
  • 原文地址:https://www.cnblogs.com/lockzy/p/11758990.html
Copyright © 2020-2023  润新知