Beispiel #1
0
        public ResultModel <StockModel[]> UpdatePrices()
        {
            if (Credentials == null)
            {
                return(ResultModel <StockModel[]> .ThrowIfError("Authorization is required"));
            }

            if (!Credentials.IsValid())
            {
                return(ResultModel <StockModel[]> .ThrowIfError("Invalid Username or Password"));
            }

            var user   = UserManager.Find(Credentials.UserName, Credentials.Password);
            var stocks = user.Stocks.Select(s => new StockModel(s.Symbol, s.Name, s.Price));

            foreach (var stock in stocks)
            {
                stock.Price = RandomHelper.GetNumber();
            }

            UserManager.Update(user);

            var model = user.Stocks.Select(s => new StockModel(s.Symbol, s.Name, s.Price)).ToArray();

            return(ResultModel <StockModel[]> .CreateInstance(model));
        }
Beispiel #2
0
        /// <summary>
        /// 发送文本消息给客户
        /// </summary>
        /// <param name="message"></param>
        private void _SendText(TextMessage message)
        {
            string sendUrl = ApiUrl.GetSendCustomUrl(message.AccessToken);

            string result = HttpHelper.PostJson(sendUrl, JsonConvert.SerializeObject(message));

            ResultModel.CreateInstance(result).HasException();
        }
Beispiel #3
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="config"></param>
        private void _CreateMenu(MenuModel menu, ConfigModel config)
        {
            string sendUrl = ApiUrl.GetCreateMenuUrl(config.AccessToken);

            string json = JsonConvert.SerializeObject(menu, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            string result = HttpHelper.PostJson(sendUrl, json);

            ResultModel.CreateInstance(result).HasException();
        }
Beispiel #4
0
        /// <summary>
        /// 创建字符型id永久二维码
        /// 如果每次使用的str id一样,生成的ticket就一样,图片一样,如果扫描,返回的str id都一样。
        /// </summary>
        /// <param name="scene_str">场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段 </param>
        /// <returns></returns>
        public QrCodeResultModel CreateQrCodeByStr(string scene_str)
        {
            string url      = ApiUrl.GetCreateQrUrl(Config.AccessToken);
            string postData = QrCodeModel.CreateQrCodeByStrPostData(scene_str);
            string json     = HttpHelper.PostJson(url, postData);

            ResultModel.CreateInstance(json).HasException();

            JObject           jo     = JObject.Parse(json);
            QrCodeResultModel rModel = jo.ToObject <QrCodeResultModel>();

            return(rModel);
        }
Beispiel #5
0
        /// <summary>
        ///  创建临时二维码
        ///  就算每次使用的id一样,生成的ticket也不会一样,图片不一样,如果扫描,返回的id却都一样。
        /// </summary>
        /// <param name="scene_id">场景值ID,临时二维码时为32位非0整型</param>
        /// <param name="expire_seconds">该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 </param>
        /// <returns></returns>
        public QrCodeResultModel CreateQrCodeTemp(int scene_id, int?expire_seconds = null)
        {
            string url      = ApiUrl.GetCreateQrUrl(Config.AccessToken);
            string postData = QrCodeModel.CreateQrCodeTempPostData(scene_id, expire_seconds);
            string json     = HttpHelper.PostJson(url, postData);

            ResultModel.CreateInstance(json).HasException();

            JObject           jo     = JObject.Parse(json);
            QrCodeResultModel rModel = jo.ToObject <QrCodeResultModel>();

            return(rModel);
        }
Beispiel #6
0
        /// <summary>
        /// 获取用户基本信息(包括UnionID机制)
        /// </summary>
        /// <param name="openid">用户ID</param>
        /// <param name="lang">语言</param>
        /// <returns></returns>
        public UserInfoModel GetUserInfo(string openid, string lang = Constants.LANG_ZH_CN)
        {
            string url = ApiUrl.GetUserInfoUrl(Config.AccessToken, openid, lang);

            String json = HttpHelper.ScrapeWebPage(url);

            ResultModel.CreateInstance(json).HasException();

            JObject jo = JObject.Parse(json);

            UserInfoModel userInfoModel = jo.ToObject <UserInfoModel>();

            return(userInfoModel);
        }
        public ResultModel <UserModel> Register(string fullName, string email, string password)
        {
            var userEnt = UserManager.FindByEmail(email);

            if (userEnt != null)
            {
                return(ResultModel <UserModel> .ThrowIfError("This " + email + " user exist"));
            }

            var role = MemberRole.Client;

            //entity
            var user = new User
            {
                UserName = email,
                Email    = email,
                FullName = fullName
            };

            //user
            var result = UserManager.Create(user, password);

            if (!result.Succeeded)
            {
                var errors = string.Join(";", result.Errors);

                return(ResultModel <UserModel> .ThrowIfError(errors));
            }

            //role
            result = UserManager.AddToRole(user.Id, role.GetName());
            if (!result.Succeeded)
            {
                var errors = string.Join(";", result.Errors);

                return(ResultModel <UserModel> .ThrowIfError(errors));
            }

            return(ResultModel <UserModel> .CreateInstance(new UserModel
            {
                FullName = fullName,
                Password = password,
                UserName = email,
                Role = role
            }));
        }
Beispiel #8
0
        public ResultModel <StockModel[]> GetList()
        {
            if (Credentials == null)
            {
                return(ResultModel <StockModel[]> .ThrowIfError("Authorization is required"));
            }

            if (!Credentials.IsValid())
            {
                return(ResultModel <StockModel[]> .ThrowIfError("Invalid Username or Password"));
            }

            var user  = UserManager.Find(Credentials.UserName, Credentials.Password);
            var model = user.Stocks.Select(s => new StockModel(s.Symbol, s.Name, s.Price)).ToArray();

            return(ResultModel <StockModel[]> .CreateInstance(model));
        }
Beispiel #9
0
        /// <summary>
        /// 批量获取用户基本信息,开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
        /// </summary>
        /// <param name="batchgetUserInfoList">要请求的批量用户</param>
        /// <returns></returns>
        public List <UserInfoModel> BatchGetUserInfo(List <ParamBatchgetUserInfo> batchgetUserInfoList)
        {
            string url = ApiUrl.BatchGetUserInfoUrl(Config.AccessToken);

            var paramBatchgetUserInfoList = new ParamBatchgetUserInfoList {
                user_list = batchgetUserInfoList
            };

            string json = HttpHelper.PostJson(url, JsonConvert.SerializeObject(paramBatchgetUserInfoList));

            ResultModel.CreateInstance(json).HasException();

            JObject jo = JObject.Parse(json);

            UserInfoList userInfoList = jo.ToObject <UserInfoList>();

            return(userInfoList.user_info_list);
        }
        public ResultModel <UserModel> Login(string user, string password)
        {
            var userEnt = UserManager.Find(user, password);

            if (userEnt == null)
            {
                return(ResultModel <UserModel> .ThrowIfError("User name or password is wrond"));
            }

            var roles   = UserManager.GetRoles(userEnt.Id) ?? new string[] { };
            var roleEnt = RoleManager.FindByName(roles[0]);
            var model   = new UserModel
            {
                UserName = user,
                Password = password,
                FullName = userEnt.FullName,
                Role     = roleEnt.Code
            };

            return(ResultModel <UserModel> .CreateInstance(model));
        }