/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Tuple <bool, string> GetQiNiuHost()
        {
            try
            {
                var cacheToken = CacheHelper.Get <string> ("qiniuhostkey");
                var host       = cacheToken.IsNullOrEmpty() ? _redisCommonService.Get <string> ("qiniuhostkey") : cacheToken;
                if (!host.IsNullOrEmpty())
                {
                    return(new Tuple <bool, string> (true, host));
                }
                var result = Helper.HttpRequestHelper.GateWaySync <Result <String> > ("ps.qiniu.host.get", new Dictionary <string, dynamic> ());
                if (result.IsSuccess)
                {
                    CacheHelper.Add("qiniuhostkey", result.Data.Trim('"'), 1440);
                    _redisCommonService.Set("qiniuhostkey", result.Data.Trim('"'), TimeSpan.FromDays(1));
                    return(new Tuple <bool, string> (true, result.Data.Trim('"')));
                }

                return(new Tuple <bool, string> (false, ""));
            }
            catch (Exception e)
            {
                return(new Tuple <bool, string> (false, e.Message));
            }
        }
Exemple #2
0
        private Tuple <bool, string> Send(string phoneNumber, string smsTempCode, string smsCodeType, ESmsType type, string param, string code = "")
        {
            if (string.IsNullOrEmpty(phoneNumber))
            {
                return(new Tuple <bool, string>(false, "手机号码为空"));
            }

            if (type == ESmsType.验证码)
            {
                //手机号码加验证码类型
                var storeKey = SmsCode_Store_PreKey + phoneNumber + "_" + smsCodeType;//sms_13000000000_6

                //写入redis
                var result = _redisCommonService.Set <string>(storeKey, code, TimeSpan.FromMinutes(10));
                if (!result)
                {
                    //记录日志
                    return(new Tuple <bool, string>(false, "写入缓存失败"));
                }
            }

            try
            {
                var dictionary = new Dictionary <string, dynamic> {
                    { "phoneNumber", phoneNumber },
                    { "smsTempCode", smsTempCode },
                    { "code", code },
                    { "param", param }
                };
                var sendResult = Helper.HttpRequestHelper.GateWaySync <Result>("ps.alidayu.send", dictionary);

                if (sendResult.IsSuccess)
                {
                    return(new Tuple <bool, string>(true, ""));
                }

                return(new Tuple <bool, string>(false, sendResult.ErrorMessage));
            }
            catch (Exception e)
            {
                return(new Tuple <bool, string>(false, e.Message));
            }
        }