" array(\n \"header\" \=\> implode(\"\r\n\", \$headers),\n \"method\" \=\> \"GET\"\n )\n)));\n\nif (\$subscription_response \=== false) {\n return \$subscription_response;\n}\n\$subscription_data \= json_decode(\$subscription_response, true);\n\$total \= \$subscription_data[\"hard_limit_usd\"];\n\n// Get billing data\n\$start_date \= date(\"Y-m-d\", strtotime(\"-99 days\"));\n\$end_date \= date(\"Y-m-d\", strtotime(\"+1 day\"));\n\$billing_url \= \"https://api.openai.com/v1/dashboard/billing/usage?start_date=\{\$start_date\}&end_date=\{\$end_date\}\";\n\$billing_response \= file_get_contents(\$billing_url, false, stream_context_create(array(\n \"http\" \=\> array(\n \"header\" \=\> implode(\"\r\n\", \$headers),\n \"method\" \=\> \"GET\"\n )\n)));\n\nif (\$billing_response \=== false) {\n return \$billing_response;\n}\n\$billing_data \= json_decode(\$billing_response, true);\n\$total_usage \= \$billing_data[\"total_usage\"] / 100;\n\$daily_costs \= \$billing_data[\"daily_costs\"];\n\$days \= min(5, count(\$daily_costs));\n\$recent \= \"最近\{\$days\}天使用情况\n\";\nfor (\$i \= 0; \$i < \$days; \$i++) {\n \$cur \= \$daily_costs[count(\$daily_costs) - \$i - 1];\n \$date \= date(\"Y-m-d\", \$cur[\"timestamp\"]);\n \$line_items \= \$cur[\"line_items\"];\n \$cost \= 0;\n foreach (\$line_items as \$item) {\n \$cost += \$item[\"cost\"];\n }\n \$recent .= \"\t\{\$date\}\t\" . (\$cost / 100) . \"\n\";\n}\n\n// Return the results\nreturn \"\n总额:\t\{\$total:.4f\}\n\" .\n \"已用:\t\{\$total_usage:.4f\}\n\" .\n \"剩余:\t\" . (\$total - \$total_usage) . \"\n\" .\n \"\n\{\$recent\}\";\n?>\


原文地址: https://www.cveoy.top/t/topic/pDUf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录