From 86a4ef8d843913e75c957f24b71b091b3cf05747 Mon Sep 17 00:00:00 2001 From: yl-yue Date: Mon, 9 Sep 2019 16:32:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?doc=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AFJAVA=E4=BB=A3=E7=A0=81=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 28 +++++++++++++++++++++++++++- README.zh-CN.md | 26 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cd6d42..5fa3555 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Slider Captcha +## Slider Captcha English | 中文 @@ -191,6 +191,32 @@ public class CaptchaController : ControllerBase } ``` +3. Server Code(JAVA SpringBoot):You may have precision problems, but you can use BigDecimal optimization +```java +@RestController +@RequestMapping("/sliderCaptcha") +public class SliderCaptchaController { + + @PostMapping("/isVerify") + public boolean isVerify(List datas) { + 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(); + return stddev != 0; + } + +} +``` + [linked issue](https://gitee.com/LongbowEnterprise/SliderCaptcha/issues/I110MF?from=project-issue) ## Contribution diff --git a/README.zh-CN.md b/README.zh-CN.md index 14ca668..99d70da 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -198,6 +198,32 @@ public class CaptchaController : ControllerBase } ``` +3. 服务器端代码(JAVA SpringBoot):可能会存在精度问题,采用BigDecimal计算即可 +```java +@RestController +@RequestMapping("/sliderCaptcha") +public class SliderCaptchaController { + + @PostMapping("/isVerify") + public boolean isVerify(List datas) { + 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(); + return stddev != 0; + } + +} +``` + [相关问题](https://gitee.com/LongbowEnterprise/SliderCaptcha/issues/I110MF?from=project-issue) ## 参与贡献 -- Gitee From 73318faf0a9869a066599920386cd7ec456775a9 Mon Sep 17 00:00:00 2001 From: yl-yue Date: Mon, 9 Sep 2019 17:25:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?doc:=20=E4=BC=98=E5=8C=96=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++---- README.zh-CN.md | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5fa3555..72a165c 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,8 @@ Please go to [Issue](../../issues) page to create issue ## Q&A ### Verify On Server Side - -1. Client code +#### Client Code Example +##### 1. JavaScript ```js verify: function (arr, url) { var ret = false; @@ -166,7 +166,8 @@ $('#captcha').sliderCaptcha({ }); ``` -2. Server Code(NETCore WebApi) +#### Server Code Example +##### 1. NETCore WebApi ```csharp /// /// slider verify web api @@ -191,7 +192,8 @@ public class CaptchaController : ControllerBase } ``` -3. Server Code(JAVA SpringBoot):You may have precision problems, but you can use BigDecimal optimization +##### 2. JAVA SpringBoot +You may have precision problems, but you can use BigDecimal optimization ```java @RestController @RequestMapping("/sliderCaptcha") diff --git a/README.zh-CN.md b/README.zh-CN.md index 99d70da..b16ec3d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -130,8 +130,8 @@ reset | $('#captcha').sliderCaptcha('reset') | 重置控件 ## 常见问题 ### 服务器端认证 - -1. 客户端代码 +#### 客户端代码示例 +##### 1. JavaScript 控件配置信息中有 remoteUrl 和 verify 两个配置项,合理正确的设置这两个配置项即可达到想要的服务器端认证逻辑 remoteUrl 默认值为 null 表示未启用服务器端认证方式,设置请求的 webapi 地址后启用服务器端认证方法 控件默认请求服务器端方法如下,可适当进行更改 @@ -173,7 +173,8 @@ $('#captcha').sliderCaptcha({ }); ``` -2. 服务器端代码(NETCore WebApi) +#### 服务器端代码示例 +##### 1. NETCore WebApi ```csharp /// /// 滑块服务器端验证方法 @@ -198,7 +199,8 @@ public class CaptchaController : ControllerBase } ``` -3. 服务器端代码(JAVA SpringBoot):可能会存在精度问题,采用BigDecimal计算即可 +##### 2. JAVA SpringBoot +可能会存在精度问题,采用BigDecimal计算即可 ```java @RestController @RequestMapping("/sliderCaptcha") -- Gitee