赞
踩
<?php header('Content-Type: text/html; charset=UTF-8'); error_reporting(0); //$httpcode = 0; $start_date = date('Y-m-d', strtotime('-99 days')); $end_date = date('Y-m-d', strtotime('+1 day')); $apikey = "sk-*******************************************************"; $suburl = "https://api.***.***/v1/dashboard/billing/subscription"; $dataurl = "https://api.***.***/v1/dashboard/billing/usage?start_date=".$start_date."&end_date=".$end_date; $headers = [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apikey ]; $resdata = curl_get($suburl,$headers); if ($httpcode == 200) { $json_a = json_decode($resdata, true); $billing = $json_a['hard_limit_usd']; $data = curl_get($dataurl,$headers); $json_a = json_decode($data, true); $used = round($json_a['total_usage']) / 100; $free = $billing - $used; echo "额度总量: " . $billing . " 美元" . '<br/>'; echo "已用额度: " . $used . " 美元" . '<br/>'; echo "剩余额度: " . $free . " 美元"; } elseif ($httpcode == 0) { echo "无法访问接口地址<br/>请检查接口地址是否错误"; } else { echo "接口访问错误<br/>返回状态码: " . $httpcode; } function curl_get ($url,$headarr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headarr); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($ch, CURLOPT_MAXREDIRS, 3); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); $data = curl_exec($ch); $GLOBALS['httpcode'] = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); return $data; } ?>
还是放张截图吧
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。