Go to the API documentation link: www.juhe.cn/docs/api/id… , support RMB quotation and foreign exchange rate query; The data is for reference only, and the transaction price is subject to the bank counter transaction price.
The RMB rate interface address: web. Juhe. Cn: 8080 / finance/exc… Supported formats: json request: get request example: web. Juhe. Cn: 8080 / finance/exc… Interface Note: 100 Foreign currency to RMB Request Parameters:
The name of the | type | mandatory | instructions |
---|---|---|---|
key | String | is | APP Key |
type | int | no | Two formats (0 or 1, default 0) |
bank | int | no | (0: INDUSTRIAL and Commercial Bank of China,1: China Merchants Bank,2: China Construction Bank,3: Bank of China,4: Bank of Communications,5: Agricultural Bank of China, default: Bank of China) |
JSON Return example:
{ "resultcode":"200", "reason":"SUCCESSED!" , "result" : [{" data1 ": {" name" : "pound", currency / * name * / "fBuyPri" : "1001.430", / * * / spot the buying "mBuyPri" : "970.510", Buying rate for notes / * * / "fSellPri" : "1009.480", the spot selling rate * / / * "mSellPri" : "1009.480", selling rate * / / * cash "bankConversionPri" : "1014.870", / * Banks reduced price/middle price * / "date" : "2012-12-13", release date * / / * "time" : "16:25:49 / * * / release time}", "data2" : {" name ":" Hong Kong ", "fBuyPri" : "80.210", "MBuyPri" : "79.570", "fSellPri" : "80.520", "mSellPri" : "80.520", "bankConversionPri" : "81.140", "date" : "2012-12-13", "Time", "16:25:49"}, "data3" : {" name ":" $", "fBuyPri" : "621.650", "mBuyPri" : "616.670", "fSellPri" : "624.150", "MSellPri" : "624.150", "bankConversionPri" : "628.870", "date" : "2012-12-13", "time" : "16:25:49"}, "data4" : {" name ":" the Swiss franc," "FBuyPri ":"670.310", "mBuyPri":"649.620", "fSellPri":"675.700", "mSellPri":"675.700", "bankConversionPri":"674.350", "Date" : "2012-12-13", "time" : "16:25:49"}, "data5" : {" name ":" the Singapore dollar, "" fBuyPri" : "508.300", "mBuyPri" : "492.610", "FSellPri" : "512.390", "mSellPri" : "512.390", "bankConversionPri" : "512.000", "date" : "2012-12-13", "time" : "16:25:49"}, "Data6" : {" name ":" Swedish krona, "" fBuyPri" : "93.340", "mBuyPri" : "90.450", "fSellPri" : "94.090", "mSellPri" : "94.090", "BankConversionPri" : "93.770", "date" : "2012-12-13", "time" : "16:25:49"}, "data7" : {" name ":" Danish krone, "" fBuyPri" : "108.920", "MBuyPri" : "105.550", "fSellPri" : "109.790", "mSellPri" : "109.790", "bankConversionPri" : "109.430", "date" : "2012-12-13", "Time", "16:25:49"}, "data8" : {" name ":" the Norwegian krone ", "fBuyPri" : "110.490", "mBuyPri" : "107.080", "fSellPri" : "111.380", "MSellPri" : "111.380", "bankConversionPri" : "111.060", "date" : "2012-12-13", "time" : "16:25:49"}, "data9" : {" name ":" yen ", "FBuyPri" : "7.431", "mBuyPri" : "7.201", "fSellPri" : "7.483", "mSellPri" : "7.483", "bankConversionPri" : "7.531", "Date" : "2012-12-13", "time" : "16:25:49"}, "data10" : {" name ":" the Canadian dollar, "" fBuyPri" : "630.950", "mBuyPri" : "611.470", "FSellPri" : "636.010", "mSellPri" : "636.010", "bankConversionPri" : "638.800", "date" : "2012-12-13", "time" : "16:25:49"}, "Data11" : {" name ":" the Australian dollar, "" fBuyPri" : "654.900", "mBuyPri" : "634.680", "fSellPri" : "660.160", "mSellPri" : "660.160", "BankConversionPri" : "663.300", "date" : "2012-12-13", "time" : "16:25:49"}, "data12" : {" name ":" the euro ", "fBuyPri" : "812.520", "MBuyPri" : "787.430", "fSellPri" : "819.040", "mSellPri" : "819.040", "bankConversionPri" : "821.960", "date" : "2012-12-13", "Time", "16:25:49"}, "data13" : {" name ":" patacas, "" fBuyPri" : "77.910", "mBuyPri" : "75.300", "fSellPri" : "78.210", "MSellPri" : "80.720", "bankConversionPri" : "78.320", "date" : "2012-12-13", "time" : "16:25:49"}, "data14" : {" name ":" the Philippine peso," "FBuyPri" : "15.100", "mBuyPri" : "14.640", "fSellPri" : "15.220", "mSellPri" : "15.690", "bankConversionPri" : "15.220", "Date" : "2012-12-13", "time" : "16:25:49"}, "data15" : {" name ":" baht, "" fBuyPri" : "20.240", "mBuyPri" : "19.620", "FSellPri" : "20.400", "mSellPri" : "21.030", "bankConversionPri" : "20.390", "date" : "2012-12-13", "time" : "16:25:49"}, "Data16" : {" name ":" the New Zealand dollar ", "fBuyPri" : "524.400", "mBuyPri" : "0.000", "fSellPri" : "528.610", "mSellPri" : "0.000", "BankConversionPri" : "526.770", "date" : "2012-12-13", "time" : "16:25:49"}, "data17" : {" name ":" kr ", "fBuyPri" : "0.000", "MBuyPri" : "0.560", "fSellPri" : "0.000", "mSellPri" : "0.608", "bankConversionPri" : "0.586", "date" : "2012-12-13", "time":"16:25:49" } } ] }Copy the code
Foreign exchange interface address: web. Juhe. Cn: 8080 / finance/exc… Supported formats: json request: get request example: web. Juhe. Cn: 8080 / finance/exc… Request parameters:
The name of the | type | mandatory | instructions |
---|---|---|---|
key | String | is | APP Key |
type | int | no | Two formats (0 or 1, default 0) |
JSON Return example:
{ "error_code":0, "resultcode":"200", "reason":"SUCCESSED!" , "result" : [{" data1 ": {" code" : "was", / * * / currency code "currency" : "the dollar yen," currency name * / / * "closePri" : "83.41", / * * / latest price "diffPer" : "0.19%", or % * / / * "diffAmo" : "0.16", / * or amount * / "openPri" : "83.25", / * * / opening "highPic" : "83.67", Highest / * * / "lowPic" : "83.1", your lowest price / * * / "range" : "0.68%", / * breadth % * / "buyPic" : "83.41", the buying rate of / * * / "sellPic" : "83.45", Selling rate / * * / "color" : "Red", / * * / fall color "date" : "2016-07-29", date / * * / "datatime" : "08:58:39 / * * / data time}", "data2" : {" code ":" CHF." "Currency" : "the dollar against the Swiss franc," "closePri" : "0.9241", "diffPer" : "0.06%", "diffAmo" : "0.0006", "openPri" : "0.9234", "highPic" : "0.9243", "LowPic" : "0.9231", "range" : "0.13%", "buyPic" : "0.9241", "sellPic" : "0.9246", "color" : "Red", "date" : "2016-07-29", "datatime":"09:40:54" }, ...... } ] }Copy the code
The sample code invokes code examples based on the currency exchange rate interface in PHP
<! -? php // +---------------------------------------------------------------------- // | JuhePHP [ NO ZUO NO DIE ] // +---------------------------------------------------------------------- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved. // +---------------------------------------------------------------------- // | Author: Juhedata <[email protected]> // +---------------------------------------------------------------------- / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / currency call sample code - the aggregated data / / online interface document: http://www.juhe.cn/docs/23 //---------------------------------- header('Content-type:text/html; charset=utf-8'); / / configure your application appkey $appkey = "* * * * * * * * * * * * * * * * * * * * *"; / / * * * * * * * * * * * * 1. The RMB rate * * * * * * * * * * * * $url = "http://web.juhe.cn:8080/finance/exchange/rmbquot"; $params = array (" key "= > $appkey, / / APP key" type "= >", "/ / two formats (0 or 1, the default is 0)); $paramstring = http_build_query($params); $content = juhecurl($url,$paramstring); $result = json_decode($content,true); if($result){ if($result['error_code']=='0'){ print_r($result); }else{ echo $result['error_code'].":".$result['reason']; }}else{echo "request failed "; } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * 2. Foreign exchange rates * * * * * * * * * * * * $url = "http://web.juhe.cn:8080/finance/exchange/frate"; $params = array (" key "= > $appkey, / / APP key" type "= >", "/ / two formats (0 or 1, the default is 0)); $paramstring = http_build_query($params); $content = juhecurl($url,$paramstring); $result = json_decode($content,true); if($result){ if($result['error_code']=='0'){ print_r($result); }else{ echo $result['error_code'].":".$result['reason']; }}else{echo "request failed "; } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / * * * request interface returned content * @ param string $[] to the url request url * @ param string $params=false,$isPost =0; $params=false,$isPOST =0; $httpInfo = array(); $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'? '.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; }Copy the code
Python – based currency exchange rate interface call code example
#! /usr/bin/python # -*- coding: utf-8 -*- import json, Urllib from urllib import urlencode # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # currency call sample code - the aggregated data online interface document: http://www.juhe.cn/docs/23 #---------------------------------- def main(): # configure your application APPKey APPKey = "* * * * * * * * * * * * * * * * * * * * *" # 1. Request1 (appkey,"GET") #2 Def (appkey, m="GET") def (appkey, m="GET") url = "http://web.juhe.cn:8080/finance/exchange/rmbquot" params = { "key" : appkey, #APP Key "type" : Params = urlenCode (params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: Error_code = res["error_code"] if error_code == 0: print res["result"] else: Print "%s:%s" % (res["error_code"],res["reason"]) else: print "request API error" def request2(appKey, m="GET"): url = "http://web.juhe.cn:8080/finance/exchange/frate" params = { "key" : appkey, #APP Key "type" : Params = urlenCode (params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: Error_code = res["error_code"] if error_code == 0: print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" if __name__ == '__main__': main()Copy the code
Java-based currency exchange rate interface call code example
import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import net.sf.json.JSONObject; /** * currency exchange rate call example code - aggregate data * online interface document: http://www.juhe.cn/docs/23 **/ public class JuheDemo { public static final String DEF_CHATSET = "UTF-8"; public static final int DEF_CONN_TIMEOUT = 30000; public static final int DEF_READ_TIMEOUT = 30000; Public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/ 57.36 (KHTML, Like Gecko) Chrome / 29.0.1547.66 Safari / 537.36 "; / / configure your application KEY public static final String APPKEY = "* * * * * * * * * * * * * * * * * * * * * * * * *"; Public static void getRequest1(){String result =null; String url ="http://web.juhe.cn:8080/finance/exchange/rmbquot"; Params = new HashMap(); // Request parameter params.put("key",APPKEY); //APP Key params.put("type",""); // Two formats (0 or 1, default 0) try {result =net(url, params, "GET"); JSONObject object = JSONObject.fromObject(result); if(object.getInt("error_code")==0){ System.out.println(object.get("result")); }else{ System.out.println(object.get("error_code")+":"+object.get("reason")); } } catch (Exception e) { e.printStackTrace(); Public static void getRequest2(){String result =null; String url ="http://web.juhe.cn:8080/finance/exchange/frate"; Params = new HashMap(); // Request parameter params.put("key",APPKEY); //APP Key params.put("type",""); // Two formats (0 or 1, default 0) try {result =net(url, params, "GET"); JSONObject object = JSONObject.fromObject(result); if(object.getInt("error_code")==0){ System.out.println(object.get("result")); }else{ System.out.println(object.get("error_code")+":"+object.get("reason")); } } catch (Exception e) { e.printStackTrace(); }} public static void main(String[] args) {} /** ** @param strUrl Request address * @param params request parameter * @param method request method * @return Network request String * @throws Exception */ public static String net(String strUrl, Map params,String method) throws Exception { HttpURLConnection conn = null; BufferedReader reader = null; String rs = null; try { StringBuffer sb = new StringBuffer(); if(method==null || method.equals("GET")){ strUrl = strUrl+"?" +urlencode(params); } URL url = new URL(strUrl); conn = (HttpURLConnection) url.openConnection(); if(method==null || method.equals("GET")){ conn.setRequestMethod("GET"); }else{ conn.setRequestMethod("POST"); conn.setDoOutput(true); } conn.setRequestProperty("User-agent", userAgent); conn.setUseCaches(false); conn.setConnectTimeout(DEF_CONN_TIMEOUT); conn.setReadTimeout(DEF_READ_TIMEOUT); conn.setInstanceFollowRedirects(false); conn.connect(); if (params! = null && method.equals("POST")) { try (DataOutputStream out = new DataOutputStream(conn.getOutputStream())) { out.writeBytes(urlencode(params)); } } InputStream is = conn.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET)); String strRead = null; while ((strRead = reader.readLine()) ! = null) { sb.append(strRead); } rs = sb.toString(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader ! = null) { reader.close(); } if (conn ! = null) { conn.disconnect(); } } return rs; Public static String urlenCode (map <String,Object>data) {StringBuilder sb = new StringBuilder(); for (Map.Entry i : data.entrySet()) { try { sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return sb.toString(); }}Copy the code
The original link: blog.csdn.net/ishxiao/art…