void AuthorizeWB_Navigating(object sender, NavigatingEventArgs e) { if (e.Uri.OriginalString.Contains("access_token")) { List<Parameter> tokenvalues = HttpUtil.GetParameters(e.Uri.OriginalString); OauthKey oauthKey = new OauthKey(); oauthKey.tokenKey = tokenvalues[0].Value; oauthKey.expiredTime = (TimeStamp.GetCurTimeStamp() + long.Parse(tokenvalues[1].Value)).ToString(); } }
private bool GetRequestToken(string customKey, string customSecret) { string url = "https://open.t.qq.com/cgi-bin/request_token"; List <Parameter> parameters = new List <Parameter>(); OauthKey oauthKey = new OauthKey(); oauthKey.customKey = customKey; oauthKey.customSecrect = customSecret; oauthKey.callbackUrl = baseurl + "/top/microblog/record1.aspx?typ=qq"; QWeiboRequest request = new QWeiboRequest(); return(ParseToken(request.SyncRequest(url, "GET", oauthKey, parameters, null))); }
protected void Button5_Click(object sender, EventArgs e) { string sql = "SELECT * FROM TopMicroBlogAccount WHERE nick = '" + nick + "'"; DataTable dt = utils.ExecuteDataTable(sql); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["typ"].ToString() == "qq") { //发送微博 List <Parameter> parameters = new List <Parameter>(); parameters.Add(new Parameter("content", "测试微博自动发送")); //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = dt.Rows[i]["tokenKey"].ToString(); oauthKey.tokenSecrect = dt.Rows[i]["tokenSecrect"].ToString(); //图片信息 List <Parameter> files = new List <Parameter>(); QWeiboRequest request = new QWeiboRequest(); int nKey = 0; if (request.AsyncRequest("http://open.t.qq.com/api/t/add", "POST", oauthKey, parameters, files, new AsyncRequestCallback(RequestCallback), out nKey)) { //textOutput.Text = "请求中..."; } else { //textOutput.Text = "请求失败..."; } } else if (dt.Rows[i]["typ"].ToString() == "sina") { //oAuthSina oauth = new oAuthSina(); //oauth.appKey = "1421367737"; //oauth.appSecret = "2be4da41eb329b6327b7b2ac56ffbe6e"; //oauth.token = dt.Rows[i]["tokenKey"].ToString(); //oauth.tokenSecret = dt.Rows[i]["tokenSecrect"].ToString(); //string url = "http://api.t.sina.com.cn/statuses/update.xml?"; //string result = oauth.RequestWithPicture(oAuthSina.Method.POST, url, "status=微博自动发送啊啊啊啊啊"); //Response.Write(result); } } }
/// <summary> /// 取得AccessToken /// </summary> /// <param name="customKey"></param> /// <param name="customSecret"></param> /// <param name="requestToken"></param> /// <param name="requestTokenSecrect"></param> /// <param name="verify"></param> /// <returns></returns> private bool GetAccessToken(string customKey, string customSecret, string requestToken, string requestTokenSecrect, string verify) { string url = "https://open.t.qq.com/cgi-bin/access_token"; List <Parameter> parameters = new List <Parameter>(); OauthKey oauthKey = new OauthKey(); oauthKey.customKey = customKey; oauthKey.customSecret = customSecret; oauthKey.tokenKey = requestToken; oauthKey.tokenSecret = requestTokenSecrect; oauthKey.verify = verify; QWeiboRequest request = new QWeiboRequest(); return(ParseToken(request.SyncRequest(url, "GET", oauthKey, parameters, null))); }
public ApiHelper(OauthKey oauthKey) { //不是用默认代理 IsUseDefaultProxy = false; Config.MyOauthKey = oauthKey; #region //var postData = string.Format("{0}username={1}&password={2}", UrlType.GetToken, oauthKey.Username, oauthKey.Passwod); //var json = this.GetHtmlNoProxy(postData); //var result = JsonHelper.JsonToModel<JsonResult<Token>>(json); //if (result.data != null) //{ // Config.MyOauthKey.Uid = result.data.uid; // Config.MyOauthKey.TokenKey = result.data.token; //} #endregion }
/// <summary> /// Post /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bntPost_Click(object sender, EventArgs args) { pgbPost.Value = 0; pgbPost.Maximum = ds_media.Tables[0].Rows.Count; for (int idx = 0; idx < ds_media.Tables[0].Rows.Count; idx++) { String mediaPublishId = ds_media.Tables[0].Rows[idx]["发布编号"].ToString(); setMediaPublishStatus(mediaPublishId, "发行中"); string content = ds_media.Tables[0].Rows[idx]["名称"].ToString() + ds_media.Tables[0].Rows[idx]["发行期号"].ToString() + "[" + ds_media.Tables[0].Rows[idx]["发行日期"].ToString() + "]\r\n" + ds_media.Tables[0].Rows[idx]["文本内容"].ToString(); string picpath = ds_media.Tables[0].Rows[idx]["本地图片"].ToString(); try { OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecret = appSecret; oauthKey.tokenKey = accessKey; oauthKey.tokenSecret = accessSecret; ///发送带图片微博 t twit = new t(oauthKey, "json"); UTF8Encoding utf8 = new UTF8Encoding(); string ret = twit.add_pic(utf8.GetString(utf8.GetBytes(content)), utf8.GetString(utf8.GetBytes("127.0.0.1")), utf8.GetString(utf8.GetBytes("")), utf8.GetString(utf8.GetBytes("")), utf8.GetString(utf8.GetBytes(picpath)) ); setMediaPublishStatus(mediaPublishId, "发行完"); } catch (Exception ex) { setMediaPublishStatus(mediaPublishId, "未发行"); NCLogger.GetInstance().WriteExceptionLog(ex); } } }
protected void BtnSend_Click(object sender, EventArgs e) { GetAccessToken(appKey, appSecret, tokenKey, tokenSecret, Session["Verify"].ToString()); accessKey = tokenKey; accessSecret = tokenSecret; OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecret = appSecret; oauthKey.tokenKey = accessKey; oauthKey.tokenSecret = accessSecret; t twit = new t(oauthKey, "json"); string ret = twit.add_pic(TbText.Text, "127.0.0.1", "", "", Server.MapPath("~/" + Pic.Url)); Response.Write(ret); }
//获取听众 protected void Unnamed1_Click(object sender, EventArgs e) { GetAccessToken(appKey, appSecret, tokenKey, tokenSecret, Session["Verify"].ToString()); accessKey = tokenKey; accessSecret = tokenSecret; OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecret = appSecret; oauthKey.tokenKey = accessKey; oauthKey.tokenSecret = accessSecret; friends friends = new friends(oauthKey, "json"); string data = friends.fanslist(10, 0); Audience weibo = YK.Common.JsonHelper.ParseFormByJson <Audience>(data); GridView1.DataSource = weibo.data.info; GridView1.DataBind(); }
/// <summary> /// 发送微博消息 /// </summary> /// <param name="nick"></param> /// <param name="content"></param> /// <param name="filepath"></param> /// <param name="index"></param> /// <param name="key"></param> /// <param name="secret"></param> public void SendMicroBlog(string nick, string content, string filepath, string key, string secret) { string appKey = "d3225497956249cbb13a7cb7375d62bd"; string appSecret = "6cf7a3274cb676328e77dff3e203061d"; //发送微博 List <Parameter> parameters = new List <Parameter>(); parameters.Add(new Parameter("content", content)); //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = key; oauthKey.tokenSecrect = secret; Console.Write(filepath + "---sending...\r\n"); //图片信息 List <Parameter> files = new List <Parameter>(); if (filepath != "") { files.Add(new Parameter("pic", DownPic(filepath))); //files.Add(new Parameter("pic", filepath)); } Console.Write("send weibo msg...[" + filepath + "]-[" + content + "]\r\n"); QWeiboRequest request = new QWeiboRequest(); int nKey = 0; if (request.AsyncRequest("http://open.t.qq.com/api/t/add_pic", "POST", oauthKey, parameters, files, new AsyncRequestCallback(RequestCallback), out nKey)) { } }
private void listen(string uid, string listento, string tokenKey, string tokenSecret) { string appKey = "d3225497956249cbb13a7cb7375d62bd"; string appSecret = "6cf7a3274cb676328e77dff3e203061d"; //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = tokenKey; oauthKey.tokenSecrect = tokenSecret; //关注对方 QWeiboRequest request = new QWeiboRequest(); int nKey = 0; List <Parameter> parameters = new List <Parameter>(); parameters.Add(new Parameter("name", listento)); if (request.AsyncRequest("http://open.t.qq.com/api/friends/add", "POST", oauthKey, parameters, null, new AsyncRequestCallback(RequestCallbackListen), out nKey)) { } //记录日志 string sql = "INSERT INTO TopMicroBlogListen (uid, listen) VALUES ('" + uid + "', '" + listento + "')"; utils.ExecuteNonQuery(sql); //记录操作日志 sql = "INSERT INTO TopMicroBlogNumLog (uid, typ, num, bak) VALUES ('" + listento + "', 'deduct', -1, '" + uid + "')"; utils.ExecuteNonQuery(sql); //减少积分 sql = "UPDATE TopMicroBlogAccount SET score = score - 1 WHERE uid = '" + listento + "'"; utils.ExecuteNonQuery(sql); //Response.Write("【" + uid + "】收听【" + listento + "】成功"); }
protected void Page_Load(object sender, EventArgs e) { //参数初始化 baseurl = "http://www.7fshop.com"; Common.Cookie cookie1 = new Common.Cookie(); string taobaoNick = cookie1.getCookie("nick"); //过期判断 if (string.IsNullOrEmpty(taobaoNick)) { Response.Write("<script>parent.location.href='http://container.open.taobao.com/container?appkey=12159997'</script>"); Response.End(); return; } Rijndael_ encode = new Rijndael_("tetesoft"); string nick = encode.Decrypt(taobaoNick); string typ = utils.NewRequest("typ", utils.RequestType.QueryString); string verify = string.Empty; if (typ == "qq") { appKey = "d3225497956249cbb13a7cb7375d62bd"; appSecret = "6cf7a3274cb676328e77dff3e203061d"; tokenKey = utils.NewRequest("oauth_token", utils.RequestType.QueryString); tokenSecret = Session["tokenSecret"].ToString(); verify = utils.NewRequest("oauth_verifier", utils.RequestType.QueryString); //获取账户信息 GetAccessToken(appKey, appSecret, tokenKey, tokenSecret, verify); //发送微博 List <Parameter> parameters = new List <Parameter>(); //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = tokenKey; oauthKey.tokenSecrect = tokenSecret; //图片信息 List <Parameter> files = new List <Parameter>(); QWeiboRequest request = new QWeiboRequest(); int nKey = 0; if (request.AsyncRequest("http://open.t.qq.com/api/user/info", "POST", oauthKey, parameters, files, new AsyncRequestCallback(RequestCallback), out nKey)) { //textOutput.Text = "请求中..."; } string sql = "SELECT COUNT(*) FROM TopMicroBlogAccount WHERE nick = '" + nick + "' AND uid='" + weiboName + "' AND typ = 'qq'"; string count = utils.ExecuteString(sql); if (count == "0") { //写入数据库 sql = "INSERT INTO TopMicroBlogAccount (nick, uid, typ, tokenKey, tokenSecrect) VALUES ('" + nick + "', '" + weiboName + "', 'qq', '" + tokenKey + "', '" + tokenSecret + "')"; utils.ExecuteNonQuery(sql); } } else if (typ == "sina") { tokenKey = Session["oauth_token"].ToString(); tokenSecret = Session["oauth_token_secret"].ToString(); verify = utils.NewRequest("oauth_verifier", utils.RequestType.QueryString); HttpGet httpRequest = HttpRequestFactory.CreateHttpRequest(Method.GET) as HttpGet; httpRequest.AppKey = "1421367737"; httpRequest.AppSecret = "2be4da41eb329b6327b7b2ac56ffbe6e"; httpRequest.Token = tokenKey; httpRequest.TokenSecret = tokenSecret; httpRequest.Verifier = verify; httpRequest.GetAccessToken(); tokenKey = httpRequest.Token; tokenSecret = httpRequest.TokenSecret; weiboName = httpRequest.UserId; string sql = "SELECT COUNT(*) FROM TopMicroBlogAccount WHERE nick = '" + nick + "' AND uid='" + weiboName + "' AND typ = 'sina'"; string count = utils.ExecuteString(sql); if (count == "0") { sql = "INSERT INTO TopMicroBlogAccount (nick, uid, typ, tokenKey, tokenSecrect) VALUES ('" + nick + "', '" + weiboName + "', 'sina', '" + tokenKey + "', '" + tokenSecret + "')"; utils.ExecuteNonQuery(sql); } } //Response.Write(sql); //跳转 Response.Redirect("weiboindex.aspx"); }
private void SendMicroBlog(string nick, string content, string filepath, string index) { //过滤过长的内容 if (content.Length > 140) { content = content.Substring(0, 140); } string appKey = "d3225497956249cbb13a7cb7375d62bd"; string appSecret = "6cf7a3274cb676328e77dff3e203061d"; string sql = "SELECT * FROM TopMicroBlogAccount WHERE nick = '" + nick + "'"; DBSql db = new DBSql(); DataTable dt = db.GetTable(sql); textBox1.AppendText("\r\n" + dt.Rows.Count.ToString()); for (int i = 0; i < dt.Rows.Count; i++) { try { if (dt.Rows[i]["typ"].ToString() == "qq") { //MessageBox.Show(content); //发送微博 List <Parameter> parameters = new List <Parameter>(); parameters.Add(new Parameter("content", content)); //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = dt.Rows[i]["tokenKey"].ToString(); oauthKey.tokenSecrect = dt.Rows[i]["tokenSecrect"].ToString(); //图片信息 List <Parameter> files = new List <Parameter>(); if (filepath != "") { files.Add(new Parameter("pic", DownPic(filepath))); } QWeiboRequest request = new QWeiboRequest(); int nKey = 0; if (request.AsyncRequest("http://open.t.qq.com/api/t/add_pic", "POST", oauthKey, parameters, files, new AsyncRequestCallback(RequestCallback), out nKey)) { //textOutput.Text = "请求中..."; } sql = "UPDATE TopMicroBlogAuto SET num" + index + " = num" + index + " + 1 WHERE nick = '" + dt.Rows[i]["nick"].ToString() + "'"; db.ExecSql(sql); textBox1.AppendText("\r\n" + sql); sql = "INSERT INTO TopMicroBlogSendLog (result, nick, uid, typ, content, auto) VALUES ('','" + nick + "','" + dt.Rows[i]["uid"].ToString() + "','qq','" + content + "','" + index + "')"; db.ExecSql(sql); textBox1.AppendText("\r\nqq-" + sql); } else if (dt.Rows[i]["typ"].ToString() == "sina") { string url = string.Empty; string result = string.Empty; HttpPost httpRequest = HttpRequestFactory.CreateHttpRequest(Method.POST) as HttpPost; httpRequest.AppKey = "1421367737"; httpRequest.AppSecret = "2be4da41eb329b6327b7b2ac56ffbe6e"; httpRequest.Token = dt.Rows[i]["tokenKey"].ToString(); httpRequest.TokenSecret = dt.Rows[i]["tokenSecrect"].ToString(); if (filepath != "") { url = "http://api.t.sina.com.cn/statuses/upload.xml?"; result = httpRequest.RequestWithPicture(url, "status=" + HttpUtility.UrlPathEncode(content.Replace("=", "")), DownPic(filepath)); //result = httpRequest.Request(url, "status=" + HttpUtility.UrlEncode(content,Encoding.UTF8)); } else { url = "http://api.t.sina.com.cn/statuses/update.xml?"; result = httpRequest.Request(url, "status=" + HttpUtility.UrlEncode(content, Encoding.UTF8)); } sql = "UPDATE TopMicroBlogAuto SET num" + index + " = num" + index + " + 1 WHERE nick = '" + dt.Rows[i]["nick"].ToString() + "'"; db.ExecSql(sql); textBox1.AppendText("\r\n" + sql); sql = "INSERT INTO TopMicroBlogSendLog (result, nick, uid, typ, content, auto) VALUES ('','" + nick + "','" + dt.Rows[i]["uid"].ToString() + "','sina','" + content + "','" + index + "')"; db.ExecSql(sql); textBox1.AppendText("\r\nsina-" + sql); } } catch (Exception e) { textBox1.AppendText("\r\n" + e.Message); textBox1.AppendText("\r\n" + e.StackTrace); continue; } } }
/// <summary> /// 媒体连接测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTest_Click(object sender, EventArgs ex) { if (dataGridView1.SelectedRows.Count > 0) { string mediaType = cmbMediaType.Text; string mediaUrl = txtMediaURL.Text; string appKey = txtAppKey.Text; string appPassword = txtAppPassword.Text; string user = txtUserName.Text; string password = txtPassword.Text; string content = txtOther.Text; string pic = txtTestImage.Text; if (File.Exists(pic)) { switch (mediaType) { case "TENCENT": FormQWeiboLogin LoginDlg = new FormQWeiboLogin(appKey, appPassword, user, password); LoginDlg.ShowDialog(); if (LoginDlg.Comfirm) { OauthKey oauthKey = new OauthKey(); oauthKey.customKey = LoginDlg.AppKey; oauthKey.customSecret = LoginDlg.AppSecret; oauthKey.tokenKey = LoginDlg.AccessKey; oauthKey.tokenSecret = LoginDlg.AccessSecret; ///发送带图片微博 t twit = new t(oauthKey, "json"); UTF8Encoding utf8 = new UTF8Encoding(); string ret = twit.add_pic(utf8.GetString(utf8.GetBytes(content)), utf8.GetString(utf8.GetBytes("127.0.0.1")), utf8.GetString(utf8.GetBytes("")), utf8.GetString(utf8.GetBytes("")), utf8.GetString(utf8.GetBytes(pic)) ); string msg = NCMessage.GetInstance(db.Language).GetMessageById("CM0057I", db.Language); MessageBox.Show(msg); } break; case "WORDPRESS": IMetaWeblog metaWeblog = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog)); XmlRpcClientProtocol clientProtocol = (XmlRpcClientProtocol)metaWeblog; clientProtocol.Url = mediaUrl; string picURL = null; string filename = pic; if (File.Exists(filename)) { FileData fileData = default(FileData); fileData.name = Path.GetFileName(filename); fileData.type = Path.GetExtension(filename); try { FileInfo fi = new FileInfo(filename); using (BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read))) { fileData.bits = br.ReadBytes((int)fi.Length); } UrlData urlData = metaWeblog.newMediaObject("6", user, password, fileData); picURL = urlData.url; } catch (Exception exc) { NCLogger.GetInstance().WriteExceptionLog(exc); } } Post newBlogPost = default(Post); newBlogPost.title = content; newBlogPost.description = ""; newBlogPost.categories = new string[1]; newBlogPost.categories[0] = cmbCategry.Text; newBlogPost.dateCreated = System.DateTime.Now; if (picURL != null) { newBlogPost.description += "<br><img src='" + picURL + "'/>"; } try { string result = metaWeblog.newPost("6", user, password, newBlogPost, true); } catch (Exception ex2) { NCLogger.GetInstance().WriteExceptionLog(ex2); } break; case "FACEBOOK": var fbLoginDlg = new FormFacebookLogin(appKey, user, password); fbLoginDlg.ShowDialog(); if (fbLoginDlg.FacebookOAuthResult != null && fbLoginDlg.FacebookOAuthResult.IsSuccess) { string _accessToken = fbLoginDlg.FacebookOAuthResult.AccessToken; var fb = new FacebookClient(_accessToken); // make sure to add event handler for PostCompleted. fb.PostCompleted += (o, e) => { // incase you support cancellation, make sure to check // e.Cancelled property first even before checking (e.Error!=null). if (e.Cancelled) { // for this example, we can ignore as we don't allow this // example to be cancelled. // you can check e.Error for reasons behind the cancellation. var cancellationError = e.Error; } else if (e.Error != null) { // error occurred this.BeginInvoke(new MethodInvoker( () => { MessageBox.Show(e.Error.Message); })); } else { // the request was completed successfully // make sure to be on the right thread when working with ui. this.BeginInvoke(new MethodInvoker( () => { //MessageBox.Show("Picture uploaded successfully"); Application.DoEvents(); })); } }; dynamic parameters = new ExpandoObject(); parameters.message = content; parameters.source = new FacebookMediaObject { ContentType = "image/jpeg", FileName = Path.GetFileName(pic) }.SetValue(File.ReadAllBytes(pic)); fb.PostAsync("me/photos", parameters); } break; case "TWITTER": TwitterService service = new TwitterService(appKey, appPassword); FormTwitterLogin form = new FormTwitterLogin(db, service); if (form.ShowDialog() == DialogResult.OK) { SendTweetWithMediaOptions sendOptions = new SendTweetWithMediaOptions(); sendOptions.Images = new Dictionary <string, Stream>(); sendOptions.Images.Add(Path.GetFileName(pic), new FileStream(pic, FileMode.Open, FileAccess.Read)); if (content.Length > 70) { content = content.Substring(0, 70); } sendOptions.Status = content; if (service.SendTweetWithMedia(sendOptions) != null) { string msg = NCMessage.GetInstance(db.Language).GetMessageById("CM0057I", db.Language); MessageBox.Show(msg); } } break; case "LINKEDIN": OAuth1 _OAuthLinkedin = new OAuth1(db); _OAuthLinkedin.Settings_Provider = "Linkedin"; _OAuthLinkedin.Settings_ConsumerKey = appKey; _OAuthLinkedin.Settings_ConsumerSecret = appPassword; _OAuthLinkedin.Settings_AccessToken_page = "https://api.linkedin.com/uas/oauth/accessToken"; _OAuthLinkedin.Settings_Authorize_page = "https://api.linkedin.com/uas/oauth/authorize"; _OAuthLinkedin.Settings_RequestToken_page = "https://api.linkedin.com/uas/oauth/requestToken"; _OAuthLinkedin.Settings_Redirect_URL = "http://www.chojo.co.jp/"; _OAuthLinkedin.Settings_User_agent = "CJW"; _OAuthLinkedin.Settings_OAuth_Realm_page = "https://api.linkedin.com/"; _OAuthLinkedin.Settings_GetProfile_API_page = "https://api.linkedin.com/v1/people/~/"; _OAuthLinkedin.Settings_StatusUpdate_API_page = "https://api.linkedin.com/v1/people/~/current-status"; _OAuthLinkedin.getRequestToken(); _OAuthLinkedin.authorizeToken(); String accessToken = _OAuthLinkedin.getAccessToken(); try { string ret = _OAuthLinkedin.APIWebRequest("POST", _OAuthLinkedin.Settings_StatusUpdate_API_page, pic); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; xml += "<current-status>" + txtOther.Text + "<img src =" + ret + "/>" + "</current-status>"; _OAuthLinkedin.APIWebRequest("PUT", _OAuthLinkedin.Settings_StatusUpdate_API_page, xml); } catch (Exception exp) { MessageBox.Show(exp.Message); } break; case "MSN": case "GOOGLE": case "YAHOO": PROVIDER_TYPE provider_type = (PROVIDER_TYPE)Enum.Parse(typeof(PROVIDER_TYPE), mediaType); setConfigure(user, password, mediaType); FormAuthSocialLogin loginForm = new FormAuthSocialLogin(db, provider_type, socialAuthManager); if (loginForm.ShowDialog() == DialogResult.OK) { string msgs = HttpUtility.UrlEncode(content); string endpoint = mediaUrl + msgs; string body = String.Empty; //byte[] reqbytes = new ASCIIEncoding().GetBytes(body); byte[] reqbytes = File.ReadAllBytes(pic); Dictionary <string, string> headers = new Dictionary <string, string>(); //headers.Add("contentType", "application/x-www-form-urlencoded"); headers.Add("contentType", "image/jpeg"); headers.Add("FileName", Path.GetFileName(pic)); var response = socialAuthManager.ExecuteFeed( endpoint, TRANSPORT_METHOD.POST, provider_type, reqbytes, headers ); } break; } } else { string msg = NCMessage.GetInstance(db.Language).GetMessageById("CM0058I", db.Language); MessageBox.Show(msg); } } else { string msg = NCMessage.GetInstance(db.Language).GetMessageById("CM0050I", db.Language); MessageBox.Show(msg); } }
protected void Page_Load(object sender, EventArgs e) { Common.Cookie cookie1 = new Common.Cookie(); string nick = cookie1.getCookie("nickweibo"); string appKey = "d3225497956249cbb13a7cb7375d62bd"; string appSecret = "6cf7a3274cb676328e77dff3e203061d"; tokenKey = utils.NewRequest("oauth_token", utils.RequestType.QueryString); tokenSecret = Session["tokenSecret"].ToString(); string verify = utils.NewRequest("oauth_verifier", utils.RequestType.QueryString); //获取账户信息 GetAccessToken(appKey, appSecret, tokenKey, tokenSecret, verify); Common.Cookie cookie = new Common.Cookie(); cookie.setCookie("tokenKey", tokenKey, 999999); cookie.setCookie("tokenSecret", tokenSecret, 999999); List <Parameter> parameters = new List <Parameter>(); List <Parameter> files = new List <Parameter>(); //身份验证 OauthKey oauthKey = new OauthKey(); oauthKey.customKey = appKey; oauthKey.customSecrect = appSecret; oauthKey.tokenKey = tokenKey; oauthKey.tokenSecrect = tokenSecret; QWeiboRequest request = new QWeiboRequest(); int nKey = 0; if (request.AsyncRequest("http://open.t.qq.com/api/statuses/broadcast_timeline", "POST", oauthKey, parameters, files, new AsyncRequestCallback(RequestCallback), out nKey)) { //textOutput.Text = "请求中..."; } cookie.setCookie("uid", weiboName, 999999); //insert sql string sql = "SELECT COUNT(*) FROM TopMicroBlogAccount WHERE typ = 'qq' AND uid = '" + weiboName + "'"; string count = utils.ExecuteString(sql); if (count == "0") { if (weiboName != "") { //写入数据库 sql = "INSERT INTO TopMicroBlogAccount (nick, uid, typ, tokenKey, tokenSecrect) VALUES ('" + nick + "', '" + weiboName + "', 'qq', '" + tokenKey + "', '" + tokenSecret + "')"; utils.ExecuteNonQuery(sql); //赠送积分 //记录操作日志 sql = "INSERT INTO TopMicroBlogNumLog (uid, typ, num) VALUES ('" + weiboName + "', 'reg', 5)"; utils.ExecuteNonQuery(sql); //增加积分 sql = "UPDATE TopMicroBlogAccount SET score = score + 5 WHERE uid = '" + weiboName + "'"; utils.ExecuteNonQuery(sql); } Response.Redirect("menu.aspx"); } else { string num = new Random(int.Parse(DateTime.Now.Second.ToString())).Next(0, 100).ToString(); string str = "#互听##互听工具#【特特互听】我在用的免费互听工具,可以安全迅速的增加听众~~(" + num + ")..http://weibo.tetesoft.com"; //string score = utils.ExecuteString("SELECT score FROM TopMicroBlogAccount WHERE uid = '" + weiboName + "'"); sql = "SELECT * FROM TopMicroBlogAccount WHERE uid = '" + weiboName + "'"; DataTable dtUser = utils.ExecuteDataTable(sql); if (dtUser.Rows.Count == 0) { return; } string score = dtUser.Rows[0]["score"].ToString(); tokenKey = dtUser.Rows[0]["tokenKey"].ToString(); tokenSecret = dtUser.Rows[0]["tokenSecrect"].ToString(); if (int.Parse(score) > 20) { //登录增加20个粉丝 sql = "SELECT TOP 20 * FROM TopMicroBlogAccount WHERE typ = 'qq' AND score > 0 AND uid <> '' ORDER BY NEWID()"; DataTable dt = utils.ExecuteDataTable(sql); for (int i = 0; i < dt.Rows.Count; i++) { listen(dt.Rows[i]["uid"].ToString(), weiboName, dt.Rows[i]["tokenKey"].ToString(), dt.Rows[i]["tokenSecrect"].ToString()); } } SendMessage(str); } }