Example #1
0
        public DiscuzParam[] Sign(string method_name, DiscuzParam[] parameters)
        {
            List <DiscuzParam> list = new List <DiscuzParam>(parameters);

            list.Add(DiscuzParam.Create("method", method_name));
            list.Add(DiscuzParam.Create("api_key", api_key));
            list.Sort();

            StringBuilder values = new StringBuilder();

            foreach (DiscuzParam param in list)
            {
                if (!string.IsNullOrEmpty(param.Value))
                {
                    values.Append(param.ToString());
                }
            }

            values.Append(secret);

            byte[] md5_result = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(values.ToString()));

            StringBuilder sig_builder = new StringBuilder();

            foreach (byte b in md5_result)
            {
                sig_builder.Append(b.ToString("x2"));
            }

            list.Add(DiscuzParam.Create("sig", sig_builder.ToString()));

            return(list.ToArray());
        }
Example #2
0
        /// <summary>
        /// 从令牌中获得会话
        /// </summary>
        /// <param name="auth_token"></param>
        /// <returns></returns>
        public SessionInfo GetSessionFromToken(string auth_token)
        {
            this.session_info = util.GetResponse <SessionInfo>("auth.getSession",
                                                               DiscuzParam.Create("auth_token", auth_token));
            //this.util.SharedSecret = session_info.Secret;

            this.auth_token          = string.Empty;
            this.session_info.Secret = util.SharedSecret;
            return(session_info);
        }
Example #3
0
        /// <summary>
        /// 创建论坛
        /// </summary>
        /// <param name="forum">要创建的论坛</param>
        /// <returns></returns>
        public CreateForumResponse ForumCreate(Forum forum)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("forum_info", JsonConvert.SerializeObject(forum)));
            CreateForumResponse fcr = util.GetResponse <CreateForumResponse>("forums.create", param_list.ToArray());

            return(fcr);
        }
Example #4
0
        /// <summary>
        /// 获取论坛信息
        /// </summary>
        /// <param name="fid">论坛id</param>
        /// <returns></returns>
        public GetForumResponse ForumGet(int fid)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("fid", fid));
            GetForumResponse gfr = util.GetResponse <GetForumResponse>("forums.get", param_list.ToArray());

            return(gfr);
        }
Example #5
0
        /// <summary>
        /// 根据用户名得到用户ID
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public int GetUserID(string username)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("user_name", username));

            GetIDResponse gir = util.GetResponse <GetIDResponse>("users.getID", param_list.ToArray());

            return(gir.UId);
        }
Example #6
0
        /// <summary>
        /// 回复帖子
        /// </summary>
        /// <param name="reply"></param>
        /// <returns></returns>
        public TopicReplyResponse TopicsReplay(Reply reply)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("reply_info", JsonConvert.SerializeObject(reply)));
            TopicReplyResponse trr = util.GetResponse <TopicReplyResponse>("topics.reply", param_list.ToArray());

            return(trr);
        }
Example #7
0
        /// <summary>
        /// 发送email通知
        /// </summary>
        /// <param name="recipients">uids</param>
        /// <param name="subject">主题</param>
        /// <param name="text">内容</param>
        /// <returns></returns>
        public string NotificationSendEmail(string recipients, string subject, string text)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("recipients", recipients));
            param_list.Add(DiscuzParam.Create("subject", subject));
            param_list.Add(DiscuzParam.Create("text", text));


            SendNotificationEmailResponse sner = util.GetResponse <SendNotificationEmailResponse>("notifications.sendEmail", param_list.ToArray());

            return(sner.Recipients = recipients);
        }
Example #8
0
        /// <summary>
        /// 发送通知
        /// </summary>
        /// <param name="note"></param>
        /// <param name="to_ids"></param>
        /// <param name="uid">如果为0,就用当前用户会话id</param>
        /// <returns>发送成功的用户id列表字符串</returns>
        public string NotificationsSend(string notification, string to_ids, int uid)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (uid < 1 && session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }

            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("to_ids", to_ids));
            param_list.Add(DiscuzParam.Create("notification", notification));

            SendNotificationResponse nsr = util.GetResponse <SendNotificationResponse>("notifications.send", param_list.ToArray());

            return(nsr.Result);
        }
Example #9
0
        /// <summary>
        /// 设置扩展积分
        /// </summary>
        /// <param name="additional_values"></param>
        /// <returns></returns>
        public bool SetExtCredits(string additional_values)
        {
            if (session_info == null)
            {
                return(false);
            }

            List <DiscuzParam> param_list = new List <DiscuzParam>();

            param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("additional_values", additional_values));

            SetExtCreditsResponse secr = util.GetResponse <SetExtCreditsResponse>("users.setExtCredits", param_list.ToArray());

            return(secr.Successfull == 1);
        }
Example #10
0
        /// <summary>
        /// 设置用户信息
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="user_for_editing"></param>
        /// <returns></returns>
        public bool SetUserInfo(int uid, UserForEditing user_for_editing)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));

            param_list.Add(DiscuzParam.Create("uid", uid));
            param_list.Add(DiscuzParam.Create("user_info", Newtonsoft.Json.JsonConvert.SerializeObject(user_for_editing)));

            SetInfoResponse sir = util.GetResponse <SetInfoResponse>("users.setInfo", param_list.ToArray());

            return(sir.Successfull == 1);
        }
Example #11
0
        /// <summary>
        /// 加密密码
        /// </summary>
        /// <param name="password"></param>
        /// <param name="isMD5Passwd"></param>
        /// <returns></returns>
        public string EncodePassword(string password, bool isMD5Passwd)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            //param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("password", password));

            if (isMD5Passwd)
            {
                param_list.Add(DiscuzParam.Create("password_format", "md5"));
            }

            EncodePasswordResponse epr = util.GetResponse <EncodePasswordResponse>("auth.encodePassword", param_list.ToArray());

            return(epr.Password);
        }
Example #12
0
        /// <summary>
        /// 最近回复的帖子
        /// </summary>
        /// <param name="fid">论坛id</param>
        /// <param name="tid">帖子id</param>
        /// <param name="page_size"></param>
        /// <param name="page_index"></param>
        /// <returns></returns>
        public TopicGetRencentRepliesResponse GetRecentReplies(int fid, int tid, int page_size, int page_index)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("fid", fid));
            param_list.Add(DiscuzParam.Create("tid", tid));
            param_list.Add(DiscuzParam.Create("page_size", page_size));
            param_list.Add(DiscuzParam.Create("page_index", page_index));

            TopicGetRencentRepliesResponse tgrr = util.GetResponse <TopicGetRencentRepliesResponse>("topics.getRecentReplies", param_list.ToArray());

            return(tgrr);
        }
Example #13
0
        /// <summary>
        /// 获取通知
        /// </summary>
        /// <returns></returns>
        public GetNotiificationResponse NotificationGet()
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            else
            {
                return(null);
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));

            GetNotiificationResponse gnr = util.GetResponse <GetNotiificationResponse>("notifications.get", param_list.ToArray());

            return(gnr);
        }
Example #14
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="isMD5Passwd"></param>
        /// <param name="nickName"></param>
        /// <returns></returns>
        public int Register(string username, string password, string email, bool isMD5Passwd, string nickName)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            //param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("user_name", username));
            param_list.Add(DiscuzParam.Create("nickname", nickName));
            param_list.Add(DiscuzParam.Create("password", password));
            param_list.Add(DiscuzParam.Create("email", email));

            if (isMD5Passwd)
            {
                param_list.Add(DiscuzParam.Create("password_format", "md5"));
            }

            RegisterResponse rsp = util.GetResponse <RegisterResponse>("auth.register", param_list.ToArray());

            return(rsp.Uid);
        }
Example #15
0
        /// <summary>
        /// 获得用户信息
        /// </summary>
        /// <param name="uids"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public User[] GetUserInfo(long[] uids, string[] fields)
        {
            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (session_info != null && !string.IsNullOrEmpty(session_info.SessionKey))
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));

            if (uids == null || uids.Length == 0)
            {
                throw new Exception("uid not provided");
            }

            param_list.Add(DiscuzParam.Create("uids", uids));
            param_list.Add(DiscuzParam.Create("fields", fields));

            UserInfoResponse rsp = util.GetResponse <UserInfoResponse>("users.getInfo", param_list.ToArray());

            return(rsp.Users);
        }
Example #16
0
        /// <summary>
        /// 创建主题
        /// </summary>
        /// <param name="uid">指定用户ID,0为当前登录用户ID</param>
        /// <param name="title">标题</param>
        /// <param name="fid">版块ID</param>
        /// <param name="message">主题内容</param>
        /// <param name="icon_id">图标编号</param>
        /// <param name="tags">标签,半角逗号分隔</param>
        /// <returns></returns>
        public TopicCreateResponse CreateTopic(int uid, string title, int fid, string message, int icon_id, string tags)
        {
            Topic topic = new Topic();

            topic.UId     = uid == 0 ? (int)session_info.UId : uid;
            topic.Title   = title;
            topic.Fid     = fid;
            topic.Message = message;
            topic.Iconid  = icon_id;
            topic.Tags    = tags;

            List <DiscuzParam> param_list = new List <DiscuzParam>();

            if (uid == 0)
            {
                param_list.Add(DiscuzParam.Create("session_key", session_info.SessionKey));
            }
            param_list.Add(DiscuzParam.Create("call_id", DateTime.Now.Ticks));
            param_list.Add(DiscuzParam.Create("topic_info", Newtonsoft.Json.JsonConvert.SerializeObject(topic)));
            TopicCreateResponse tcr = util.GetResponse <TopicCreateResponse>("topics.create", param_list.ToArray());

            return(tcr);
        }