Seccode.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\api\controller;
  3. use think\captcha\facade\Captcha;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 图片验证码控制器
  10. */
  11. class Seccode extends MobileMall
  12. {
  13. /**
  14. * 产生验证码
  15. * type 验证码传入可标识的信息
  16. */
  17. public function makecode()
  18. {
  19. $config = [
  20. // 验证码字体大小
  21. 'fontSize' => 40,
  22. // 验证码位数
  23. 'length' => 4,
  24. // 关闭验证码杂点
  25. 'useNoise' => false,
  26. ];
  27. config($config, 'captcha');
  28. $captcha = Captcha::create();
  29. return $captcha;
  30. }
  31. /**
  32. * @api {POST} api/Seccode/check 检查验证码
  33. * @apiVersion 1.0.0
  34. * @apiGroup Seccode
  35. *
  36. * @apiParam {String} captcha 验证码
  37. *
  38. * @apiSuccess {String} code 返回码,10000为成功
  39. * @apiSuccess {String} message 返回消息
  40. * @apiSuccess {Object} result 返回数据
  41. */
  42. public function check()
  43. {
  44. $captch = input('param.captcha');
  45. if (captcha_check($captch)) {
  46. ds_json_encode(10000, '');
  47. } else {
  48. ds_json_encode(10001, '验证码错误', ['code' => '']);
  49. }
  50. }
  51. }