curl($url); $data = json_decode($data, true); if (!blank($data) && isset($data['conversion_rates'])) { $rate = $data['conversion_rates']['CNY'] ?? '6.836'; if (!blank($rate)) Cache::store('redis')->put('usd2cny', $rate); } else { $rate = '6.836'; if (!blank($rate)) Cache::store('redis')->put('usd2cny', $rate); } } private function curl($url, $req_method = 'GET', $postdata = []) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); if ($req_method == 'POST') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata)); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", ]); $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return $output; } }