實做 PHP SOAP 匯率換算

贊助我 Steam 遊戲

讀取中…

 

<?php
$uri    = 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL';
$from   = isset($_GET['cur1']) ? $_GET['cur1'] : 'USD';
$to     = isset($_GET['cur2']) ? $_GET['cur2'] : 'USD';
$param  = [
    'FromCurrency' => $from,
    'ToCurrency'   => $to
];
try {
    $client = new SoapClient($uri);
    $result = $client->ConversionRate($param);
    exit(json_encode($result->ConversionRateResult));
} catch (SoapFault $exception) {
    exit($exception);
}
?>