Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                HttpGet httpRequest = HttpRequestFactory.CreateHttpRequest(Method.GET) as HttpGet;
                if (Request["oauth_verifier"] != null)
                {
                    httpRequest.Token       = Session["oauth_token"].ToString();
                    httpRequest.TokenSecret = Session["oauth_token_secret"].ToString();
                    httpRequest.Verifier    = Request["oauth_verifier"];
                    httpRequest.GetAccessToken();
                    Session["oauth_token"]        = httpRequest.Token;
                    Session["oauth_token_secret"] = httpRequest.TokenSecret;
                    Session["oauth_user_id"]      = httpRequest.userid;

                    Response.Redirect("/Default.aspx");
                }
                if (Session["oauth_token"] != null)
                {
                    this.sinaButton.Text = "Á¬½Ó³É¹¦";
                    //this.Label4.Text = httpRequest.Request("http://api.t.sina.com.cn/users/show.xml?", "screen_name=0351netcn");
                }
            }
        }
    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");
    }