Browse Source

Merge branch 'master' of wangchaoqun/wxservice into master

王超群 2 years ago
parent
commit
08ee71f603

+ 38 - 4
src/main/java/com/ematou/wxservice/controller/WeChatViewController.java

@@ -1,18 +1,21 @@
 package com.ematou.wxservice.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ematou.wxservice.common.web.R;
 import com.ematou.wxservice.entity.pojo.ScannVO;
 import com.ematou.wxservice.entity.pojo.UserInfo;
+import com.ematou.wxservice.entity.vo.BindIngVo;
 import com.ematou.wxservice.entity.vo.BindingInfo;
 import com.ematou.wxservice.service.UserInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
 
 /**
  * @author lhm
@@ -36,7 +39,7 @@ public class WeChatViewController {
         //判断是否注册
         UserInfo msg = userInfoService.queryUserInfoByOpenId(request.getParameter("openid"));
         if (msg != null) {
-            return "qrcode";
+            return "return";
         } else {
             return "binding";
         }
@@ -44,7 +47,7 @@ public class WeChatViewController {
     }
 
 
-    @PostMapping("/binding")
+ /*   @PostMapping("/binding")
     public String binding(HttpServletRequest request, Model model) {
         String phone = request.getParameter("phone1");
         String openid = request.getParameter("btnSendCode2");
@@ -61,8 +64,39 @@ public class WeChatViewController {
         }
         model.addAttribute("errmsg", "验证码错误!");
         return "binding";
+    }*/
+
+    @PostMapping("/binding")
+    @ResponseBody
+    public R<?>  binding(@RequestBody BindIngVo bindIngVo) {
+        String phone = bindIngVo.getPhone();
+        if(StringUtils.isEmpty(phone)){
+            return new R<String>().error("手机号不能为空!");
+        }
+        String openid = bindIngVo.getOpenId();
+        if(StringUtils.isEmpty(openid)){
+            return new R<String>().error("网络异常,请退出重试");
+        }
+        String code1 = bindIngVo.getCode();
+        if(StringUtils.isEmpty(phone)){
+            return new R<String>().error("验证码不能为空!");
+        }
+
+        BindingInfo bindingInfo = new BindingInfo();
+        bindingInfo.setOpenId(openid);
+        bindingInfo.setTellPhoneNumber(phone);
+        bindingInfo.setValidateCode(code1);
+
+        boolean result = userInfoService.binding(bindingInfo);
+
+        if (result) {
+            return new R<String>().success();
+        }
+        return new R<String>().error("验证码错误或未匹配到手机号!");
     }
 
+
+
     /**
      * 扫一扫
      *

+ 34 - 0
src/main/java/com/ematou/wxservice/entity/vo/BindIngVo.java

@@ -0,0 +1,34 @@
+package com.ematou.wxservice.entity.vo;
+
+/**
+ * 绑定手机号类
+ */
+public class BindIngVo {
+    private String phone;
+    private String code;
+    private String openId;
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getOpenId() {
+        return openId;
+    }
+
+    public void setOpenId(String openId) {
+        this.openId = openId;
+    }
+}

+ 100 - 63
src/main/resources/static/js/clean.js

@@ -1,78 +1,83 @@
-(function($) {
-    $.fn.extend({
-        addClear: function(options) {
-            var options = $.extend({
-                closeSymbol: "&#10006;",
-                color: "#CCC",
-                top: 1,
-                right: 4,
-                returnFocus: true,
-                showOnLoad: false,
-                onClear: null
-            }, options);
-
-            $(this).wrap("<span style='position:relative;' class='add-clear-span'>");
-            $(this).after("<a href='#clear'>" + options.closeSymbol + "</a>");
-            $("a[href='#clear']").css({
-                color: options.color,
-                'text-decoration': 'none',
-                display: 'none',
-                'line-height': 1,
-                overflow: 'hidden',
-                position: 'absolute',
-                right: options.right,
-                top: options.top
-            }, this);
-
-            if ($(this).val().length >= 1 && options.showOnLoad === true) {
-                $(this).siblings("a[href='#clear']").show();
-            }
+(function ($) {
+        $.fn.extend({
+            addClear: function (options) {
+                var options = $.extend({
+                    closeSymbol: "&#10006;",
+                    color: "#CCC",
+                    top: 1,
+                    right: 4,
+                    returnFocus: true,
+                    showOnLoad: false,
+                    onClear: null
+                }, options);
+
+                $(this).wrap("<span style='position:relative;' class='add-clear-span'>");
+                $(this).after("<a href='#clear'>" + options.closeSymbol + "</a>");
+                $("a[href='#clear']").css({
+                    color: options.color,
+                    'text-decoration': 'none',
+                    display: 'none',
+                    'line-height': 1,
+                    overflow: 'hidden',
+                    position: 'absolute',
+                    right: options.right,
+                    top: options.top
+                }, this);
 
-            $(this).keyup(function() {
-                if ($(this).val().length >= 1) {
+                if ($(this).val().length >= 1 && options.showOnLoad === true) {
                     $(this).siblings("a[href='#clear']").show();
-                } else {
-                    $(this).siblings("a[href='#clear']").hide();
                 }
-            });
 
-            $("a[href='#clear']").click(function() {
-                $(this).siblings("input").val("");
-                $(this).hide();
-                if (options.returnFocus === true) {
-                    $(this).siblings("input").focus();
-                }
-                if (options.onClear) {
-                    options.onClear($(this).siblings("input"));
-                }
-                return false;
-            });
-            return this;
-        }
-    });
-}
+                $(this).keyup(function () {
+                    if ($(this).val().length >= 1) {
+                        $(this).siblings("a[href='#clear']").show();
+                    } else {
+                        $(this).siblings("a[href='#clear']").hide();
+                    }
+                });
+
+                $("a[href='#clear']").click(function () {
+                    $(this).siblings("input").val("");
+                    $(this).hide();
+                    if (options.returnFocus === true) {
+                        $(this).siblings("input").focus();
+                    }
+                    if (options.onClear) {
+                        options.onClear($(this).siblings("input"));
+                    }
+                    return false;
+                });
+                return this;
+            }
+        });
+    }
 )(jQuery);
 
-// var phoneReg = /^1\d{11}$/; //
+var phoneReg = /^1\d{10}$/; //
 var count = 60;
 var InterValObj1;
 var curCount1;
+
 function sendMessage1() {
     curCount1 = count;
     var phone = $.trim($('#phone1').val());
-    // if (!phoneReg.test(phone)) {
-    //     alert("请输入有效的手机号码");
-    //     return false;
-    // }
+    if (!phoneReg.test(phone)) {
+        alert("请输入有效的手机号码");
+        return false;
+    }
     $("#btnSendCode1").attr("disabled", "true");
     $("#btnSendCode1").val(+curCount1 + "秒再获取");
 
-    $.get("https://wxservice.ds-bay.com/user/send?phoneNumber=" + phone+"&openId="+sessionStorage.getItem("openid"), function (res) {
+    $.get("https://wxservice.ds-bay.com/user/send?phoneNumber=" + phone + "&openId=" + sessionStorage.getItem("openid"), function (res) {
     })
 
     InterValObj1 = window.setInterval(SetRemainTime1, 1000);
 
 }
+returnMethod = function  (){
+    WeixinJSBridge.call('closeWindow');
+    window.close();
+}
 function SetRemainTime1() {
     if (curCount1 == 0) {
         window.clearInterval(InterValObj1);
@@ -89,26 +94,56 @@ submitForm = function () {
 
     if (flag) {
         var openid = getUrlParam("openid");
-        $("#btnSendCode2").val(openid);
-        $("#submit_form").submit();
+        $.ajax({
+            url: "https://wxservice.ds-bay.com/binding",
+            data: JSON.stringify({phone: $("#phone1").val(), code: $("#code1").val(), openId: openid}),
+            type: "POST",
+            contentType: 'application/json',
+            dataType: "json",
+            success: function (result) {
+                if(result && result.code == "0"){
+
+                    // window.location.href="../../templates/return.html";
+
+                    alert("绑定成功!请扫码取件!")
+                    returnMethod();
+                    var t1 = window.setTimeout(function() {
+                        returnMethod();
+                        window.clearTimeout(t1) // 去除定时器
+                    },1000)
+
+                }else{
+                    alert(result.message);
+                }
+            },
+            error: function () {
+                alert("请求失败");
+            }
+        });
     }
 }
-checkInput = function (){
+checkInput = function () {
     var a = true;
     var code = $("#code1").val;
-    if ($.trim(code) === '') {
+    if (!code) {
         a = false;
         alert("请输入验证码!");
         return a;
     }
 
+    var phone1 = $("#phone1").val;
+    if (!phone1) {
+        a = false;
+        alert("请输入手机号!");
+        return a;
+    }
     return a;
 }
 
 
 // 强制关注公众号,获取openid
 getCode = function () {
-    if (sessionStorage.getItem("openid")&&sessionStorage.getItem("openid")!="undefined") {
+    if (sessionStorage.getItem("openid") && sessionStorage.getItem("openid") != "undefined") {
         return false;
     }
     var code = getUrlParam('code') // 截取路径中的code,如果没有就去微信授权,如果已经获取到了就直接传code给后台获取openId
@@ -125,7 +160,7 @@ getOpenId = function (code) {
     $.ajax({
         type: 'GET',
         dataType: 'text',
-        url: 'https://wxservice.ds-bay.com/oauth2?code='+code,
+        url: 'https://wxservice.ds-bay.com/oauth2?code=' + code,
         success: function (res) {
             if (res.status == -1) {
                 // 提示没有关注公众号 没有关注公众号跳转到关注公众号页面
@@ -142,14 +177,16 @@ getOpenId = function (code) {
     });
 }
 //获取地址栏的参数
-getUrlParam= function (name) {
+getUrlParam = function (name) {
     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
-    if (r != null) return unescape(r[2]); return null;
+    if (r != null) return unescape(r[2]);
+    return null;
 }
 //页面执行调用
 getCode();
 window.scroll(0, 0);
+
 function binding() {
     alert(1)
 }

+ 1 - 1
src/main/resources/templates/binding.html

@@ -42,7 +42,7 @@
                 <div class="aui-code-box">
                     <h2>绑定手机</h2>
                     <p>登录及找回密码的途径</p>
-                    <form id="submit_form" action="https://wxservice.ds-bay.com/binding" method="post">
+                    <form id="submit_form" ><!--action="https://wxservice.ds-bay.com/binding" method="post"-->
                         <p class="aui-code-line">
                             <em>+86</em>
                             <input type="text" class="aui-code-line-input" name="phone1" value="" id="phone1" autocomplete="off" placeholder="请输入已绑定的手机号" style="padding-left:28px;"/>

+ 1 - 1
src/main/resources/templates/return.html

@@ -43,7 +43,7 @@
                     </div>
                     <div class="aui-back-title">
                         <h2>绑定成功</h2>
-                        <p>点击返回按钮到公众号查询取件码</p>
+                        <p>点击返回按钮到公众号扫码取件</p>
                     </div>
                     <div class="aui-back-button">
                         <button type="button" onclick="returnMethod()" id="return_btn">返  回</button>