/// <summary>
        /// 组参.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private async Task <bool> ConfigParams(RestRequest request, SdkRequestType type, ISdkCmdBase data)
        {
            Action <string> errAction = (e1) =>
            {
                mSdkResponse.content = e1;
                mSdkResponse.errCode = SdkErrCode.XPARAM_ERR;
            };

            if (null == request)
            {
                errAction(Constants.SdkMsg.SDKInnerErr);
                return(false);
            }
            m_Client.BaseUrl = Constants.PublicApiUrl;
            if (SdkData.AccessToken != null)
            {
                request.AddParameter("access_token", SdkData.AccessToken);
            }
            else
            {
                errAction(Constants.SdkMsg.TokenNull);
                return(false);
            }

            switch (type)
            {
            case SdkRequestType.POST_MESSAGE:
            {
                CmdPostMessage message = null;
                if (data is CmdPostMessage)
                {
                    message = data as CmdPostMessage;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Method   = Method.POST;
                request.Resource = Constants.WeiboAPI.PostMsg;

                if (message.Status.Length > 0)
                {
                    request.AddParameter("status", message.Status);
                }
                if (message.ReplyId.Length > 0)
                {
                    request.AddParameter("in_reply_to_status_id", message.ReplyId);
                }
                if (message.Lat.Length > 0)
                {
                    request.AddParameter("lat", message.Lat);
                }
                if (message.Long.Length > 0)
                {
                    request.AddParameter("long", message.Long);
                }
                if (message.Annotations.Length > 0)
                {
                    request.AddParameter("annotations", message.Annotations);
                }
            }
            break;

            case SdkRequestType.POST_MESSAGE_PIC:
            {
                CmdPostMsgWithPic message = null;
                if (data is CmdPostMsgWithPic)
                {
                    message = data as CmdPostMsgWithPic;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Method   = Method.POST;
                request.Resource = Constants.WeiboAPI.PostMsgPic;

                request.AddParameter("status", message.Status);

                if (message.Lat.Length > 0)
                {
                    request.AddParameter("lat", message.Lat);
                }
                if (message.Long.Length > 0)
                {
                    request.AddParameter("long", message.Long);
                }

                if (0 == message.PicPath.Length)
                {
                    errAction(Constants.SdkMsg.PicPathEmpty);
                    return(false);
                }

                string picType = System.IO.Path.GetExtension(message.PicPath);
                string picName = System.IO.Path.GetFileName(message.PicPath);

//                        await request.AddFileAsync("pic", message.PicPath);
            }
            break;

            case SdkRequestType.FRIENDS_TIMELINE:
            {
                CmdTimelines message = null;
                if (data is CmdTimelines)
                {
                    message = data as CmdTimelines;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.FriendTimeline;
                request.Method   = Method.GET;
                if (message.SinceID.Length > 0)
                {
                    request.AddParameter("since_id", message.SinceID);
                }
                if (message.MaxID.Length > 0)
                {
                    request.AddParameter("max_id", message.MaxID);
                }
                if (message.Count.Length > 0)
                {
                    request.AddParameter("count", message.Count);
                }
                if (message.Page.Length > 0)
                {
                    request.AddParameter("page", message.Page);
                }
                if (message.BaseApp.Length > 0)
                {
                    request.AddParameter("base_app", message.BaseApp);
                }
                if (message.Feature.Length > 0)
                {
                    request.AddParameter("feature", message.Feature);
                }
            }
            break;

            case SdkRequestType.USER_TIMELINE:
            {
                CmdUserTimeline message = null;
                if (data is CmdUserTimeline)
                {
                    message = data as CmdUserTimeline;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.UserTimeline;
                request.Method   = Method.GET;

                if (message.UserId.Length > 0)
                {
                    request.AddParameter("user_id", message.UserId);
                }
                if (message.ScreenName.Length > 0)
                {
                    request.AddParameter("screen_name", message.ScreenName);
                }
                if (message.SinceID.Length > 0)
                {
                    request.AddParameter("since_id", message.SinceID);
                }
                if (message.MaxID.Length > 0)
                {
                    request.AddParameter("max_id", message.MaxID);
                }
                if (message.Count.Length > 0)
                {
                    request.AddParameter("count", message.Count);
                }

                if (message.Page.Length > 0)
                {
                    request.AddParameter("page", message.Page);
                }
                if (message.BaseApp.Length > 0)
                {
                    request.AddParameter("base_app", message.BaseApp);
                }
                if (message.Feature.Length > 0)
                {
                    request.AddParameter("feature", message.Feature);
                }
            }
            break;

            case SdkRequestType.FRIENDSHIP_CREATE:
            {
                CmdFriendShip message = null;
                if (data is CmdFriendShip)
                {
                    message = data as CmdFriendShip;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.CreateFriendShip;
                request.Method   = Method.POST;

                if (message.UserId.Length > 0)
                {
                    request.AddParameter("user_id", message.UserId);
                }
                if (message.ScreenName.Length > 0)
                {
                    request.AddParameter("screen_name", message.ScreenName);
                }
            }
            break;

            case SdkRequestType.FRIENDSHIP_DESDROY:
            {
                CmdFriendShip message = null;
                if (data is CmdFriendShip)
                {
                    message = data as CmdFriendShip;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.DestroyFriendShip;
                request.Method   = Method.POST;

                if (message.UserId.Length > 0)
                {
                    request.AddParameter("user_id", message.UserId);
                }
                if (message.ScreenName.Length > 0)
                {
                    request.AddParameter("screen_name", message.ScreenName);
                }
            }
            break;

            case SdkRequestType.FRIENDSHIP_SHOW:
            {
                CmdFriendShip message = null;
                if (data is CmdFriendShip)
                {
                    message = data as CmdFriendShip;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.ShowFriendShip;
                request.Method   = Method.GET;

                if (message.SourceId.Length > 0)
                {
                    request.AddParameter("source_id", message.SourceId);
                }
                if (message.SourceScreenName.Length > 0)
                {
                    request.AddParameter("source_screen_name", message.SourceScreenName);
                }

                if (message.UserId.Length > 0)
                {
                    request.AddParameter("target_id", message.UserId);
                }
                if (message.ScreenName.Length > 0)
                {
                    request.AddParameter("target_screen_name", message.ScreenName);
                }
            }
            break;

            case SdkRequestType.AT_USERS:
            {
                CmdAtUsers atUsers = null;
                if (data is CmdAtUsers)
                {
                    atUsers = data as CmdAtUsers;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.AtUser;
                request.Method   = Method.GET;
                if (atUsers.Keyword.Length > 0)
                {
                    request.AddParameter("q", atUsers.Keyword);
                }
                if (atUsers.Count.Length > 0)
                {
                    request.AddParameter("count", atUsers.Count);
                }
                if (atUsers.Range.Length > 0)
                {
                    request.AddParameter("range", atUsers.Range);
                }
                if (atUsers.Type.Length > 0)
                {
                    request.AddParameter("type", atUsers.Type);
                }
            }
            break;

            case SdkRequestType.SHORTEN_URL:
            {
                CmdShortenUrl shortUrl = null;
                if (data is CmdShortenUrl)
                {
                    shortUrl = data as CmdShortenUrl;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                request.Resource = Constants.WeiboAPI.ShortenUrl;
                request.Method   = Method.GET;
                if (shortUrl.OriginalUrl.Length > 0)
                {
                    request.AddParameter("url_long", shortUrl.OriginalUrl);
                }
            }
            break;

            case SdkRequestType.OTHER_API:
            {
                ICustomCmdBase customData = null;
                if (data is ICustomCmdBase)
                {
                    customData = data as ICustomCmdBase;
                }
                else
                {
                    errAction(Constants.SdkMsg.ParamTypeErr);
                    return(false);
                }
                customData.ConvertToRequestParam(request);
            }
            break;

            default:
            {
                errAction(Constants.SdkMsg.RequestNotSupppt);
                return(false);
            }
            }
            request.AddParameter("curtime", DateTime.Now.Ticks.ToString());
            return(true);
        }
Пример #2
0
		private async Task<string> Timeline()
		{
			var engine = new SdkNetEngine();
			ISdkCmdBase cmdBase = new CmdTimelines()
			{
				Count = "10",
				Page = "1"
			};
			var result = await engine.RequestCmd(SdkRequestType.FRIENDS_TIMELINE, cmdBase);
			if (result.errCode == SdkErrCode.SUCCESS)
			{
				return result.content;

			}
			else
			{
				return string.Empty;
			}
		}