酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.6 KiB

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. \think\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
  12. \think\Validate::extend('captcha', function ($value, $id = "") {
  13. return captcha_check($value, $id, (array)\think\Config::get('captcha'));
  14. });
  15. \think\Validate::setTypeMsg('captcha', '验证码错误!');
  16. /**
  17. * @param string $id
  18. * @param array $config
  19. * @return \think\Response
  20. */
  21. function captcha($id = "", $config = [])
  22. {
  23. $captcha = new \think\captcha\Captcha($config);
  24. return $captcha->entry($id);
  25. }
  26. /**
  27. * @param $id
  28. * @return string
  29. */
  30. function captcha_src($id = "")
  31. {
  32. return \think\Url::build('/captcha' . ($id ? "/{$id}" : ''));
  33. }
  34. /**
  35. * @param $id
  36. * @return mixed
  37. */
  38. function captcha_img($id = "")
  39. {
  40. return '<img src="' . captcha_src($id) . '" alt="captcha" />';
  41. }
  42. /**
  43. * @param $value
  44. * @param string $id
  45. * @param array $config
  46. * @return bool
  47. */
  48. function captcha_check($value, $id = "", $config = [])
  49. {
  50. $captcha = new \think\captcha\Captcha($config);
  51. return $captcha->check($value, $id);
  52. }