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

  • 相关阅读:
    ASP.NET获取服务器信息
    检测到有潜在危险的 Request.Form 值错误解决办法
    修改sql server数据库逻辑文件名的语句
    遍历类的所有属性和根据属性名动态设置属性值
    JS三种编解码方式
    获取QQ群用户列表
    关于字符串类型相关的问题总结
    学习C++之父的最新姐妹作笔记1
    【转】 Uniode TO ANSI 转换函数封装
    添加工具栏图标按钮(转)
  • 原文地址:https://www.cnblogs.com/lockzy/p/11758990.html
Copyright © 2011-2022 走看看