/// <summary> /// 汇率转换 /// </summary> /// <param name="Currency">当前币种:CNY</param> /// <param name="ToCurrency">目标币种:USD</param> /// <returns>汇率</returns> public string GetExchangeRate(string Currency, string ToCurrency) { int Number = 0; one: string Price = null; string url = string.Format("http://hk.finance.yahoo.com/q/bc?s={0}=X&t=5d&l=on&z=m&q=l&c=", Currency + ToCurrency); System.Net.WebRequest request = System.Net.WebRequest.Create(url); request.Method = "Get"; request.ContentType = "application/x-www-form-urlencoded"; try { using (System.Net.WebResponse response = request.GetResponse()) { using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) { string str = reader.ReadToEnd(); if (!string.IsNullOrEmpty(str)) Price = str.Substring(str.IndexOf("<span class="time_rtq_ticker"") + 30, 5); } } } catch (Exception) { if (Number == 0) { Number++; goto one; } } return Price; }
/// <summary> /// 币种码 /// </summary> enum Currency { /// <summary> ///澳大利亚元 /// </summary> AUD, /// <summary> ///英镑 /// </summary> GBP, /// <summary> ///欧元 /// </summary> EUR, /// <summary> ///日元 /// </summary> JPY, /// <summary> ///瑞士法郎 /// </summary> CHF, /// <summary> ///美元 /// </summary> USD, /// <summary> ///阿富汗尼 /// </summary> AFN, /// <summary> ///阿尔巴尼亚列克 /// </summary> ALL, /// <summary> ///阿尔及利亚第纳尔 /// </summary> DZD, /// <summary> ///安哥拉宽扎 /// </summary> AOA, /// <summary> ///阿根廷比索 /// </summary> ARS, /// <summary> ///亚美尼亚德拉姆 /// </summary> AMD, /// <summary> ///阿鲁巴弗罗林 /// </summary> AWG, /// <summary> ///澳大利亚元 /// </summary> AUD, /// <summary> ///阿塞拜疆马纳特 /// </summary> AZN, /// <summary> ///巴哈马元 /// </summary> BSD, /// <summary> ///巴林第纳尔 /// </summary> BHD, /// <summary> ///孟加拉塔卡 /// </summary> BDT, /// <summary> ///巴巴多斯元 /// </summary> BBD, /// <summary> ///白俄罗斯卢布 /// </summary> BYR, /// <summary> ///伯利兹元 /// </summary> BZD, /// <summary> ///百慕大元 /// </summary> BMD, /// <summary> ///不丹努尔特鲁姆 /// </summary> BTN, /// <summary> ///玻利维亚币 /// </summary> BOB, /// <summary> ///波斯尼亚马克 /// </summary> BAM, /// <summary> ///博茨瓦纳普拉 /// </summary> BWP, /// <summary> ///巴西里尔 /// </summary> BRL, /// <summary> ///英镑 /// </summary> GBP, /// <summary> ///文莱元 /// </summary> BND, /// <summary> ///保加利亚列弗 /// </summary> BGN, /// <summary> ///布隆迪法郎 /// </summary> BIF, /// <summary> ///多哥非洲共同体法郎 /// </summary> XOF, /// <summary> ///刚果中非共同体法郎 /// </summary> XAF, /// <summary> ///太平洋法兰西共同体法郎 /// </summary> XPF, /// <summary> ///柬埔寨瑞尔 /// </summary> KHR, /// <summary> ///加拿大元 /// </summary> CAD, /// <summary> ///埃斯库多 /// </summary> CVE, /// <summary> ///开曼群岛元 /// </summary> KYD, /// <summary> ///智利比索 /// </summary> CLP, /// <summary> ///人民币 /// </summary> CNY, /// <summary> ///哥伦比亚比索/// </summary> COP, /// <summary> ///科摩罗法郎 /// </summary> KMF, /// <summary> ///刚果法郎 /// </summary> CDF, /// <summary> ///哥斯达黎加科朗/// </summary> CRC, /// <summary> ///克罗地亚库纳/// </summary> HRK, /// <summary> ///古巴可兑换比索/// </summary> CUC, /// <summary> ///古巴比索 /// </summary> CUP, /// <summary> ///塞浦路斯镑 /// </summary> CYP, /// <summary> ///捷克克朗 /// </summary> CZK, /// <summary> ///丹麦克朗 /// </summary> DKK, /// <summary> ///吉布提法郎 /// </summary> DJF, /// <summary> ///多米尼加比索 /// </summary> DOP, /// <summary> ///东加勒比元 /// </summary> XCD, /// <summary> ///埃及镑/// </summary> EGP, /// <summary> ///萨尔瓦多科朗 /// </summary> SVC, /// <summary> ///爱沙尼亚伦尼 /// </summary> EEK, /// <summary> ///埃塞俄比亚比尔 /// </summary> ETB, /// <summary> ///欧元 /// </summary> EUR, /// <summary> ///福克兰群岛镑 /// </summary> FKP, /// <summary> ///斐济元 /// </summary> FJD, /// <summary> ///冈比亚达拉西 /// </summary> GMD, /// <summary> ///格鲁吉亚拉里 /// </summary> GEL, /// <summary> ///加纳新赛地 /// </summary> GHS, /// <summary> ///直布罗陀镑 /// </summary> GIP, /// <summary> ///黄金(盎司) /// </summary> XAU, /// <summary> ///危地马拉查尔 /// </summary> GTQ, /// <summary> ///几内亚法郎 /// </summary> GNF, /// <summary> ///圭亚那元 /// </summary> GYD, /// <summary> ///海地古德 /// </summary> HTG, /// <summary> ///洪都拉斯皮拉 /// </summary> HNL, /// <summary> ///港币 /// </summary> HKD, /// <summary> ///匈牙利福林 /// </summary> HUF, /// <summary> ///冰岛克朗 /// </summary> ISK, /// <summary> ///印度卢比 /// </summary> INR, /// <summary> ///印度尼西亚卢比 /// </summary> IDR, /// <summary> ///伊朗里亚尔 /// </summary> IRR, /// <summary> ///伊拉克第纳尔 /// </summary> IQD, /// <summary> ///以色列新谢克尔 /// </summary> ILS, /// <summary> ///牙买加元 /// </summary> JMD, /// <summary> ///日元 /// </summary> JPY, /// <summary> ///约旦第纳尔 /// </summary> JOD, /// <summary> ///哈萨克斯坦腾格 /// </summary> KZT, /// <summary> ///肯尼亚先令 /// </summary> KES, /// <summary> ///科威特第纳尔 /// </summary> KWD, /// <summary> ///吉尔吉斯斯坦索姆 /// </summary> KGS, /// <summary> ///老挝基普 /// </summary> LAK, /// <summary> ///拉脱维亚拉特 /// </summary> LVL, /// <summary> ///黎巴嫩镑 /// </summary> LBP, /// <summary> ///莱索托洛蒂 /// </summary> LSL, /// <summary> ///利比里亚元 /// </summary> LRD, /// <summary> ///利比亚第纳尔 /// </summary> LYD, /// <summary> ///立陶宛立特 /// </summary> LTL, /// <summary> ///澳门元 /// </summary> MOP, /// <summary> ///马其顿第纳尔 /// </summary> MKD, /// <summary> ///马达加斯加阿里亚里 /// </summary> MGA, /// <summary> ///马拉维克瓦查 /// </summary> MWK, /// <summary> ///马来西亚林吉特 /// </summary> MYR, /// <summary> ///马尔代夫拉菲亚 /// </summary> MVR, /// <summary> ///马耳他镑 /// </summary> MTL, /// <summary> ///毛里塔尼亚乌吉亚 /// </summary> MRO, /// <summary> ///毛里求斯卢比 /// </summary> MUR, /// <summary> ///墨西哥比索 /// </summary> MXN, /// <summary> ///摩尔多瓦列伊 /// </summary> MDL, /// <summary> ///蒙古图格里克 /// </summary> MNT, /// <summary> ///摩洛哥迪拉姆 /// </summary> MAD, /// <summary> ///莫桑比克美提卡 /// </summary> MZN, /// <summary> ///缅甸元 /// </summary> MMK, /// <summary> ///荷属安的列斯盾 /// </summary> ANG, /// <summary> ///纳米比亚元 /// </summary> NAD, /// <summary> ///尼泊尔卢比 /// </summary> NPR, /// <summary> ///新西兰元 /// </summary> NZD, /// <summary> ///尼加拉瓜科多巴 /// </summary> NIO, /// <summary> ///尼日利亚奈拉 /// </summary> NGN, /// <summary> ///南韩元 /// </summary> KPW, /// <summary> ///挪威克朗 /// </summary> NOK, /// <summary> ///阿曼里亚尔 /// </summary> OMR, /// <summary> ///巴基斯坦卢比 /// </summary> PKR, /// <summary> ///巴拿马巴波亚 /// </summary> PAB, /// <summary> ///巴布亚新几内亚基那 /// </summary> PGK, /// <summary> ///巴拉圭瓜尼 /// </summary> PYG, /// <summary> ///秘鲁新索尔 /// </summary> PEN, /// <summary> ///菲律宾比索 /// </summary> PHP, /// <summary> ///波兰兹罗提 /// </summary> PLN, /// <summary> ///卡塔尔里亚尔 /// </summary> QAR, /// <summary> ///罗马尼亚塑胶币 /// </summary> RON, /// <summary> ///俄罗斯卢布 /// </summary> RUB, /// <summary> ///卢旺达法郎 /// </summary> RWF, /// <summary> ///萨摩亚塔拉 /// </summary> WST, /// <summary> ///圣多美/普林西比 /// </summary> STD, /// <summary> ///沙特里亚尔 /// </summary> SAR, /// <summary> ///塞尔维亚第纳尔 /// </summary> RSD, /// <summary> ///塞舌尔卢比 /// </summary> SCR, /// <summary> ///塞拉利昂利昂 /// </summary> SLL, /// <summary> ///白银(盎司) /// </summary> XAG, /// <summary> ///新加坡元 /// </summary> SGD, /// <summary> ///斯洛伐克克朗 /// </summary> SKK, /// <summary> ///斯洛文尼亚拉捷夫 /// </summary> SIT, /// <summary> ///所罗门群岛元 /// </summary> SBD, /// <summary> ///索马里先令 /// </summary> SOS, /// <summary> ///南非兰特 /// </summary> ZAR, /// <summary> ///北韩元 /// </summary> KRW, /// <summary> ///斯里兰卡卢比 /// </summary> LKR, /// <summary> ///圣赫勒拿群岛镑 /// </summary> SHP, /// <summary> ///苏丹第纳尔 /// </summary> SDG, /// <summary> ///苏里南元 /// </summary> SRD, /// <summary> ///斯威士兰里兰吉尼 /// </summary> SZL, /// <summary> ///瑞典克朗 /// </summary> SEK, /// <summary> ///瑞士法郎 /// </summary> CHF, /// <summary> ///叙利亚镑 /// </summary> SYP, /// <summary> ///台币 /// </summary> TWD, /// <summary> ///坦桑尼亚先令 /// </summary> TZS, /// <summary> ///泰铢 /// </summary> THB, /// <summary> ///汤加潘加 /// </summary> TOP, /// <summary> ///特立尼达/多巴哥元 /// </summary> TTD, /// <summary> ///突尼斯第纳尔 /// </summary> TND, /// <summary> ///突尼斯新里拉 /// </summary> TRY, /// <summary> ///土库曼斯坦纳特 /// </summary> TMM, /// <summary> ///乌干达先令 /// </summary> UGX, /// <summary> ///乌克兰赫夫米 /// </summary> UAH, /// <summary> ///乌拉圭比索 /// </summary> UYU, /// <summary> ///阿联酋迪拉姆 /// </summary> AED, /// <summary> ///瓦努阿图瓦图 /// </summary> VUV, /// <summary> ///委内瑞拉博利瓦 /// </summary> VEB, /// <summary> ///越南盾 /// </summary> VND, /// <summary> ///也门里亚尔 /// </summary> YER, /// <summary> ///赞比亚克瓦查 /// </summary> ZMK, /// <summary> ///津巴布韦元 /// </summary> ZWD }