BlockPuzzleController.php 2.2 KB

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