Seccode.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 验证码
  4. *
  5. */
  6. namespace app\home\controller;
  7. use think\captcha\facade\Captcha;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Seccode
  16. {
  17. /**
  18. *产生验证码
  19. */
  20. public function makecode()
  21. {
  22. $config = [
  23. 'fontSize' => 20, // // 验证码字体大小
  24. 'length' => 4, // 验证码位数
  25. 'useNoise' => false, //是否添加杂点
  26. 'useCurve' => true,
  27. 'imageH' => 50, //高度
  28. 'imageW' => 150,
  29. ];
  30. config($config, 'captcha');
  31. $captcha = Captcha::create();
  32. return $captcha;
  33. }
  34. /**
  35. * AJAX验证
  36. */
  37. public function check()
  38. {
  39. $config = [];
  40. if (input('param.reset') == 'false') {
  41. //验证成功之后,验证码是否失效,验证成功后是否重置
  42. $config['reset'] = FALSE;
  43. }
  44. config($config, 'captcha');
  45. $code = input('param.captcha');
  46. if (captcha_check($code)) {
  47. exit('true');
  48. } else {
  49. exit('false');
  50. }
  51. }
  52. }