Yii2 验证码 captcha for rest api
2016-11-05 16:49
615 查看
前言
用yii2的restful做了一个APP后端,yii2自带速率控制,很爽,但是有的地方又必须用图片验证码,比如登录的时候,要防止暴力破解。yii2是自带图片验证码的,但是封装的太好了,只适用于web。找来找去,packagist.org上也找到了一个比较好的,叫Gregwar/Captcha,但是用了之后,又转念一想,能不能自行封装一下yii2自带的那个图片验证码呢?于是就有了下面的代码代码实现
更多类属性请访问yii\captcha\CaptchaAction类文档<?php namespace app\models\imgcode; use yii\captcha\CaptchaAction; class CodeImgGenerate extends CaptchaAction{ private $verifycode; public function __construct(){ $this->init(); //更多api请访问yii\captcha\CaptchaAction类文档 $this->minLength = 4; $this->maxLength = 5; $this->foreColor = 0x00ff00; $this->width = 80; $this->height = 45; } //return image data//返回图片二进制 public function inline(){ return $this->renderImage($this->getPhrase()); } //return image code//返回图片验证码 public function getPhrase(){ if($this->verifycode){ return $this->verifycode; }else{ return $this->verifycode = $this->generateVerifyCode(); } } } ?>
更新2016-11-18:
已经上传到packagist.org了,走你,可以直接composer,方便快捷相关文章推荐
- java 访问 salesforece rest api
- 如何通过REST API登录Portal for ArcGIS
- “API design is like sex: Make one mistake and support it for the rest of your life.”
- Kylin Rest API FOR Java
- ArcGIS API for Silverlight中通过https访问rest服务
- Yii2 captcha 验证码,点击不刷新,解决方案
- JIRA REST API FOR Excel VBA
- 文档通知百度云推送通知埋的大大的坑,成功测试REST API for PHP服务端
- ArcGIS API for Silverlight中通过https访问rest服务(二)
- yii2-RBAC-rest api开发思路
- Yii2.x 中captcha 验证码使用的一些心得
- ArcGIS API for Silverlight中通过https访问rest服务(三)
- Chrome Restful Api 测试工具 Postman-REST-Client离线安装包下载,Axure RP Extension for Chrome离线版下载
- ArcGIS Server Rest for Javascript API 学习教程-2
- ArcGIS API for javascript开发笔记(六)——REST详解及如何使用REST API调用GP服务
- SuperMap iClient for Silverlight API聚合ArcGIS server的REST服务
- 关于yii2 REST api 的问题
- ArcGIS API for javascript开发笔记(六)——REST详解及如何使用REST API调用GP服务
- SQL Data Services Abandons REST for TDS API and Knocks My Socks Off
- ArcGIS Server Rest for Javascript API 学习教程-4