当前位置: 首页 > news >正文

龙岗这边哪里有教做网站的北京seo编辑

龙岗这边哪里有教做网站的,北京seo编辑,自适应网站,深圳燃气公众号1. 安装 gregwar/captcha 图片验证码接口的流程是: 生成图片验证码 生成随机的 key,将验证码文本存入缓存。 返回随机的 key,以及验证码图片 # 不限于 laravel 普通 php 项目也可以使用额 $ composer require gregwar/captcha2. 开发接口 …

1. 安装 gregwar/captcha

图片验证码接口的流程是:

生成图片验证码
生成随机的 key,将验证码文本存入缓存。
返回随机的 key,以及验证码图片

# 不限于 laravel 普通 php 项目也可以使用额
$ composer require gregwar/captcha

2. 开发接口

1). 新建路由

routes/web.php

oute::prefix('auth')->group(function (){Route::post('captchas', [CaptchasController::class, 'store']);    
});

2). 新建控制器和表单验证类

创建 CaptchasController 以及 CaptchaRequest

$ php artisan make:controller CaptchasController
$ php artisan make:request Api/CaptchaRequest

修改文件如下

app/Http/Requests/Api/CaptchaRequest.php

<?phpnamespace App\Http\Requests\Api;use Illuminate\Foundation\Http\FormRequest;class CaptchaRequest extends FormRequest
{/*** Determine if the user is authorized to make this request.** @return bool*/public function authorize(){return true;}/*** Get the validation rules that apply to the request.** @return array*/public function rules(){return [// 'phone' => 'required|regex:/^1[34578]\d{9}$/|unique:users',];}
}

app/Http/Controllers/CaptchasController.php


<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Gregwar\Captcha\CaptchaBuilder;
use App\Http\Requests\Api\CaptchaRequest;
class CaptchasController extends Controller
{public function store(CaptchaRequest $request, CaptchaBuilder $captchaBuilder){   // $key = 'captcha-'.str_random(15);$key = 'captcha-'.time();$phone = $request->phone;$captcha = $captchaBuilder->build();$expiredAt = now()->addMinutes(2);\Cache::put($key, ['phone' => $phone, 'code' => $captcha->getPhrase()], $expiredAt);$result = ['captcha_key' => $key,'expired_at' => $expiredAt->toDateTimeString(),'captcha_image_content' => $captcha->inline()];return $result;return $this->response->$result->setStatusCode(201);}
}

代码分析

use Gregwar\Captcha\CaptchaBuilder;
创建验证码实例: $captcha = $captchaBuilder->build();
获取验证码值: $captcha->getPhrase(); // abcd…
获取验证码图片的 base64: $captcha->inline() // base64 xxxxx

3). 代码分解

分析一下代码:

增加了 CaptchaRequest 要求用户必须通过手机号调用图片验证码接口。
controller 中,注入CaptchaBuilder,通过它的 build 方法,创建出来验证码图片
使用 getPhrase 方法获取验证码文本,跟手机号一同存入缓存。
返回 captcha_key,过期时间以及 inline 方法获取的 base64 图片验证码
这里给图片验证码设置为 2 分钟过期,

4).请求结果

在这里插入图片描述

在这里插入图片描述

http://www.wangmingla.cn/news/160556.html

相关文章:

  • wordpress edc电商网站seo优化
  • 网站服务器建设软件重庆seo快速优化
  • 呼市做网站公司百度关键词排名查询
  • 一个网页大概多少钱广西壮族自治区在线seo关键词排名优化
  • 网站资源整合与建设百度网址大全在哪里找
  • 各种购物网站大全互联网广告平台代理
  • 网站域名的设置优化网络的软件
  • 网站建站授权模板下载苏州seo排名公司
  • 网站百度seo推广怎么做网络营销理论基础有哪些
  • 企业网站小程序源码著名的网络营销案例
  • 做站用什么网站程序seo排名优化技巧
  • 做网站的公司现在还 赚钱吗6中国最新消息今天
  • 网站弹出广告gif出处上海十大营销策划公司排名
  • 祥云平台做的网站效果好最新引流推广方法
  • 成都都网站建设百度竞价电话
  • 免费个人网页制作网站天津的网络优化公司排名
  • 积极做好门户网站建设工作广州婚恋网站排名
  • 纺织面料做哪个网站好91手机用哪个浏览器
  • wordpress 图片弹出seo是什么牌子
  • 上海网站建设设计制作私人做网站建设
  • 网站建设公司发展方向及趋势百度搜索高级搜索技巧
  • 太原网站建设鸣蝉百度手机点击排名工具
  • 做网站设计累吗企业培训课程推荐
  • 软件外包项目网站中国培训网是国家公认的吗
  • jsp asp php哪个做网站广州信息流推广公司排名
  • 怎样把网站做的好看东莞网络优化服务商
  • 老网站权重低的原因襄阳seo优化排名
  • 怎样在工商局网站做公示抖音seo优化软件
  • 做头像的网站横杆带字百度seo在哪里
  • wordpress后台速度慢苏州seo公司