예제 #1
0
        ///// <summary>
        ///// 加入农场
        ///// </summary>
        ///// <param name="user">用户类</param>
        ///// <returns></returns>
        //[HttpPost]
        //[AuthFilterOutside]
        //public object JoinFarm(User user)
        //{
        //    string token = null;
        //    //获取请求
        //    var request = HttpContext.Current.Request;
        //    token = request.Headers["Token"];
        //    AuthFilterOutside auth = new AuthFilterOutside();
        //    var role = auth.RoleType(token);
        //    //响应
        //    ResultMsg<User> resultmsg = new ResultMsg<User>();
        //    HttpResponseMessage response = new HttpResponseMessage();
        //    PostgreSQL.OpenCon();//打开数据库
        //    //判断用户
        //    string strtoken = SunGolden.Encryption.DEncrypt.Decrypt(request.Headers["Token"]); //解密Token
        //    string str_mobile = strtoken.Substring(0, strtoken.IndexOf(","));
        //    //查询数据库
        //    string str1 = string.Format("select * from tb_user where \"mobile\" =\'{0}\'", str_mobile);
        //    //string str ="select farm from tb_user where \"mobile\" = \'@mobile\'}";
        //    var para2 = new DbParameter[1];
        //    para2[0] = PostgreSQL.NewParameter("@moblie", str_mobile);
        //    var quser = PostgreSQL.ExecuteTQuery<User>(str1, null, para2);
        //    if (quser != null)
        //    {
        //        if (role == "1")// "管理员"
        //        {
        //            //string str = "select * from  tb_user where mobile=@mobile;";  //SQL查询语句
        //            var trans = PostgreSQL.BeginTransaction();
        //            try
        //            {
        //                string str_update = "update tb_user set farm= @farm where id=@id;";// mobile= @mobile;";
        //                var para1 = new DbParameter[2];
        //                para1[0] = PostgreSQL.NewParameter("@farm", user.farm);
        //                para1[1] = PostgreSQL.NewParameter("@id", user.id);
        //                var num = PostgreSQL.ExecuteNoneQuery(str_update, trans, para1);
        //                PostgreSQL.CommitTransaction(trans);
        //                //查询数据库
        //                //var para2 = new DbParameter[1];
        //                //para2[0] = PostgreSQL.NewParameter("@mobile", user.mobile);
        //                //var qfarm1 = PostgreSQL.ExecuteTQuery<User>(str, null, para2);
        //                //PostgreSQL.CloseCon();
        //                //返回信息
        //                resultmsg.status = true;
        //                resultmsg.msg = "成功加入农场!";
        //                resultmsg.data = null;
        //                token = request.Headers["Token"];
        //            }
        //            catch (Exception ex)
        //            {
        //                PostgreSQL.RollbackTransaction(trans);
        //                //返回信息
        //                resultmsg.status = false;
        //                resultmsg.msg = "[ERROR] 数据库操作出现异常:" + ex.Message;
        //                resultmsg.data = null;
        //                token = request.Headers["Token"];
        //            }
        //        }
        //        else
        //        {
        //            resultmsg.status = false;
        //            resultmsg.msg = "用户为农场主,不用加入农场!";
        //            resultmsg.data = null;
        //            token = request.Headers["Token"];
        //        }
        //    }
        //    else
        //    {
        //        resultmsg.status = false;
        //        resultmsg.msg = "此用户不存在,非用户操作!";
        //        resultmsg.data = null;
        //        token = request.Headers["Token"];
        //    }
        //    PostgreSQL.CloseCon();//关闭数据库
        //    //添加响应头信息
        //    var resultObj = JsonConvert.SerializeObject(resultmsg, Formatting.Indented);
        //    response.Headers.Add("Token", token);
        //    response.Content = new StringContent(resultObj);
        //    return response;
        //}

        //OpenIM
        private void OpenIm(Userinfo userinfo)
        {
            string                url       = "https://eco.taobao.com/router/rest";
            string                appkey    = "24863493";
            string                appsecret = "faaf14c5f5f5331387a50e43e2e9b599";
            ITopClient            client    = new DefaultTopClient(url, appkey, appsecret);
            OpenimUsersAddRequest req       = new OpenimUsersAddRequest();

            req.Userinfos = JsonConvert.SerializeObject(userinfo, Formatting.Indented); //"{\"userid\":\"" + userinfo + "\" ,\"password\":\"" +SunGolden.Encryption.DEncrypt.Encrypt(userinfo) + "\" ,\"mobile\":\"" + userinfo + "\"}";
            OpenimUsersAddResponse response = client.Execute(req);
        }
예제 #2
0
        internal bool Inserts(List <OpenIMUserInfo> openImUserInfoList)
        {
            bool result = false;
            OpenimUsersAddRequest request = new OpenimUsersAddRequest();
            List <Userinfos>      list    = new List <Userinfos>();

            foreach (var item in openImUserInfoList.AsEnumerable())
            {
                Userinfos user_item = new Userinfos()
                {
                    Address     = item.Address,
                    Age         = item.Age,
                    Career      = item.Career,
                    Email       = item.Email,
                    Extra       = item.Extra,
                    Gender      = (item.Sex == MiicSexSetting.Female ? "F" : "M"),
                    IconUrl     = item.Logo,
                    Mobile      = item.Mobile,
                    Name        = item.RealName,
                    Nick        = item.NickName,
                    Password    = item.Password,
                    Qq          = item.QQ,
                    Remark      = item.Remark,
                    Status      = (long)(int)item.Status,
                    Userid      = item.UserID,
                    Taobaoid    = item.TaobaoID,
                    Vip         = item.Vip,
                    Wechat      = item.Weixin,
                    Weibo       = item.Weibo,
                    GmtModified = item.UpdateTime.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm:ss")
                };
                Userinfos user = user_item;
                list.Add(user);
            }
            request.Userinfos_ = list;
            try
            {
                OpenimUsersAddResponse response = client.Execute(request);
                if (response.UidSucc.Count == openImUserInfoList.Count)
                {
                    result = true;
                }
                else
                {
                    for (var item = 0; item < response.FailMsg.Count; item++)
                    {
                        if (response.FailMsg[item] == "data exist")
                        {
                            ((IOpenIMUserInfo)this).Delete(response.UidFail[item]);
                        }
                        else
                        {
                            ((IOpenIMUserInfo)this).Delete(response.UidSucc[item]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Config.IlogicLogService.Write(new LogicLog()
                {
                    AppName       = Config.AppName,
                    ClassName     = ClassName,
                    NamespaceName = NamespaceName,
                    MethodName    = MethodBase.GetCurrentMethod().Name,
                    Message       = ex.Message,
                    Oper          = Config.Oper
                });
            }
            return(result);
        }