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

  • 相关阅读:
    Spark中文指南(入门篇)-Spark编程模型(一)
    Scala入门学习笔记三--数组使用
    沃老师学生的成绩
    Codeforces Round #461 (Div. 2) DRobot Vacuum Cleaner
    Codeforces Round #461 (Div. 2) ABC
    Educational Codeforces Round 37 (Rated for Div. 2) ABC
    Codeforces Round #460 (Div. 2) D Substring
    Codeforces Round #460 (Div. 2) ABC
    中缀式转后缀式求表达式结果
    计算器——python正则表达式
  • 原文地址:https://www.cnblogs.com/lockzy/p/11758990.html
Copyright © 2011-2022 走看看