PHPackages                             phalapi/gtcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. phalapi/gtcode

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

phalapi/gtcode
==============

PhalApi 2.x 扩展类库 - 极验验证码拓展

11681PHP

Since Dec 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gongshunkai/phalapi-gtcode)[ Packagist](https://packagist.org/packages/phalapi/gtcode)[ RSS](/packages/phalapi-gtcode/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (0)

极验验证码扩展
=======

[](#极验验证码扩展)

安装和配置
-----

[](#安装和配置)

修改项目下的composer.json文件，并添加：

```
    "phalapi/gtcode":"dev-master"

```

在/path/to/phalapi/config/app.php文件中，配置：

```
    'gtserver' => array(
        'captchaId'   => '',  //ID
        'privateKey' => '',  //KEY
    )

```

然后执行`composer update`。

注册
--

[](#注册)

在/path/to/phalapi/config/di.php文件中，注册：

```
$di->gtcode = function() {
	return new \PhalApi\GTCode\Lite();
};
```

使用
--

[](#使用)

定义GTCode类接口文件

1. 初始化验证方法startCaptchaServlet，返回验证字符串数据提供给客户端脚本初始化，并在回调函数中获取captchaObj对象提供给二次验证需要的参数
2. 二次验证方法verifyLoginServlet，返回验证的结果，1表示成功，0表示失败

客户端配置参见极验文档：如在使用中有任何疑问可以加我的qq:49078111

```
class GTCode extends Api {

    public function getRules() {
        return array(
            'startCaptchaServlet' => array(
                'userId' => array('name' => 'user_id', 'type' => 'string', 'require' => false, 'default' => 'test', desc' => '用户ID'),
                'clientType' => array('name' => 'client_type', 'type' => 'enum', 'require' => false, 'default' => 'web', 'range' => array('web','h5','native'), 'desc' => 'web:电脑上的浏览器；h5:手机上的浏览器，包括移动应用内完全内置的web_view；native：通过原生SDK植入APP应用的方式')
            ),
            'verifyLoginServlet' => array(
                'userId' => array('name' => 'user_id', 'type' => 'string', 'require' => false, 'default' => 'test', desc' => '用户ID'),
                'clientType' => array('name' => 'client_type', 'type' => 'enum', 'require' => false, 'default' => 'web', 'range' => array('web','h5','native'), 'desc' => 'web:电脑上的浏览器；h5:手机上的浏览器，包括移动应用内完全内置的web_view；native：通过原生SDK植入APP应用的方式'),
                'challenge' => array('name' => 'challenge', 'type' => 'string', 'require' => true, 'desc' => 'challenge'),
                'validate' => array('name' => 'validate', 'type' => 'string', 'require' => true, 'desc' => 'validate'),
                'seccode' => array('name' => 'seccode', 'type' => 'string', 'require' => true, 'desc' => 'seccode'),
            ),
        );
    }

    /**
     * 初始化验证
     * @desc 初始化验证
     * @return int success success
     * @return string gt 验证 id，极验后台申请得到
     * @return string challenge 验证流水号，后服务端 SDK 向极验服务器申请得到
     * @return int new_captcha 宕机情况下使用，表示验证是 3.0 还是 2.0，3.0 的 sdk 该字段为 true
     */
    public function startCaptchaServlet() {
        return \PhalApi\DI()->gtcode->startCaptchaServlet(array(
            'user_id' => $this->userId,
            'client_type' => $this->clientType,
            'ip_address' => $_SERVER["REMOTE_ADDR"]
        ));
    }

    /**
     * 二次验证
     * @desc 二次验证
     * @return int code 验证的结果，1表示成功，0表示失败
     */
    public function verifyLoginServlet() {
        $rs = array();

        $code = \PhalApi\DI()->gtcode->verifyLoginServlet($this->challenge, $this->validate, $this->seccode, array(
            'user_id' => $this->userId,
            'client_type' => $this->clientType,
            'ip_address' => $_SERVER["REMOTE_ADDR"]
        ));

        $rs['code'] = $code;

        return $rs;
    }

}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d70b1236f8f67d96ba3da4ba88889faf2837ff8f7ab62acc54fe6cb4992c87?d=identicon)[dogstarhuang](/maintainers/dogstarhuang)

---

Top Contributors

[![gongshunkai](https://avatars.githubusercontent.com/u/16865308?v=4)](https://github.com/gongshunkai "gongshunkai (9 commits)")

### Embed Badge

![Health badge](/badges/phalapi-gtcode/health.svg)

```
[![Health](https://phpackages.com/badges/phalapi-gtcode/health.svg)](https://phpackages.com/packages/phalapi-gtcode)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
