public override QzoneResourceSession Build(QzoneRequestResSetting setting)
 {
     try
     {
         var interactiveInfo = HttpSupplier.Get <QzoneAccessTokenInteractive, QzoneErrorResult>(new Uri(setting.RequestGetAccessTokenPtl()), new UrlParamConverter());
         var qzoneSession    = new QzoneResourceSession(HttpSupplier, new AccessToken(interactiveInfo.access_token))
         {
             ExpiresIn = long.Parse(interactiveInfo.expires_in)
             , AppId   = setting.AppId
         };
         var openIdInfo = HttpSupplier.Get <QzoneOpenIdResult, QzoneErrorResult>(new Uri(qzoneSession.RequestOpenIdPtl()), new CallbackConverter());
         qzoneSession.OpenId = openIdInfo.openid;
         return(qzoneSession);
     }
     catch (JsonResultException jException)
     {
         return(null);
     }
 }
 public TRes Request <TRes>(Uri uri) where TRes : IResource
 {
     try
     {
         return(HttpSupplier.Get <TRes, SinaErrorResult>(uri));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public TRes Request <TRes>(Uri uri) where TRes : IResource
 {
     try
     {
         return(HttpSupplier.Get <TRes, QzoneErrorResult>(uri));
     }
     catch (Exception)
     {
         return(default(TRes));
     }
 }
Example #4
0
 /// <summary>
 /// 在认证服务器上完成和认证服务器的交互,并且拿到AccessToken
 /// 根据文档,该Token可以在后续的访问资源中调用API使用,不过
 /// 该Token可能过期,但也可以实现<seealso cref="IForeverable"/>来实现新获取Session机制
 /// </summary>
 /// <param name="setting"></param>
 /// <returns></returns>
 public override WxResourceSession Build(WxRequestResSetting setting)
 {
     try
     {
         var interactiveInfo = HttpSupplier.Get <WxAccessTokenInteractive, WxErrorResult>(new Uri(setting.RequestGetAccessTokenPtl()));
         return(new WxResourceSession(HttpSupplier, new AccessToken(interactiveInfo.access_token), new RefrechToken(interactiveInfo.refresh_token))
         {
             OpenId = interactiveInfo.openid
         });
     }
     catch (JsonResultException jException)
     {
         return(null);
     }
 }