protected void Page_Load(object sender, EventArgs e) { int appid = 100651351; string appkey = "e358f5d6c4c5cd822419911c13a18e73"; string server_name = "openapi.tencentyun.com";//"119.147.19.43"; string openid = Request.QueryString["openid"]; string openkey = Request.QueryString["openkey"]; string pf = Request.QueryString["pf"]; OpenApiV3 sdk = new OpenApiV3(appid, appkey); sdk.SetServerName(server_name); RstArray result = new RstArray(); //get_info接口 result = UserHelper.GetUserInfo(sdk, openid, openkey, pf); //测试 //Response.Write("<br>ret = " + result.Ret + "<br>msg = " + result.Msg); //Response.End(); string jsonString = result.Msg; QQInfoClass qq = JsonHelper.JsonDeserialize <QQInfoClass>(jsonString); string u = "qz"; string oId = openid; string aToken = openkey; string userNickName = HttpUtility.UrlEncode(qq.nickname); string userImage = HttpUtility.UrlEncode(qq.figureurl); Response.Redirect("OAuth.aspx?u=" + u + "&openId=" + oId + "&accessToken=" + aToken + "&name=" + userNickName + "&image=" + userImage); }
protected void GetQQImageButton_Click(object sender, EventArgs e) { if (this.AppID.Text.Trim() == "" || this.AppKey.Text.Trim() == "" || this.OpenIDBox.Text.Trim() == "" || this.AccessTokenBox.Text.Trim() == "") { this.ResultLabel.Text = "{ empty. }"; return; } int appid = Convert.ToInt32(this.AppID.Text.Trim()); string appkey = this.AppKey.Text.Trim(); string server_name = "openapi.tencentyun.com";//"119.147.19.43"; string openid = this.OpenIDBox.Text.Trim(); string openkey = this.AccessTokenBox.Text.Trim(); OpenApiV3 sdk = new OpenApiV3(appid, appkey); sdk.SetServerName(server_name); RstArray result = new RstArray(); //get_info接口 result = UserHelper.GetUserInfo(sdk, openid, openkey, "qzone"); //测试 //Response.Write("<br>ret = " + result.Ret + "<br>msg = " + result.Msg); string jsonString = result.Msg; QQInfoClass qq = JsonHelper.JsonDeserialize <QQInfoClass>(jsonString); string str = ""; OAuthInfo oauth = bll.GetOAuthByOpenId(openid); if (FixImageBox.Checked && oauth.OAuthID > 0) { int userId = oauth.UserID; UserInfo user = user_bll.GetUserByUserId(userId); user.UserNickName = qq.nickname; user.UserImage = qq.figureurl; //user.ModifyDate = DateTime.Now; bool success = user_bll.UpdateUser(user); if (success) { str = "{ " + user.UserImage + " }"; } else { str = "{ error. }"; } } this.ResultLabel.Text = str + "<br><br>" + jsonString; }
protected void GetQQImageButton_Click(object sender, EventArgs e) { if (this.AppID.Text.Trim() == "" || this.AppKey.Text.Trim() == "" || this.OpenIDBox.Text.Trim() == "" || this.AccessTokenBox.Text.Trim() == "") { this.ResultLabel.Text = "{ empty. }"; return; } int appid = Int32.Parse(this.AppID.Text.Trim()); string appkey = this.AppKey.Text.Trim(); string server_name = "openapi.tencentyun.com";//"119.147.19.43";// string openid = this.OpenIDBox.Text.Trim(); string openkey = this.AccessTokenBox.Text.Trim(); OpenApiV3 sdk = new OpenApiV3(appid, appkey); sdk.SetServerName(server_name); RstArray result = new RstArray(); result = GetUserInfo(sdk, openid, openkey, "qzone"); //Response.Write("<br>ret = " + result.Ret + "<br>msg = " + result.Msg); string qqStr = result.Msg; QQInfoClass qq = JsonHelper.JsonDeserialize <QQInfoClass>(qqStr); string userStr = ""; DataTable dt = OAuthAccess.GetOAuthByOpenId(openid); if (dt.Rows.Count > 0) { int userId = Int32.Parse(dt.Rows[0]["UserID"].ToString()); UserEntity user = UserAccess.GetUserById(userId); user.UserNickName = qq.nickname; user.UserImage = qq.figureurl; bool success = UserAccess.UpdateUser(user); if (success) { userStr = "{ " + user.UserImage + " }"; } else { userStr = "{ error. }"; } } this.ResultLabel.Text = userStr + "<br><br>" + qqStr; }