public override string OnUpdateAuthorizedRequest(RequestMessageUpdateAuthorized requestMessage) { string autherAppId = requestMessage.AuthorizerAppid; LogService.GetInstance().AddLog("OnUpdateAuthRequest", null, "auther appid is " + autherAppId, "", "info"); var appAuthInfo = db.AppAuths.FirstOrDefault(c => c.AuthorizerAppId == autherAppId); if (appAuthInfo != null) { appAuthInfo.LastUpdateOn = DateTime.Now; appAuthInfo.Authorized = true; appAuthInfo.AuthorizerAppId = requestMessage.AuthorizerAppid; appAuthInfo.Code = requestMessage.AuthorizationCode; appAuthInfo.ExpiredTime = requestMessage.AuthorizationCodeExpiredTime; db.SaveChanges(); //todo: 增加authorizer的信息更新 } else { Console.WriteLine("can't find auth info for appid " + autherAppId); } return(base.OnUpdateAuthorizedRequest(requestMessage)); }
//<?xml version="1.0" encoding="utf-8"?> //<xml> // <ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName> // <FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName> // <CreateTime>1357986928</CreateTime> // <MsgType><![CDATA[text]]></MsgType> // <Content><![CDATA[中文]]></Content> // <MsgId>5832509444155992350</MsgId> //</xml> /// <summary> /// 获取XDocument转换后的IRequestMessageBase实例。 /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常 /// </summary> /// <returns></returns> public static IRequestMessageBase GetRequestEntity(XDocument doc, PostModel postModel = null) { RequestMessageBase requestMessage = null; RequestInfoType infoType; try { infoType = InfoTypeHelper.GetRequestInfoType(doc); switch (infoType) { case RequestInfoType.component_verify_ticket: requestMessage = new RequestMessageComponentVerifyTicket(); break; case RequestInfoType.unauthorized: /* * <xml> * <AppId>第三方平台appid</AppId> * <CreateTime>1413192760</CreateTime> * <InfoType>unauthorized</InfoType> * <AuthorizerAppid>公众号appid</AuthorizerAppid> * </xml> */ requestMessage = new RequestMessageUnauthorized(); break; case RequestInfoType.authorized: /* * <xml> * <AppId>第三方平台appid</AppId> * <CreateTime>1413192760</CreateTime> * <InfoType>authorized</InfoType> * <AuthorizerAppid>公众号appid</AuthorizerAppid> * <AuthorizationCode>授权码(code)</AuthorizationCode> * <AuthorizationCodeExpiredTime>过期时间</AuthorizationCodeExpiredTime> * </xml> */ requestMessage = new RequestMessageAuthorized(); break; case RequestInfoType.updateauthorized: requestMessage = new RequestMessageUpdateAuthorized(); break; default: throw new UnknownRequestMsgTypeException(string.Format("InfoType:{0} 在RequestMessageFactory中没有对应的处理程序!", infoType), new ArgumentOutOfRangeException()); //为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常 } EntityHelper.FillEntityWithXml(requestMessage, doc); } catch (ArgumentException ex) { throw new WeixinException(string.Format("RequestMessage转换出错!可能是InfoType不存在!,XML:{0}", doc.ToString()), ex); } return(requestMessage); }
/// <summary> /// 授权更新通知 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public virtual string OnUpdateAuthorizedRequest(RequestMessageUpdateAuthorized requestMessage) { return("success"); }
/// <summary> /// 授权更新通知 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public virtual string OnUpdateAuthorizedRequest(RequestMessageUpdateAuthorized requestMessage) { return "success"; }
public override string OnUpdateAuthorizedRequest(RequestMessageUpdateAuthorized requestMessage) { return(base.OnUpdateAuthorizedRequest(requestMessage)); }