本文共 612 字,大约阅读时间需要 2 分钟。
/** * 获取美元人民币汇率 * @return float */ function getRate(){ //百度汇率接口(15分钟左右更新一次) $url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=1%E7%BE%8E%E5%85%83%E7%AD%89%E4%BA%8E%E5%A4%9A%E5%B0%91%E4%BA%BA%E6%B0%91%E5%B8%81&co=&resource_id=6017&t=1517817481143&cardId=6017&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery1102045803999539536244_1517817285354&_=1517817285360'; $output = curl($url); $rate = 6.29;//默认汇率 if($output){ preg_match('/\"number2\"\:\"(.*)\"\, \"content1Mini\"/',$output,$match); if(is_numeric($match[1])){ $rate = $match[1]; } } return $rate;}
欢迎关注微信订阅号:phpstory
转载地址:http://oxvzn.baihongyu.com/