示例#1
0
 public static JSAPITicket GetJSAPITicket(WeChatPayConfig config,AccessToken oldToken,JSAPITicket oldTicket, out bool changed)
 {
     changed = false;
     JSAPITicket ticket = null;
     bool needGet = false;
     JSAPITicketRequest request = null;
     if(oldTicket==null)
     {
         needGet = true;
     }
     else
     {
         if(oldTicket.ExpiresTime<DateTime.Now)
         {
             needGet = true;
         }
     }
     if(needGet)
     {
         changed = true;
         bool tChanged = false;
         request = new JSAPITicketRequest(config);
         AccessToken token = WeChatPaymentWrapper.GetWeChatToken(config,oldToken,out tChanged);
         request.Access_Token = token;
         BaseResponse res = request.Execute();
         if(res!=null)
         {
             JSAPITicketResponse jsRes = (JSAPITicketResponse)res;
             ticket = jsRes.Ticket;
         }
     }
     return ticket;
 }
示例#2
0
 private static JSAPITicket RequestWeChatJsApiTicket()
 {
     JSAPITicket ticket = null;
     JSAPITicketRequest request = null;
     request = new JSAPITicketRequest(config);
     request.Access_Token = GetWeChatAccessToken();
     BaseResponse res = request.Execute();
     if (res != null)
     {
         JSAPITicketResponse jsRes = (JSAPITicketResponse)res;
         ticket = jsRes.Ticket;
     }
     if (ticket != null)
     {
         XMLUtil.SerializeObject(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatJSAPITicket.xml"), ticket);
     }
     return ticket;
 }