diff --git a/inc/options-framework/js/options-custom.js b/inc/options-framework/js/options-custom.js index aeea43c..9f851d2 100755 --- a/inc/options-framework/js/options-custom.js +++ b/inc/options-framework/js/options-custom.js @@ -44,6 +44,16 @@ jQuery(document).ready(function ($) { jQuery("#section-g_cos_secretkey").show(); } + jQuery("#g_007").click(function () { + jQuery("#section-g_007_appid").fadeToggle(400); + jQuery("#section-g_007_appsecretkey").fadeToggle(400); + }); + + if (jQuery("#g_007:checked").val() !== undefined) { + jQuery("#section-g_007_appid").show(); + jQuery("#section-g_007_appsecretkey").show(); + } + jQuery("#g_cc_switch").click(function () { jQuery("#section-g_cc").fadeToggle(400); }); diff --git a/inc/theme-core.php b/inc/theme-core.php index 00c599f..0387c9e 100644 --- a/inc/theme-core.php +++ b/inc/theme-core.php @@ -282,4 +282,129 @@ if (kratos_option('g_search', false)) { return $search; } +} + +// 腾讯云验证码 +if (kratos_option('g_007', false)) { + add_action('login_head', 'add_login_head'); + function add_login_head() + { + echo ''; + } + + add_action('login_form', 'add_captcha_body'); + function add_captcha_body(){ ?> + + + + + + + $appid, + "AppSecretKey" => $appsecretkey, + "Ticket" => $ticket, + "Randstr" => $randstr, + "UserIP" => $userip + ); + $paramstring = http_build_query($params); + $content = txcurl($url, $paramstring); + $result = json_decode($content, true); + + if($result){ + if($result['response'] == 1){ + return array( + 'result' => 1, + 'message' => '' + ); + }else{ + return array( + 'result' => 0, + 'message' => $result['err_msg'] + ); + } + }else{ + return array( + 'result' => 0, + 'message' => '错误:请求异常,请稍后再试' + ); + } + } + + function txcurl($url, $params=false, $ispost=0) + { + $httpInfo = array(); + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); + curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + + if($ispost) + { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + curl_setopt($ch, CURLOPT_URL, $url); + }else{ + if($params) + { + curl_setopt($ch, CURLOPT_URL, $url . '?' . $params); + }else{ + curl_setopt($ch, CURLOPT_URL, $url); + } + } + + $response = curl_exec($ch); + + if ($response === FALSE) + { + return false; + } + + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); + + curl_close($ch); + return $response; + } } \ No newline at end of file diff --git a/inc/theme-options.php b/inc/theme-options.php index 4ba6cd3..5b1e459 100644 --- a/inc/theme-options.php +++ b/inc/theme-options.php @@ -234,6 +234,28 @@ function kratos_options() 'type' => 'checkbox', ); + $options[] = array( + 'name' => __('腾讯云验证码', 'kratos'), + 'desc' => __('开启后台登录页面验证码功能', 'kratos'), + 'id' => 'g_007', + 'std' => '0', + 'type' => 'checkbox', + ); + + $options[] = array( + 'name' => __('App ID', 'kratos'), + 'id' => 'g_007_appid', + 'class' => 'hidden', + 'type' => 'text', + ); + + $options[] = array( + 'name' => __('App Secret Key', 'kratos'), + 'id' => 'g_007_appsecretkey', + 'class' => 'hidden', + 'type' => 'password', + ); + $options[] = array( 'name' => __('Chrome 导航栏颜色', 'kratos'), 'desc' => __('Chrome 移动端浏览器导航栏的颜色', 'kratos'),