zoukankan      html  css  js  c++  java
  • 微信手机号发送验证码

    #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

  • 相关阅读:
    数据结构-串的堆分配存储
    ServerSocket
    Java-坦克大战
    Java-输入输出流
    MyEclipse 快捷键
    数据结构-串的定长顺序存储
    我的软考资料集合
    软考中级软件设计师考试大纲
    2016年第一季度阅读书目
    中国大陆开源镜像网站汇总
  • 原文地址:https://www.cnblogs.com/lockzy/p/11758990.html
Copyright © 2011-2022 走看看