Initial commit
Some checks failed
定时更新GitHub源插件 / 自动更新GitHub插件 (push) Has been cancelled

This commit is contained in:
chorblack
2026-03-07 11:19:25 +08:00
commit e75f275ef4
4484 changed files with 645480 additions and 0 deletions

99
GeeTest/Plugin.php Normal file
View File

@@ -0,0 +1,99 @@
<?php
/**
* 极验验证
*
* @package GeeTest
* @author 啸傲居士
* @link http://jiya.io
* @version 1.0.1
* @date 2015-02-01
*
* 更新1. 更新geetestlib到最新版本2. 增加样式选择选项3. 如果选择弹出样式请将提交按钮id设为“submit-button”
*/
require_once('lib/geetestlib.php');
class GeeTest_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate() {
Typecho_Plugin::factory('Widget_Feedback')->comment = array(__CLASS__, 'filter');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate() {}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form) {}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form) {
$captchakeyDescription = _t("To use GeeTest you must get an API key from <a href='http://www.geetest.com/'>http://www.geetest.com/</a>");
$captchakey = new Typecho_Widget_Helper_Form_Element_Text('captchakey', NULL, '', _t('Captcha key:'), $captchakeyDescription);
$privatekey = new Typecho_Widget_Helper_Form_Element_Text('privatekey', NULL, '', _t('Private key:'), _t(''));
$dispmode = new Typecho_Widget_Helper_Form_Element_Select('dispmode', array('float' => '浮动式','embed' => '嵌入式','popup' => '弹出式'), 'float', _t('Display mode(<a href="http://geetest.com/experience">experience online</a>):'), _t(''));
$form->addInput($captchakey);
$form->addInput($privatekey);
$form->addInput($dispmode);
}
/**
* 展示验证码
*/
public static function output() {
$captchakey = Typecho_Widget::widget('Widget_Options')->plugin('GeeTest')->captchakey;
$dispmode = Typecho_Widget::widget('Widget_Options')->plugin('GeeTest')->dispmode;
$str = '&product='.$dispmode;
if ($dispmode == 'popup') {
$str = $str.'&popupbtnid=submit-button';
}
echo "<script async type='text/javascript' src='http://api.geetest.com/get.php?gt=$captchakey$str'></script>";
}
public static function filter($comment, $obj) {
$userObj = $obj->widget('Widget_User');
if($userObj->hasLogin() && $userObj->pass('administrator', true)) {
return $comment;
}
$privatekey = Typecho_Widget::widget('Widget_Options')->plugin('GeeTest')->privatekey;
$geetest = new GeetestLib($privatekey);
$validate_response = $geetest->geetest_validate( @$_POST ['geetest_challenge'],
@$_POST ['geetest_validate'], @$_POST ['geetest_seccode']);
if ($validate_response) {
return $comment;
}
throw new Typecho_Widget_Exception(_t('验证码不正确哦!'));
}
}

43
GeeTest/README.md Normal file
View File

@@ -0,0 +1,43 @@
GeeTest验证码插件
=============
评论框验证码插件,防止垃圾评论,作者「[啸傲居士](http://jiya.io)」。
2015年2月1日更新
1. 更新[geetestlib](https://github.com/GeeTeam/gt-php-sdk/)到最新版本;
2. 增加样式选择选项;
3. 如果选择弹出样式请将提交按钮id设为“submit-button”
说明:请先禁用后再更新本插件。
---
在[seccode代码](http://521-wf.com/archives/36.html)的基础上修改,可以到[官方体验页面](http://geetest.com/experience)体验。
### 使用说明
1. 在[GeeTest官网](http://my.geetest.com/)页面申请Captcha Key即ID和Private Key即Key
2. 把插件文件夹上传到usr/plugins/目录下;
2. 进入后台点击“激活”并配置Key
3. 在模板中加入显示验证码的代码找到对应模板目录下的comments.php文件然后在提交按钮前加入如下代码这只是个方法不是必须与下面代码一模一样可以根据自己的需要做稍微的改动
```
<?php
if(!$this->user->hasLogin()) {
GeeTest_Plugin::output();
}
?>
<div style="clear: both;margin: 15px 0;zoom: 1;">
<button id="submit-button" type="submit" class="submit"><?php _e('提交评论'); ?></button>
</div>
```
### 附:
为方便大家特提供如下key
```
Public Key: 6d1d522f9af8576c4287bde5d1963047
Private Key: 88aa2a14010d795a3d27d9f24fec4ba6
```

View File

@@ -0,0 +1,78 @@
<?php
/**
* 极验行为式验证安全平台php 网站主后台包含的库文件
*/
// define("PRIVATE_KEY","0f1a37e33c9ed10dd2e133fe2ae9c459");
class GeetestLib {
function __construct($PRIVATE_KEY){
$this->PRIVATE_KEY = $PRIVATE_KEY;
}
function geetest_validate($challenge, $validate, $seccode) {
$apiserver = 'api.geetest.com';
if (strlen($validate) > 0 && $this->_check_result_by_private($challenge, $validate)) {
$query = 'seccode='.$seccode;
$servervalidate = $this->_http_post($apiserver, '/validate.php', $query);
if (strlen($servervalidate) > 0 && $servervalidate == md5($seccode)) {
return TRUE;
}else if($servervalidate == "false"){
return FALSE;
}else{
return $servervalidate;
}
}
return FALSE;
}
function challenge(){
$str = str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
$time = strval(time());
$rand = strval(rand(0,99999));
$test = $time.$str.$rand;
$challenge = md5($test);
return $challenge;
}
function _check_result_by_private($origin, $validate) {
return $validate == md5($this->PRIVATE_KEY.'geetest'.$origin) ? TRUE : FALSE;
}
function _http_post($host, $path, $data, $port = 80) {
// $data = _fix_encoding($data);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http_request .= "Content-Length: " . strlen($data) . "\r\n";
$http_request .= "\r\n";
$http_request .= $data;
$response = '';
if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) {
die ('Could not open socket! ' . $errstr);
}
fwrite($fs, $http_request);
while (!feof($fs))
$response .= fgets($fs, 1160);
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response[1];
}
function _fix_encoding($str) {
$curr_encoding = mb_detect_encoding($str) ;
if($curr_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) {
return $str;
} else {
return utf8_encode($str);
}
}
}
?>