ClickWordController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types=1);
  3. use Fastknife\Utils\RandomUtils;
  4. use Fastknife\Service\ClickWordCaptchaService;
  5. class ClickWordController
  6. {
  7. public function get()
  8. {
  9. $config = require '../src/config.php';
  10. $service = new ClickWordCaptchaService($config);
  11. $data = $service->get();
  12. echo json_encode([
  13. 'error' => false,
  14. 'repCode' => '0000',
  15. 'repData' => $data,
  16. 'repMsg' => null,
  17. 'success' => true,
  18. ]);
  19. }
  20. /**
  21. * 一次验证
  22. */
  23. public function check()
  24. {
  25. $config = require '../src/config.php';
  26. $service = new ClickWordCaptchaService($config);
  27. $data = $_REQUEST;
  28. $msg = null;
  29. $error = false;
  30. $repCode = '0000';
  31. try {
  32. $service->check($data['token'], $data['pointJson']);
  33. } catch (\Exception $e) {
  34. $msg = $e->getMessage();
  35. $error = true;
  36. $repCode = '6111';
  37. }
  38. echo json_encode([
  39. 'error' => $error,
  40. 'repCode' => $repCode,
  41. 'repData' => null,
  42. 'repMsg' => $msg,
  43. 'success' => ! $error,
  44. ]);
  45. }
  46. /**
  47. * 二次验证
  48. */
  49. public function verification()
  50. {
  51. $config = require '../src/config.php';
  52. $service = new ClickWordCaptchaService($config);
  53. $data = $_REQUEST;
  54. $msg = null;
  55. $error = false;
  56. $repCode = '0000';
  57. try {
  58. if(isset($data['captchaVerification'])){
  59. $service->verificationByEncryptCode($data['captchaVerification']);
  60. }else if (isset($data['token']) && isset($data['pointJson'])){
  61. $service->verification($data['token'], $data['pointJson']);
  62. } else {
  63. throw new \Exception('参数错误!');
  64. }
  65. } catch (\Exception $e) {
  66. $msg = $e->getMessage();
  67. $error = true;
  68. $repCode = '6111';
  69. }
  70. echo json_encode([
  71. 'error' => $error,
  72. 'repCode' => $repCode,
  73. 'repData' => null,
  74. 'repMsg' => $msg,
  75. 'success' => ! $error,
  76. ]);
  77. }
  78. }