Ejemplo n.º 1
0
        internal static string tryGetAccessToken()
        {
            string appId     = WxConfigFile.config().AppID;
            string appSecret = WxConfigFile.config().AppSecret;

            return(AccessTokenContainer.TryGetAccessToken(appId, appSecret));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 下载远程服务url的文件到本地服务器,并返回文件在本地服务器上的url
        /// </summary>
        /// <param name="url"></param>
        /// <param name="virPath"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string downloadFile(string url, string virPath, string fileName)
        {
            if (string.IsNullOrEmpty(virPath) || string.IsNullOrEmpty(fileName))
            {
                throw new Exception("must need virPath and fileName");
            }

            if (!virPath.StartsWith("/"))
            {
                virPath = "/" + virPath;
            }
            if (!virPath.EndsWith("/"))
            {
                virPath += "/";
            }
            virPath += fileName;
            string toPath = System.AppDomain.CurrentDomain.BaseDirectory + virPath.Replace("/", "\\");


            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";
            WebResponse response = request.GetResponse();
            string      ext      = response.Headers["Content-Type"];

            ext      = "." + ext.Remove(0, ext.IndexOf("/") + 1).Trim().ToLower();
            toPath  += ext;
            virPath += ext;

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                using (StreamWriter sw = new StreamWriter(new FileStream(toPath, FileMode.Create)))
                {
                    sw.Write(reader.ReadToEnd());
                    sw.Close();
                }
                reader.Close();
            }


            //FileStream stream = new FileStream(toPath, FileMode.Create);
            //try
            //{
            //    stream.Write(data, 0, data.Length);

            //    //foreach (var b in data)
            //    //{
            //    //    stream.WriteByte(b);
            //    //}
            //}
            //finally
            //{
            //    stream.Close();
            //}
            return(WxConfigFile.config().Domain + virPath);
        }