123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 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 bAuthSuccess = false;
-
- string strAuthCode = this.Request.QueryString["auth_code"].ToString();
-
- int AuthCodeExpireIn = Convert.ToInt32(this.Request.QueryString["expires_in"].ToString());
-
- string strEntId = "";
-
- string strAppId = "";
-
- string strAppType = "";
-
- if (this.Request.QueryString["auth_parameters"] != null)
- {
- string[] AuthParameters = LYFZ.WinAPI.SDKSecurity.Decode(Request["auth_parameters"].ToString().Trim()).Split('&');
- strAppType = AuthParameters[0];
- strEntId = AuthParameters[1];
- strAppId = AuthParameters[2];
- }
- try
- {
-
- LoginModel.app_authorization model = GlobalCache.DalAppAuthorize.GetModel(strEntId, strAppId);
- if ( model != null )
- {
- model.authorize_status = 1;
- model.authorizer_access_token = strAuthCode;
- model.expires_in = AuthCodeExpireIn;
-
- bAuthSuccess = GlobalCache.DalAppAuthorize.UpdateEx(model.id, strAuthCode, AuthCodeExpireIn, 1);
- }
- else
- {
- model = new LoginModel.app_authorization();
- model.ent_id = strEntId;
- model.app_id = strAppId;
- model.app_type_name = strAppType;
- model.authorizer_access_token = strAuthCode;
- model.authorize_status = 1;
- model.create_time = DateTime.Now;
- model.expires_in = AuthCodeExpireIn;
- model.refresh_token_time = DateTime.Now.AddMilliseconds(AuthCodeExpireIn);
- model.update_time = DateTime.Now;
-
- bAuthSuccess = GlobalCache.DalAppAuthorize.Add(model, "id");
- }
- #if 参考
-
- LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = Global.GetCustomerModel(strEntId);
- if (cusModel != null && cusModel.ID > 0 && cusModel.AppID.Trim().ToLower() == strAppId.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", strAppId);
- if (isExistsAuthorization_info)
- {
- Authorization_infoModel = (LYFZ.WeixinServiceDate.Model.Model_Authorization_info)Authorization_infoDal.GetModelObject("authorizer_appid", strAppId);
- 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=" + strAppId + "&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“" + strAppId + "”与管理软件中配置的公众号APPID不匹配";
- }
- }
-
- }
- else
- {
- retText = this.Title + ",失败原因:请求授权公众号为非法公众号";
- }
- #endif
- }
- catch (Exception ex)
- {
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("解析返回授权信息时出错:" + ex.Message, "-2", Global.LogsDongleDomainList);
- }
- if (bAuthSuccess)
- {
- this.Title = "微信公众号授权成功";
- retText = this.Title + ",可以关闭此页";
- }
- }
- else
- {
- retText = this.Title + ",授权请求无效,请在管理软件中重新发起授权";
- }
- }
- else
- {
- retText = this.Title + ",授权请求已过期";
- }
- this.h3Info.InnerHtml = retText;
- }
- }
- }
|