helper.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 = '', $domid = ''): string
  35. {
  36. $src = captcha_src($id);
  37. $domid = empty($domid) ? $domid : "id='" . $domid . "'";
  38. return "<img src='{$src}' alt='captcha' " . $domid . " onclick='this.src=\"{$src}?\"+Math.random();' />";
  39. }
  40. /**
  41. * @param string $value
  42. * @return bool
  43. */
  44. function captcha_check($value)
  45. {
  46. return Captcha::check($value);
  47. }