Vaptcha.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace Sakura\API;
  3. class Vaptcha
  4. {
  5. public function script()
  6. {
  7. $vid = iro_opt('vaptcha_vid');
  8. $color = iro_opt('theme_skin');
  9. $scene = iro_opt('vaptcha_scene');
  10. return <<<JS
  11. <script src="https://v-cn.vaptcha.com/v3.js"></script>
  12. <script>
  13. vaptcha({
  14. vid: `{$vid}`,
  15. type: 'click',
  16. scene: `{$scene}`,
  17. container: '#vaptchaContainer',
  18. color: `{$color}`
  19. }).then(function (vaptchaObj) {
  20. vaptchaObj.renderTokenInput('wp-login.php');
  21. vaptchaObj.render();
  22. });
  23. </script>
  24. JS;
  25. }
  26. public function html()
  27. {
  28. return <<<HTML
  29. <p>
  30. <label for="user_login">验证码</label>
  31. </p>
  32. <div id="vaptchaContainer" class="vaptchaContainer">
  33. <div class="vaptcha-init-main">
  34. <div class="vaptcha-init-loading">
  35. <a href="/" target="_blank">
  36. <svg
  37. xmlns="http://www.w3.org/2000/svg"
  38. xmlns:xlink="http://www.w3.org/1999/xlink"
  39. width="48px"
  40. height="60px"
  41. viewBox="0 0 24 30"
  42. style="enable-background: new 0 0 50 50; width: 14px; height: 14px; vertical-align: middle"
  43. xml:space="preserve"
  44. >
  45. <rect x="0" y="9.22656" width="4" height="12.5469" fill="#CCCCCC">
  46. <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
  47. <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
  48. </rect>
  49. <rect x="10" y="5.22656" width="4" height="20.5469" fill="#CCCCCC">
  50. <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
  51. <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
  52. </rect>
  53. <rect x="20" y="8.77344" width="4" height="13.4531" fill="#CCCCCC">
  54. <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
  55. <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
  56. </rect>
  57. </svg>
  58. </a>
  59. <span class="vaptcha-text">Vaptcha Initializing...</span>
  60. </div>
  61. </div>
  62. </div>
  63. HTML;
  64. }
  65. public function checkVaptcha($url, $token, $ip)
  66. {
  67. $param = [
  68. 'id' => iro_opt('vaptcha_vid'),
  69. 'secretkey' => iro_opt('vaptcha_key'),
  70. 'scene' => iro_opt('vaptcha_scene'),
  71. 'token' => $token,
  72. 'ip' => $ip,
  73. ];
  74. return $this->post($url, $param);
  75. }
  76. public function post($url, $param = [])
  77. {
  78. $response = wp_safe_remote_post($url, [
  79. 'timeout' => 15,
  80. 'body' => $param,
  81. ]);
  82. if (is_wp_error($response)) {
  83. $errorMessage = $response->get_error_message();
  84. return $errorMessage;
  85. } else {
  86. return json_decode($response['body']);
  87. }
  88. }
  89. }