public FuncResult Handler(string userCode, string userPwd, string mobileno, string smsContent)
 {
     try
     {
         Tsms_Thirdparty daThirdparty = null;
         string          error;
         if (!SmsUtils.CheckUserCode(userCode, userPwd, mobileno, out daThirdparty, out error))
         {
             return(FuncResult.FailResult(error));
         }
         ISmsProvider sms = SmsServiceFactory.GetSmsServiceByChannel(daThirdparty.Channel_Id, out error);
         if (sms == null)
         {
             return(FuncResult.FailResult(error));
         }
         SmsServiceProvider provider = new SmsServiceProvider(sms, daThirdparty.Appid, mobileno, smsContent);
         if (!provider.Send())
         {
             return(FuncResult.FailResult(provider.PromptInfo.CustomMessage));
         }
         return(FuncResult.SuccessResult());
     }
     catch (Exception ex)
     {
         Log.Error("handler异常", ex);
         return(FuncResult.FailResult(ex.Message));
     }
 }
Example #2
0
        public FuncResult <ThirdPartyLoginResult> Login(int clientSource, string clientSys, string deviceId, string clientVer, string ipAddress, string session_id, int appId)
        {
            if (this._user == null)
            {
                return(FuncResult.FailResult <ThirdPartyLoginResult>("未注册", 404));
            }
            LoginProvider localLogin = new LoginProvider(_user.UserCode, null, "basic");

            localLogin.IgnorePassword = true;
            if (!localLogin.Login(clientSource, clientSys, deviceId, ipAddress, session_id, clientVer, appId))
            {
                return(FuncResult.FailResult <ThirdPartyLoginResult>(localLogin.PromptInfo.CustomMessage, (int)localLogin.PromptInfo.ResultType));
            }
            var data = new ThirdPartyLoginResult
            {
                Token          = localLogin.Token,
                UserCode       = _user.UserCode,
                Expires        = localLogin.OAuthUser.Expire_In,
                RefreshExpires = localLogin.OAuthUser.Refresh_Expire_In,
                RefreshToken   = localLogin.OAuthUser.Refresh_Token,
                Openid         = localLogin.OAuthUser.Open_Id
            };

            return(FuncResult.SuccessResult(data));
        }
        private static FuncResult <int?> GetIntroducerId(string refereeCode)
        {
            if (string.IsNullOrEmpty(refereeCode) && AppConfig.RegisterRefereeRequired)
            {
                return(FuncResult.FailResult <int?>("必须填写推荐人"));
            }

            if (string.IsNullOrEmpty(refereeCode))
            {
                return(FuncResult.SuccessResult(default(int?)));
            }
            var   fac         = UserModuleFactory.GetUserModuleInstance();
            IUser refereeUser = null;

            if (refereeCode.StartsWith("U"))
            {
                refereeUser = fac?.GetUserByCode(refereeCode);
            }
            else
            {
                int userid;
                if (!int.TryParse(refereeCode.Replace("U", ""), out userid))
                {
                    return(FuncResult.FailResult <int?>("无效的邀请码"));
                }
                refereeUser = fac?.GetUserByID(userid);
            }
            if (refereeUser == null)
            {
                return(FuncResult.FailResult <int?>("推荐人账号不存在"));
            }
            return(FuncResult.SuccessResult(refereeUser?.UserId));
        }
Example #4
0
        public FuncResult <ThirdPartyLoginResult> Login(Winner.WebApi.Contract.ApiPackage package, string ipAddress, string session_id, int appId)
        {
            //ThirdParty、OpenId
            bool           isExist = false;
            int            userId  = 0;
            Tnet_User_Auth daAuth  = new Tnet_User_Auth();

            if (!(isExist = daAuth.SelectByThirdparty_OpenId((int)this._thirdParty, this._openID)))
            {
                //if not exist
                //add one
                userId            = GetNewUserId();
                daAuth.Open_Id    = this._openID;
                daAuth.Status     = 1;
                daAuth.Thirdparty = (int)this._thirdParty;
                daAuth.User_Id    = userId;
                if (!daAuth.Insert())
                {
                    //Alert("登录失败,保存登录信息异常");
                    return(FuncResult.FailResult <ThirdPartyLoginResult>("登录失败,保存登录信息异常"));
                }
            }
            else
            {
                userId = daAuth.User_Id;
            }
            if (!isExist)
            {
                return(FuncResult.SuccessResult((ThirdPartyLoginResult)null));
            }
            var   fac  = UserModuleFactory.GetUserModuleInstance();
            IUser user = fac.GetUserByID(userId);

            if (user == null)
            {
                return(FuncResult.SuccessResult((ThirdPartyLoginResult)null));
            }
            LoginProvider localLogin = new LoginProvider(user.UserCode, null);

            localLogin.IgnorePassword = true;
            if (!localLogin.Login(package.ClientSource, package.ClientSystem, package.Device_Id, ipAddress, session_id, package.ClientVersion, appId))
            {
                return(FuncResult.FailResult <ThirdPartyLoginResult>(localLogin.PromptInfo.CustomMessage, (int)localLogin.PromptInfo.ResultType));
            }
            var data = new ThirdPartyLoginResult
            {
                Token    = localLogin.Token,
                UserCode = user.UserCode
            };

            return(FuncResult.SuccessResult(data));
        }
Example #5
0
        /// <summary>
        /// 创建GPU订单
        /// </summary>
        /// <returns></returns>
        private FuncResult <GpuOrder> CreateGpuOrder(IUser user, string order_no, decimal amount, PayType PayType)
        {
            string subject   = string.Concat(_arg.OrderType, "升级");
            var    currency  = new Currency(CurrencyType.RMB, amount);
            string notifyUrl = AppConfig.GpuNotifyReceiveUrl;
            var    gpuPay    = new GpuQuickPaymentProvider(user, subject, order_no, currency, (GpuPayType)PayType, TransferReason.升级VIP, notifyUrl);

            gpuPay.SetPrivateValue(AppConfig.VIPORDER_PRIVATE_VALUE);
            GpuOrder order = gpuPay.CreateOrder();

            if (order == null)
            {
                return(FuncResult.FailResult <GpuOrder>(gpuPay.PromptInfo.CustomMessage));
            }
            return(FuncResult.SuccessResult(order));
        }
Example #6
0
        public FuncResult <IParameterModel> Resolve(ReverseProxyContext context)
        {
            var result = GetParameterModel(context.HttpMethod, context.InputStream, context.Query);

            if (!result.Success)
            {
                return(result);
            }
            var signV = result.Content.VerifySignature();

            if (!signV.Success)
            {
                return(FuncResult.FailResult <IParameterModel>(signV.Message, signV.StatusCode));
            }
            ContentType contentType = "GET".Equals(context.HttpMethod, StringComparison.OrdinalIgnoreCase) ? ContentType.form_urlencoded : ContentType.json;

            context.DataModel    = result.Content;
            context.ForwardValue = new ProxyForwardValue(context.DataModel.GetBizContent(), contentType);
            return(FuncResult.SuccessResult(context.DataModel));
        }
        protected override FuncResult <IParameterModel> GetParameterModel(string httpMethod, Stream inputStream, IQueryCollection query)
        {
            GatewayParameterModel dataModel;

            if ("POST".Equals(httpMethod, StringComparison.OrdinalIgnoreCase))
            {
                string postData = null;
                using (StreamReader reader = new StreamReader(inputStream))
                {
                    postData = reader.ReadToEnd();
                }
                if (string.IsNullOrEmpty(postData))
                {
                    return(FuncResult.FailResult <IParameterModel>("无效报文", 405));
                }
                dataModel = JsonSerializer.Deserializer <GatewayParameterModel>(postData);
                dataModel.RequestOriginalString = postData;
            }
            else if ("GET".Equals(httpMethod, StringComparison.OrdinalIgnoreCase))
            {
                dataModel            = new GatewayParameterModel();
                dataModel.Data       = query["data"];
                dataModel.Sign       = query["sign"];
                dataModel.MerchantNo = query["merchantNo"];
                dataModel.Service    = query["service"];
                dataModel.Timestamp  = Convert.ToInt64(query["timestamp"]);
                StringBuilder sb = new StringBuilder();
                query.Aggregate(sb, (b, kv) => b.Append(kv.Key).Append("=").Append(kv.Value).Append("&"));
                if (sb.Length > 1)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                dataModel.RequestOriginalString = sb.ToString();
            }
            else
            {
                return(FuncResult.FailResult <IParameterModel>("不支持的请求头", 415));
            }
            return(FuncResult.SuccessResult((IParameterModel)dataModel));
        }
Example #8
0
        public ActionResult Apis()
        {
            OAuth2.Token.UserToken userToken = Token.UserToken.FromCipherToken(Package.Token);
            Tauth_Token            daToken   = new Tauth_Token();

            if (!daToken.SelectByAppId_UserId(userToken.AppId, Package.UserId))
            {
                return(FailResult("未找到授权访问令牌,Token无效", (int)ApiStatusCode.OPERATOR_FORBIDDEN));
            }
            Tauth_Token_RightCollection daRightCollection = new Tauth_Token_RightCollection();

            daRightCollection.ListEffectiveByTokenId(daToken.Token_Id);
            List <ScopeApiResult> list = MapProvider.Map <ScopeApiResult>(daRightCollection.DataTable);

            if (list == null || list.Count <= 0)
            {
                return(Json(FuncResult.SuccessResult(list)));
            }
            var apis = from scope in list where scope.Status == 1 select scope.Api_Url;

            return(Json(FuncResult.SuccessResult(apis)));
        }
Example #9
0
        public static FuncResult <OAuth2.Token.UserToken> DecryptAccessToken(string access_token)
        {
            var token = OAuth2.Token.UserToken.FromCipherToken(access_token);

            return(FuncResult.SuccessResult(token));
        }
        /// <summary>
        /// 创蓝通道发送短信,为SendNo赋值
        /// </summary>
        /// <param name="mobileno">目标手机号</param>
        /// <param name="msg">短信息内容</param>
        /// <param name="extno">扩展号码,纯数字(1-3位)</param>
        /// <returns></returns>
        private FuncResult SendSmsByChuangLan(string mobileno, string smsContent, string extno)
        {
            if (Debuger.IsDebug)
            {
                return(FuncResult.SuccessResult());
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("0", "提交成功");
            dic.Add("101", "无此用户");
            dic.Add("102", "密码错");
            dic.Add("103", "提交过快(提交速度超过流速限制)");
            dic.Add("104", "系统忙(因平台侧原因,暂时无法处理提交的短信)");
            dic.Add("105", "敏感短信(短信内容包含敏感词)");
            dic.Add("106", "消息长度错(>536或<=0)");
            dic.Add("107", "包含错误的手机号码");
            dic.Add("108", "手机号码个数错(群发>50000或<=0;单发>200或<=0)");
            dic.Add("109", "无发送额度(该用户可用短信数已使用完)");
            dic.Add("110", "不在发送时间内");
            dic.Add("111", "超出该账户当月发送额度限制");
            dic.Add("112", "无此产品,用户没有订购该产品");
            dic.Add("113", "extno格式错(非数字或者长度不对)");
            dic.Add("115", "自动审核驳回");
            dic.Add("116", "签名不合法,未带签名(用户必须带签名的前提下)");
            dic.Add("117", "IP地址认证错,请求调用的IP地址不是系统登记的IP地址");
            dic.Add("118", "用户没有相应的发送权限");
            dic.Add("119", "用户已过期");
            dic.Add("120", "短信内容不在白名单中");

            //string postStrTpl = "account={0}&pswd={1}&mobile={2}&msg={3}&needstatus=true&product=&extno={4}";
            string       postStrTpl = "un={0}&pw={1}&phone={2}&msg={3}&rd=1";
            UTF8Encoding encoding   = new UTF8Encoding();

            byte[] postData = encoding.GetBytes(string.Format(postStrTpl, this._channel.Access_Name, this._channel.Access_Key,
                                                              mobileno, smsContent));

            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(this._channel.Service_Url);
                myRequest.Method        = "POST";
                myRequest.ContentType   = "application/x-www-form-urlencoded";
                myRequest.ContentLength = postData.Length;

                Stream newStream = myRequest.GetRequestStream();
                // Send the data.
                newStream.Write(postData, 0, postData.Length);
                newStream.Flush();
                newStream.Close();

                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                if (myResponse.StatusCode == HttpStatusCode.OK)
                {
                    StreamReader reader   = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                    string       respText = reader.ReadToEnd();
                    Log.Info(respText);
                    TextReader tr      = new System.IO.StringReader(respText);
                    var        resText = tr.ReadLine();
                    var        msgid   = tr.ReadLine();
                    var        array   = resText.Split(',');
                    this.SendNo = msgid;
                    if (array[1] != "0")
                    {
                        string error = dic.ContainsKey(array[1]) ? dic[array[1]] : "发送失败";
                        return(FuncResult.FailResult(error));
                    }
                    return(FuncResult.SuccessResult());
                }
                return(FuncResult.FailResult("短信通道访问异常"));
            }
            catch (Exception ex)
            {
                return(FuncResult.FailResult("发送短信时出现系统繁忙!原因:" + ex.Message));
            }
        }