/// <summary> /// Send TExt Content With Picture to social platform /// </summary> /// <param name="platformType">platfrom Type</param> /// <param name="content">Content TExt</param> /// <param name="picFileStream">Upload File Stream</param> public void SendTextWithPicContent(PlatformType platformType, string content, Stream picFileStream) { AuthorizeConfig authorizeConfig = GetAuthorizeConfig(platformType); DataRequestHelper dataRequestHelper = new DataRequestHelper(); string requestUrl = string.Empty; //upload picture as text content byte[] picBytes = new byte[picFileStream.Length]; picFileStream.Seek(0, SeekOrigin.Begin); picFileStream.Read(picBytes, 0, picBytes.Length); //notice : when you add fileparameter rename filename to api convert List <FileParameter> uploadFileList = new List <FileParameter>() { FileParameter.Create("pic", picBytes, DateTime.Now.ToString("yyyyMMddHHmmss")) }; if (platformType == PlatformType.Tencent) { #region send text with picture to tencent platform AccessTokenData tokenData = IsolatedStorageSettings.ApplicationSettings["tencenttoken"] as AccessTokenData; TencentSocialHelper tencentSocialHelper = new TencentSocialHelper(); requestUrl = tencentSocialHelper.GetTextContentWithPicUrl(authorizeConfig.OauthApiUrl, authorizeConfig.AppKey, tokenData.AccessToken, tokenData.OpenId, content, FormatType.Json); if (tencentSocialHelper.PostArgumentList != null) { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, tencentSocialHelper.PostArgumentList, uploadFileList); } else { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, null, uploadFileList); } dataRequestHelper.AsyncResponseComplated += (responseData, ex) => { if (!string.IsNullOrEmpty(responseData.ToString())) { TencentTextResponseData uploadRepData = JsonConvert.DeserializeObject <TencentTextResponseData>(responseData.ToString()); if (uploadRepData.ErrCode == "0" && uploadRepData.Msg.Trim().ToLower() == "ok") { //send text with picture success if (AsyncSendPictureComplated != null) { AsyncSendPictureComplated("success", null); } } else { //send text with picture failed if (AsyncSendPictureComplated != null) { AsyncSendPictureComplated("fail", uploadRepData.Msg); } } } }; #endregion } else if (platformType == PlatformType.Sina) { #region send text with picture to sina platform AccessTokenData sinaToken = IsolatedStorageSettings.ApplicationSettings["sinatoken"] as AccessTokenData; SinaSocialHelper sinaSocialHelper = new SinaSocialHelper(); requestUrl = sinaSocialHelper.GetTextContentWithPicUrl(authorizeConfig.OauthApiUrl, sinaToken.AccessToken, content); if (sinaSocialHelper.PostArgumentList != null) { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, sinaSocialHelper.PostArgumentList, uploadFileList); } else { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, null, uploadFileList); } dataRequestHelper.AsyncResponseComplated += (responseData, ex) => { if (!string.IsNullOrEmpty(responseData.ToString())) { SinaTextErrorData sinaErrorData = JsonConvert.DeserializeObject <SinaTextErrorData>(responseData.ToString()); SinaTextResponseData sinaRepData = JsonConvert.DeserializeObject <SinaTextResponseData>(responseData.ToString()); if (sinaErrorData.Error == null && sinaErrorData.Error_Code == null) { //send text with picture success if (AsyncSendPictureComplated != null) { AsyncSendPictureComplated("success", null); } } else { //send text with picture fail if (AsyncSendPictureComplated != null) { AsyncSendPictureComplated("fail", sinaErrorData.Error); } } } }; #endregion } }
/// <summary> /// Send Pure text content to social platform /// </summary> /// <param name="platformType">platform type</param> /// <param name="content">text content</param> public void SendPureTextContent(PlatformType platformType, string content) { AuthorizeConfig authorizeConfig = GetAuthorizeConfig(platformType); DataRequestHelper dataRequestHelper = new DataRequestHelper(); string requestUrl = string.Empty; if (platformType == PlatformType.Tencent) { #region send pure text content to tencent platform AccessTokenData tencentToken = IsolatedStorageSettings.ApplicationSettings["tencenttoken"] as AccessTokenData; TencentSocialHelper tencentSocialHelper = new TencentSocialHelper(); requestUrl = tencentSocialHelper.GetPureTextContentUrl(authorizeConfig.ApiUrl, authorizeConfig.AppKey, tencentToken.AccessToken, tencentToken.OpenId, content, FormatType.Json); if (tencentSocialHelper.PostArgumentList != null) { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, tencentSocialHelper.PostArgumentList); } else { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST); } dataRequestHelper.AsyncResponseComplated += (responseData, ex) => { if (!string.IsNullOrEmpty(responseData.ToString())) { TencentTextResponseData pureRepData = JsonConvert.DeserializeObject <TencentTextResponseData>(responseData.ToString()); if (pureRepData.Msg.Trim().ToLower() == "ok" && pureRepData.ErrCode == "0") { //send text content success if (AsyncSendContentComplated != null) { AsyncSendContentComplated("success", null); } } else { //send text content failed if (AsyncSendContentComplated != null) { AsyncSendContentComplated("fail", pureRepData.Msg); } } } }; #endregion } else if (platformType == PlatformType.Sina) { #region send pure text content to sina platform AccessTokenData sinaToken = IsolatedStorageSettings.ApplicationSettings["sinatoken"] as AccessTokenData; SinaSocialHelper sinaSocialHelper = new SinaSocialHelper(); requestUrl = sinaSocialHelper.GetPureTextContentUrl(authorizeConfig.ApiUrl, sinaToken.AccessToken, content); if (sinaSocialHelper.PostArgumentList != null) { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST, sinaSocialHelper.PostArgumentList); } else { dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.POST); } dataRequestHelper.AsyncResponseComplated += (responseData, ex) => { if (!string.IsNullOrEmpty(responseData.ToString())) { SinaTextErrorData sinaErrorData = JsonConvert.DeserializeObject <SinaTextErrorData>(responseData.ToString()); SinaTextResponseData sinaResponseData = JsonConvert.DeserializeObject <SinaTextResponseData>(responseData.ToString()); if (sinaErrorData.Error == null && sinaErrorData.Error_Code == null) { //send text content success if (AsyncSendContentComplated != null) { AsyncSendContentComplated("success", null); } } else { //send text content failed if (AsyncSendContentComplated != null) { AsyncSendContentComplated("fail", sinaErrorData.Error); } } } }; #endregion } }