Beispiel #1
0
        /// <summary>
        /// 根据域名获取IP地址
        /// </summary>
        /// <param name="domain">域名</param>
        /// <returns>IP地址,失败返回null</returns>
        internal unsafe static                                        IPAddress[] Get(ref SubArray <byte> domain)
        {
            try
            {
                fixed(byte *domainFixed = domain.GetFixedBuffer())
                {
                    byte *domainStart = domainFixed + domain.StartIndex;

                    AutoCSer.Memory.Common.ToLowerNotNull(domainStart, domainStart + domain.Length);
                    HashBytes       key = domain;
                    DomainIPAddress value;

                    Monitor.Enter(domainIpLock);
                    try
                    {
                        value = domainIps.Get(ref key, default(DomainIPAddress));
                        if (value.Ips != null && value.Timeout < AutoCSer.Threading.SecondTimer.Now)
                        {
                            domainIps.Remove(ref key, out value);
                            value.Ips = null;
                        }
                    }
                    finally { Monitor.Exit(domainIpLock); }
                    if (value.Ips == null)
                    {
                        if (value.Domain == null)
                        {
                            value.Domain = MemoryExtensionWebClient.BytesToStringNotEmpty(domainStart, domain.Length);
                        }
                        IPAddress ip;
                        if (IPAddress.TryParse(value.Domain, out ip))
                        {
                            value.Timeout = DateTime.MaxValue;
                            value.Domain  = null;
                            setDomainIp(key.Copy(), ref value);
                            return(value.Ips = new IPAddress[] { ip });
                        }
                        value.Ips = Dns.GetHostEntry(value.Domain).AddressList;
                        if (value.Ips.Length != 0)
                        {
                            value.Timeout = AutoCSer.Threading.SecondTimer.Now.AddTicks(domainIpTimeoutTicks);
                            setDomainIp(key.Copy(), ref value);
                            return(value.Ips);
                        }
                    }
                    else
                    {
                        return(value.Ips);
                    }
                }
            }
            catch (Exception error)
            {
                AutoCSer.LogHelper.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// 获取商品二维码URL
        /// </summary>
        /// <param name="product_id"></param>
        /// <returns></returns>
        public unsafe string GetProductUrl(string product_id)
        {
            ProductUrlSign sign = new ProductUrlSign {
                product_id = product_id
            };

            sign.setConfig(this);
            SubBuffer.PoolBufferFull buffer = default(SubBuffer.PoolBufferFull);
            int length = Sign <ProductUrlSign> .GetData(sign, key, ref buffer);

            try
            {
                fixed(byte *bufferFixed = buffer.GetFixedBuffer())
                {
                    using (MD5 md5 = new MD5CryptoServiceProvider())
                    {
                        return("weixin://wxpay/bizpayurl?" + MemoryExtensionWebClient.BytesToStringNotEmpty(bufferFixed + buffer.StartIndex, length) + "&sign=" + sign.sign);
                    }
                }
            }
            finally { buffer.Free(); }
        }