PHPackages                             hotzhan/think-verifycode - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hotzhan/think-verifycode

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hotzhan/think-verifycode
========================

The easiest way for ThinkPHP to send verify code.

1.0.2(2y ago)066MITPHP

Since Mar 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hotzhan/think-verifycode)[ Packagist](https://packagist.org/packages/hotzhan/think-verifycode)[ RSS](/packages/hotzhan-think-verifycode/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

hotzhan/think-verifycode
------------------------

[](#hotzhanthink-verifycode)

- ThinkPHP验证码发送库(邮件+短信 两种方式可用)
- 短信发送依赖 easy-sms
- 邮件发送依赖 phpmailer （需安装php-imap扩展，如果是宝塔面板在对应php版本设置里可直接安装）

ThinkPHP适用版本
------------

[](#thinkphp适用版本)

- ThinkPHP 6 / 8

安装本库
----

[](#安装本库)

```
composer require hotzhan/think-verifycode
```

配置文件
----

[](#配置文件)

- config目录里的sms.php和mail.php文件会自动复制到thinkphp的config目录里
- 如果没有自动复制，请自己手动复制一下
- 具体配置参考配置文件里有详细注释
- 短信支持多平台多网关同时配置，如果1个网关发送失败，会根据配置的依次发送直到成功为止
- 邮件支持多服务器配置，支持qq/163等个人邮箱，可以配置多个邮箱，1个发送失败会按根据配置按顺序依次发送直到成功为止

如何使用
----

[](#如何使用)

### 发送短信验证码示例

[](#发送短信验证码示例)

```
        use hotzhan\verifycode\sms\SmsVerifyCode;

        //注册验证码
        public function regSms(SmsVerifyCode $sms)
        {
            //前端获取到手机号码
            $param = request()->param();
            $phoneNumber = $param['mobile'];
            //发送注册验证码
            $sms->sendRegisterSms($phoneNumber);
            //返回验证码发送结果，结果里包含token，需要返回给前端，验证时前端需要提交这个token
            return $sms->getResultData();
        }

        //验证码校验
        public function checkSms(SmsVerifyCode $sms)
        {
            $param = request()->param();
            //$param里的字段根据自己前端的设置
            $phoneNumber = $param['mobile'];
            $code = $param['code'];
            $token = $param['smstoken'];
            //校验验证码和对应的手机号
            $res = $sms->checkSmsVerifyCode($token, $code, $phoneNumber);
            if(!$res)//验证码校验不通过
                return $sms->getResultData();
        }

```

### 发送邮件验证码示例

[](#发送邮件验证码示例)

```
        use hotzhan\verifycode\mail\MailVerifyCode;

        //注册验证码
        public function regMail(MailVerifyCode $mail)
        {
            //前端获取到手机号码
            $param = request()->param();
            $mailAddress = $param['address']; //12345678@qq.com
            //给对应邮箱发送验证码
            $mail->sendVerifyCodeMail($mailAddress)
            //返回验证码发送结果，结果里包含token，需要返回给前端，验证时前端需要提交这个token
            return $mail->getResultData();
        }

        //验证码校验
        public function checkMail(MailVerifyCode $mail)
        {
            $param = request()->param();
            //$param里的字段根据自己前端的设置
            $mailAddress = $param['address'];
            $code = $param['code'];
            $token = $param['mailtoken'];
            //校验验证码和对应的邮箱
            $res = $mail->checkMailVerifyCode($token, $code, $mailAddress);
            if(!$res)//验证码校验不通过
                return $sms->getResultData();
        }
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

793d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5616ced66084253be5a0fe6983c9edfa98c55a42f1aa8590ce7b5026bb6d12f5?d=identicon)[hotzhan](/maintainers/hotzhan)

---

Top Contributors

[![hotzhan](https://avatars.githubusercontent.com/u/153747356?v=4)](https://github.com/hotzhan "hotzhan (5 commits)")

### Embed Badge

![Health badge](/badges/hotzhan-think-verifycode/health.svg)

```
[![Health](https://phpackages.com/badges/hotzhan-think-verifycode/health.svg)](https://phpackages.com/packages/hotzhan-think-verifycode)
```

###  Alternatives

[utopia-php/messaging

A simple, light and advanced PHP messaging library

23187.5k4](/packages/utopia-php-messaging)[jetsung/pusher

A message push extension.

168.6k](/packages/jetsung-pusher)

PHPackages © 2026

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