阿里云推出了實時外匯查詢接口,也很便宜,通遼易聯(lián)通達給客戶對接如下
public function currency_exchange($fromCode, $toCode, $money=0) {
if( $fromCode == "" || $toCode == "" ) {
exit('Please Input exchange_rate param: fromCode, toCode');
}
$host = "https://tysjhlcx.market.alicloudapi.com";
$path = "/exchange_rate/convert";
$method = "GET";
$appcode = "8a18d0903f734832a49bb3992a8d85bd";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "fromCode=".$fromCode."&toCode=".$toCode."&money=".$money;
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
//var_dump(curl_exec($curl));
$response = curl_exec($curl);
有需要的朋友可以聯(lián)系我們