Beispiel #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);
        }
Beispiel #2
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;
 }
        public static JSAPITicket GetWeChatJsApiTicket()
        {
            if(WeChatJsApiTicket==null || WeChatJsApiTicket.ExpiresTime < DateTime.Now)
            {
                WeChatJsApiTicket = RequestWeChatJsApiTicket();
            }

            return WeChatJsApiTicket;
        }
 static PersistentValueManager()
 {
     KMLogger.GetLogger().Info(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatPayConfig.xml"));
     KMLogger.GetLogger().Info(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatAccessToken.xml"));
     KMLogger.GetLogger().Info(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatJSAPITicket.xml"));
     config = XMLUtil.DeserializeXML<WeChatPayConfig>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatPayConfig.xml"));
     WeChatAccessToken = XMLUtil.DeserializeXML<AccessToken>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatAccessToken.xml"));
     WeChatJsApiTicket= XMLUtil.DeserializeXML<JSAPITicket>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Config\\WeChatJSAPITicket.xml"));
 }
Beispiel #5
0
        /// <summary>
        /// JSSDK Payment configure signature
        /// </summary>
        /// <param name="config"></param>
        /// <param name="nancestr"></param>
        /// <param name="timestamp"></param>
        /// <param name="url"></param>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public static string GetJsApiPayConfigSign(WeChatPayConfig config, string nancestr, string timestamp, string url, JSAPITicket ticket)
        {
            string sign = null;
            SortedDictionary <string, string> param = new SortedDictionary <string, string>();

            if (ticket == null || string.IsNullOrEmpty(ticket.Ticket))
            {
                throw new Exception("WeChat js ticket is empty.");
            }
            logger.Info("Generate pay config sign");
            logger.Info("jsapi_ticket:" + ticket.Ticket);
            logger.Info("timestamp:" + timestamp);
            logger.Info("noncestr:" + nancestr);
            logger.Info("url:" + url);

            param.Add("jsapi_ticket", ticket.Ticket);
            param.Add("timestamp", timestamp);
            param.Add("noncestr", nancestr);
            param.Add("url", url);
            sign = HashWrapper.SHA1_Hash(param);
            logger.Info("sign:" + sign);
            return(sign);
        }