helper.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. use think\captcha\facade\Captcha;
  12. use think\facade\Route;
  13. use think\Response;
  14. /**
  15. * @param string $config
  16. * @return \think\Response
  17. */
  18. function captcha($config = null): Response
  19. {
  20. return Captcha::create($config);
  21. }
  22. /**
  23. * @param $config
  24. * @return string
  25. */
  26. function captcha_src($config = null): string
  27. {
  28. return Route::buildUrl('/captcha' . ($config ? "/{$config}" : ''));
  29. }
  30. /**
  31. * @param $id
  32. * @return string
  33. */
  34. function captcha_img($id = ''): string
  35. {
  36. $src = captcha_src($id);
  37. return "<img src='{$src}' alt='captcha' onclick='this.src=\"{$src}?s=\"+Math.random();' />";
  38. }
  39. /**
  40. * @param string $value
  41. * @return bool
  42. */
  43. function captcha_check($value)
  44. {
  45. return Captcha::check($value);
  46. }