From c4735215d5a93261ebe445d4415491faf59e6184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E6=A9=99=E6=A5=8A?= <2370374436@qq.com> Date: Thu, 24 Oct 2019 20:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BE=E5=BA=A6AK/SK=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/ApiConfig.php | 109 +++++++++++++++++++++++++++++++++++++++ admin/Login.php | 8 ++- admin/WasteSorting.php | 3 -- api/BaiduImage.php | 26 ++++------ baidu/BaiduAiRequest.php | 91 ++++++++++++++++++++------------ database/Query.php | 31 +++++++++++ entity/Param.php | 48 +++++++++++++++++ index.php | 2 +- script/db.sql | 9 +++- test.php | 8 +-- 10 files changed, 276 insertions(+), 59 deletions(-) create mode 100644 admin/ApiConfig.php create mode 100644 entity/Param.php diff --git a/admin/ApiConfig.php b/admin/ApiConfig.php new file mode 100644 index 0000000..6e4e18f --- /dev/null +++ b/admin/ApiConfig.php @@ -0,0 +1,109 @@ + + + + +
+
+
+
+
+ API Key +
+ +
+ API Key不能为空 +
+
+
+
+ API Key +
+ +
+ Secret Key不能为空 +
+
+
+EOF; + if (isset($_GET["check"]) and $_GET["check"] == "true") { + echo ''; + } else { + echo ''; + } + echo <<返回 +
+
+
+
+ + +EOF; + +} else if (!empty($_GET["action"])) { + if (empty($_POST["api_key"])) { + error_res("API Key不能为空", $_SERVER["PHP_SELF"]); + } else if (empty($_POST["secret_key"])) { + error_res("Secret Key不能为空", $_SERVER["PHP_SELF"]); + } else if ($_GET["action"] == "test") { + $api_key = $_POST["api_key"]; + $secret_key = $_POST["secret_key"]; + $result = BaiduAiRequest::request_token_with_config($api_key, $secret_key); + if (array_key_exists("status", $result) and $result["status"]) { + info_res("AK/SK测试通过", $_SERVER["PHP_SELF"] . "?check=true"); + } else { + warn_res("AK/SK测试失败", $_SERVER["PHP_SELF"] . "?check=false"); + } + } else if ($_GET["action"] == "update") { + try { + DbUtil::update("update param set param_value=? where param_key=?", "ss", $_POST["api_key"], "api_key"); + DbUtil::update("update param set param_value=? where param_key=?", "ss", $_POST["secret_key"], "secret_key"); + info_res("保存成功", $_SERVER["PHP_SELF"]); + } catch (Exception $e) { + error($e); + error_res("保存异常请联系管理员", $_SERVER["PHP_SELF"]); + } + } else { + error_res("非法操作!", $_SERVER["PHP_SELF"]); + } +} else { + error_res("非法操作!", $_SERVER["PHP_SELF"]); +} \ No newline at end of file diff --git a/admin/Login.php b/admin/Login.php index 20a6212..8e456e8 100644 --- a/admin/Login.php +++ b/admin/Login.php @@ -24,8 +24,10 @@ function update_token(QueryManager $manager_result, $msg) info_res($msg, "/",); echo << - -let count=3 + +$(function() { + let count=3; + $("#tip").text(count+"秒后自动跳转"); let i=setInterval(function() { if(count-->0){ $("#tip").text(count+"秒后自动跳转"); @@ -34,6 +36,8 @@ let i=setInterval(function() { } console.info("定时器!!!!!") },1000) +}) +