diff --git a/SliderCaptchaController.java b/SliderCaptchaController.java new file mode 100644 index 0000000000000000000000000000000000000000..7a8c10f39ccbaabf972ecd20666a61d63e76c5cf --- /dev/null +++ b/SliderCaptchaController.java @@ -0,0 +1,37 @@ +package com.fmj43.fanyoutong.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/sliderCaptcha") +public class SliderCaptchaController { + + + @PostMapping("/isVerify") + public boolean isVerify(@RequestParam(value = "datas") String datazz) { + List datas=new ArrayList<>(); + for (int i = 0; i < datazz.length(); i++) { + char c = datazz.charAt(i); + if (c >= '0' && c <= '9') { + datas.add(Integer.valueOf(String.valueOf(c))); + } + } + int sum = 0; + for (Integer data : datas) { + sum += data; + } + double avg = sum * 1.0 / datas.size(); + double sum2 = 0.0; + for (Integer data : datas) { + sum2 += Math.pow(data - avg, 2); + } + double stddev = sum2 / datas.size(); + System.out.println("验证码判断"+(stddev != 0)); + return stddev != 0; + } + +} diff --git a/src/disk/longbow.slidercaptcha.js b/src/disk/longbow.slidercaptcha.js index a1dcf1aac3ffbd99780a9d5747c08493857d0b22..8659a8967cc23d0c34f9309592c2cb4390ef8861 100644 --- a/src/disk/longbow.slidercaptcha.js +++ b/src/disk/longbow.slidercaptcha.js @@ -1,4 +1,4 @@ -(function () { +(function () { 'use strict'; var extend = function () { @@ -55,15 +55,18 @@ }, verify: function (arr, url) { var ret = false; - fetch(url, { - method: 'post', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + $.ajax({ + url:url, + data:{ + "datas":JSON.stringify(arr), }, - body: JSON.stringify(arr) - }).then(function (result) { - ret = result; + dataType:"json", + type:"post", + async:false, + success:function(result){ + ret=JSON.stringify(result); + console.log("返回结果:"+ret) + } }); return ret; }, @@ -341,4 +344,4 @@ this.text.textContent = this.options.loadingText; this.img.setSrc(); }; -})(); \ No newline at end of file +})();