模拟腾讯返回的json数据
$(document).ready(function () { $("#SubmitButton").click(function () { alert("ajax准备开始"); var wxJson = { "authorization_info": { "authorizer_appid": "wxf8b4f85f3a794e77", "authorizer_access_token": "QXjUqNqfYVH0yBE1iI_7vuN_9gQbpjfK7hYwJ3P7xOa88a89-Aga5x1NMYJyB8G2yKt1KCl0nPC3W9GJzw0Zzq_dBxc8pxIGUNi_bFes0qM", "expires_in": 7200, "authorizer_refresh_token": "dTo-YCXPL4llX-u1W1pPpnp8Hgm4wpJtlR6iV0doKdY", "func_info": [ { "funcscope_category": { "id": 3 } }, { "funcscope_category": { "id": 2 } }, { "funcscope_category": { "id": 4 } } ] } }; var fff= JSON.stringify(wxJson); var objAAA = ""; $.ajax({ url: "/SysClient/BusinessWxAuthorizationTest1/OAuthCallbackTest1.aspx", data: { wxJson: fff, auth_code: "123kkk", }, //dataType: "json", success: function (obj) { alert(obj); objAAA = eval('(' + obj + ')'); if (objAAA.code == "1") { alert("成功"); alert(objAAA.data.redirectUrl); return; } else if (objAAA.code == "0") { alert("服务器返回来一个失败,请检查语句。" + obj.msg); return; } alert("成功了,返回:" + obj); return; }, error: function () { alert("程序失败了,请调试检查"); } }) alert("ajax完成"); }) })
//---------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e) { //模拟腾讯返回数据,进行处理 string wxJson = Request["wxJson"]; //string auth_code = Request["auth_code"]; //授权方appid string authorizer_appid = string.Empty; //授权方接口调用凭据 string authorizer_access_token = string.Empty; //有效期(在授权的公众号或小程序具备API权限时,才有此返回值) int expires_in; //接口调用凭据刷新令牌 string authorizer_refresh_token = string.Empty; StringBuilder sb = new StringBuilder(); var queryAuthResultEntity = ResultJsonHelper.GetResult<QueryAuthResult>(wxJson); authorizer_appid = queryAuthResultEntity.authorization_info.authorizer_appid; authorizer_access_token = queryAuthResultEntity.authorization_info.authorizer_access_token; expires_in = queryAuthResultEntity.authorization_info.expires_in; authorizer_refresh_token = queryAuthResultEntity.authorization_info.authorizer_refresh_token; foreach (var item in queryAuthResultEntity.authorization_info.func_info) { var idInt = (int)item.funcscope_category.id; sb.Append(idInt + ","); } string sbStr = sb.ToString().Substring(0, sb.ToString().Length - 1); }