Seccode.php 1.6 KB

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