123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using LYFZ.Weixin.SDK;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace LYFZ.WeixinServers
- {
- public partial class AuthorizeCallback : System.Web.UI.Page
- {
- public string retText = "";
- LYFZ.WeixinServiceDate.DAL.DAL_Authorization_info Authorization_infoDal = new WeixinServiceDate.DAL.DAL_Authorization_info();
- protected void Page_Load(object sender, EventArgs e)
- {
-
-
- this.Title = "微信公众号授权失败";
- retText = this.Title + ",请在管理软件中重新发起授权";
- if (!IsPostBack)
- {
- if (this.Request.QueryString["auth_code"] != null && this.Request.QueryString["expires_in"] != null)
- {
-
- bool AuthorizeSuccess = false;
-
-
- string JMGDomainName = "";
- string AuthorizedAPPID = "";
- if (this.Request.QueryString["authorizeParameter"] != null)
- {
-
- string[] authorizeParameters = LYFZ.WinAPI.SDKSecurity.Decode(Request["authorizeParameter"].ToString().Trim()).Split('&');
- AuthorizedAPPID = authorizeParameters[0];
- JMGDomainName = authorizeParameters[1];
- }
- try
- {
- LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = Global.GetCustomerModel(JMGDomainName);
- if (cusModel != null && cusModel.ID > 0 && cusModel.AppID.Trim().ToLower() == AuthorizedAPPID.Trim().ToLower())
- {
- LYFZ.WeixinServiceDate.Model.Model_Authorization_info Authorization_infoModel = new LYFZ.WeixinServiceDate.Model.Model_Authorization_info();
- int tempCount = 0;
- while (tempCount<10)
- {
- tempCount++;
- System.Threading.Thread.Sleep(500);
- bool isExistsAuthorization_info = Authorization_infoDal.Exists("authorizer_appid", AuthorizedAPPID);
- if (isExistsAuthorization_info)
- {
- Authorization_infoModel = (LYFZ.WeixinServiceDate.Model.Model_Authorization_info)Authorization_infoDal.GetModelObject("authorizer_appid", AuthorizedAPPID);
- Authorization_infoModel.CompanyName = cusModel.CompanyName;
- Authorization_infoModel.JMGDomainName = cusModel.JMGDomainName;
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("邦定接口:CompanyName=" + Authorization_infoModel.CompanyName + " &JMGDomainName=" + Authorization_infoModel.JMGDomainName, "-2", Global.LogsDongleDomainList);
- AuthorizeSuccess = Authorization_infoDal.Update(Authorization_infoModel);
- if (!AuthorizeSuccess)
- {
- retText = this.Title + ",请点击“<a href=\"Authorize.aspx?appid=" + AuthorizedAPPID + "&yuname=" + Request["yuname"].ToString().Trim() + "\">重新授权</a>”<br />失败原因:更新数据库操作失败";
- }
- else {
- Global.AddAuthorizedAPPIDHand(Authorization_infoModel);
- Global.UpdateAuthorizationInfoDaTable(Authorization_infoModel.Authorizer_appid, Authorization_infoModel);
- }
- break;
- }
- else
- {
- retText = this.Title + ",失败原因:请求授权公众号APPID“" + AuthorizedAPPID + "”与管理软件中配置的公众号APPID不匹配";
- }
- }
-
- }
- else
- {
- retText = this.Title + ",失败原因:请求授权公众号为非法公众号";
- }
- }
- catch (Exception ex)
- {
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("解析返回授权信息时出错:" + ex.Message, "-2", Global.LogsDongleDomainList);
- }
- if (AuthorizeSuccess)
- {
- this.Title = "微信公众号授权成功";
- retText = this.Title + ",可以关闭此页";
- }
- }
- else
- {
- retText = this.Title + ",授权请求无效,请在管理软件中重新发起授权";
- }
- }
- else
- {
- retText = this.Title + ",授权请求已过期";
- }
- this.h3Info.InnerHtml = retText;
- }
- }
- }
|