private static AccessToken RequestWeChatAccessToken()
 {
     AccessToken token = null;
     TokenRequest request = null;
     request = new TokenRequest(config);
     BaseResponse res = request.Execute();
     if (res != null)
     {
         AccessTokenResponse tokenRes = (AccessTokenResponse)res;
         if (tokenRes.Access_Token != null)
         {
             token = tokenRes.Access_Token;
         }
     }
     if(token!=null)
     {
         XMLUtil.SerializeObject(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatAccessToken.xml"), token);
     }
     return token;
 }
Beispiel #2
0
        public static AccessToken GetWeChatToken(WeChatPayConfig config, AccessToken oldToken,out bool changed)
        {
            changed = false;
            AccessToken token = null;
            TokenRequest request = null;
            bool needGet = false;
            if (oldToken==null)
            {
                needGet = true;
            }
            else
            {
                if(oldToken.ExpiresTime<DateTime.Now)
                {
                    needGet = true;
                }
            }

            if(needGet)
            {
                request = new TokenRequest(config);
                BaseResponse res = request.Execute();
                if (res != null)
                {
                    changed = true;
                    AccessTokenResponse tokenRes = (AccessTokenResponse)res;
                    if (tokenRes.Access_Token != null)
                    {
                        token = tokenRes.Access_Token;
                        oldToken = token;
                    }
                }
            }
            return token;
        }