Просмотр исходного кода

Merge remote-tracking branch 'origin/dev' into dev

hejq 8 лет назад
Родитель
Сommit
5deb93402d

+ 4 - 4
donate-service/src/main/java/com/uas/service/donate/controller/AlipayController.java

@@ -75,8 +75,8 @@ public class AlipayController {
      * 手机 wap支付
      */
     @ResponseBody
-    @RequestMapping(value = "/wapPay", method = RequestMethod.GET)
-    public void wapPay(@RequestParam String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException {
+    @RequestMapping(value = "/wapPay", method = RequestMethod.POST)
+    public void wapPay(@RequestParam("jsonStr") String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException {
         ProjectRecode projectRecode= null;
         try {
             projectRecode = this.createProjectRecode(jsonStr);
@@ -109,8 +109,8 @@ public class AlipayController {
      * PC支付
      */
     @ResponseBody
-    @RequestMapping(value = "/pcPay", method = RequestMethod.GET)
-    public void pcPay(@RequestParam String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException {
+    @RequestMapping(value = "/pcPay", method = RequestMethod.POST)
+    public void pcPay(@RequestParam("jsonStr") String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException {
         //AlipayTradePayModel  sellerId
         ProjectRecode projectRecode= null;
         try {

+ 35 - 9
donate-service/src/main/resources/templates/index.ftl

@@ -13,6 +13,9 @@
     <link rel="stylesheet" href="static/css/bootstrap.min.css">
     <link rel="stylesheet" href="static/css/base.css">
     <link rel="stylesheet" type="text/css" href="static/css/kkpager_blue.css" />
+
+    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
+    <script type="text/javascript" src ="static/js/pay.js"></script>
     <style>
         body{
             font-family: "Microsoft Yahei", "微软雅黑";
@@ -738,29 +741,28 @@
                 <!--弹出窗-->
                 <div class="pop">
                     <div class="header clearfix">
-                        <p>$
-                            {project.name}</p>
+                        <p>${project.name}</p>
                         <div class="close fr" class="close">&times;</div>
                     </div>
                     <div class="body">
                         <div class="choose clearfix">
                             <span class="fl">捐款金额:</span>
                             <div class="fl">
-                                <ul>
+                                <ul id="choose-money">
                                     <li class="active">1元</li>
                                     <li>50元</li>
                                     <li>100元</li>
                                     <li>200元</li>
                                 </ul>
-                                <div class="write"><input type="text" placeholder="其他金额" class="form-control"/><em>元</em></div>
+                                <div class="write"><input type="text" placeholder="其他金额" class="form-control" id="custom-amount${project.id!''}"/><em>元</em></div>
                             </div>
                         </div>
                         <div class="choose clearfix">
                             <span class="fl">支付方式:</span>
-                            <div class="fl pay">
-                                <div class="item active"><a href=""><img src="static/images/zfb.png" alt=""/>支付宝</a></div>
-                                <div class="item"><a href=""><img src="static/images/wx.png" alt=""/>微信支付</a></div>
-                                <div class="item"><a href=""><img src="static/images/bank.png" alt=""/>网银支付</a></div>
+                            <div class="fl pay" id="pay-way">
+                                <div class="item active"><img src="static/images/zfb.png" alt=""/>支付宝</div>
+                                <div class="item"><img src="static/images/wx.png" alt=""/>微信支付</div>
+                                <div class="item"><img src="static/images/bank.png" alt=""/>网银支付</div>
                             </div>
                         </div>
                         <div class="choose clearfix">
@@ -770,7 +772,7 @@
                                 <input type="checkbox" class="fl"><span class="fl"><a href="">同意并接受《优软一元捐用户协议》</a></span>
                             </div>
                         </div>
-                        <a href="donationsOver"> <button>确认捐款</button></a>
+                        <#--<a href="donationsOver">--> <button onclick="pay(${project.id!''}, money, payWay)">确认捐款</button><#--</a>-->
                     </div>
                 </div>
             </div>
@@ -801,6 +803,7 @@
         $(e).parent().next().css('display','block');
         $("#hover-background").css('display','block');
     }
+
     //    banner
     $('#myCarousel').carousel({
         interval: 5000
@@ -906,6 +909,29 @@
           window.location.href="http://lj.ubtob.com/index?search="+search;
       }
     })
+
+    //选择金额
+    var money = 1;
+    $('#choose-money li').on('click', function (event) {
+        var lis = $('#choose-money li');
+        for (var i=0;i<lis.length; i++) {
+            $(lis[i]).removeClass('active');
+        }
+        $(event.target).addClass('active');
+        money = $(event.target).text()
+    })
+
+    //选择支付方式
+    var payWay = "支付宝";
+    $('#pay-way div').on('click', function (event) {
+        var divs = $('#pay-way div');
+        for (var i=0;i<divs.length; i++) {
+            $(divs[i]).removeClass('active');
+        }
+        $(event.target).addClass('active');
+        payWay = $(event.target).text()
+    })
+
 </script>
 </body>
 </html>

+ 155 - 0
donate-service/src/main/webapp/resources/js/pay.js

@@ -0,0 +1,155 @@
+/**
+ * Created by 黄诚天 on 2017-11-03.
+ */
+
+// var proId;
+// var amount;
+// var payWay;//0支付宝 1微信 2银联
+// var uuid = "10041166";
+
+const userAgent = navigator.userAgent;
+const isMobile = /(iPhone|iPad|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent);
+
+var pay =function (proId, amount, payWay) {
+     var customAmount = $("#custom-amount" + proId).val();
+     console.log(customAmount);
+    if ($.trim(customAmount) != "") {
+        var reg = "^(([0-9]+\.[0-9]{1,2})|([0-9]*[1-9][0-9]*\.[0-9]{1,2})|([0-9]*[1-9][0-9]*))$";
+        var patt = new RegExp(reg);
+        var r = patt.test(customAmount);
+        if (r) {
+            amount = customAmount;
+        } else {
+            alert('输入金额有误,请正确输入金额且最多保留两位小数!');
+            return;
+        }
+    }
+
+    var yuanIndex = amount.toString().indexOf("元");
+    if (yuanIndex > 0) {
+        amount = amount.toString().substring(0, yuanIndex);
+    }
+
+    //获取支付方式
+    if(payWay == "支付宝") {
+        aliPay(proId, amount);
+    } else if (payWay == "微信支付") {
+        wxPay();
+    } else if (payWay == "网银支付") {
+        unionPay();
+    }
+}
+
+
+var wxPay = function () {
+    //公众号支付js模板 需引入http://res.wx.qq.com/open/js/jweixin-1.0.0.js
+    //对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
+    //var userAgent = navigator.userAgent;
+    if (userAgent.match(/MicroMessenger/i) == 'MicroMessenger') {
+        //公众号支付逻辑(微信浏览器)
+        $.ajax({
+            url : "/wxpay/webPay",
+            type : "POST",
+            dataType : 'json',
+            //TODO ProjectRecord json数据
+            success : function(data) {
+                WeixinJSBridge.invoke('getBrandWCPayRequest', {
+                    "appId" : data.appId, //公众号名称,由商户传入       
+                    "timeStamp" : data.timeStamp, //时间戳,自1970年以来的秒数       
+                    "nonceStr" : data.nonceStr, //随机串       
+                    "package" : data.package,
+                    "signType" : data.signType, //微信签名方式:       
+                    "paySign" : data.paySign
+                    //微信签名   
+                }, function(res) {
+                    if (res.err_msg == "get_brand_wcpay_request:ok") {
+                        alert("支付成功");
+                        // 使用以上方式判断前端返回:res.err_msg将在用户支付成功后返回    ok,但并不保证它绝对可靠。
+                    }
+                    else{
+                        alert("支付失败");
+                        //res.err_msg;  
+                    }
+                });
+
+
+                //这个if判断后面加的  不知道作用
+                if (typeof WeixinJSBridge == "undefined") {
+                    if (document.addEventListener) {
+                        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
+                    } else if (document.attachEvent) {
+                        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
+                        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
+                    }
+                } else {
+                    onBridgeReady();
+                }
+            }
+        });
+    }else{
+        //H5支付逻辑
+        //电脑or手机?
+
+        $.ajax({
+            type : "POST",
+            url : "/wxpay/wapPay",
+            dataType : "json",
+            contentType : 'application/json;charset=UTF-8',
+            //data : JSON.stringify({orderId:orderId}),//TODO ProjectRecord json数据
+            success : function(res){
+                if("success" == res.errCode){
+                    var mwebUrl = res.data;
+                    window.location.href = mwebUrl;
+                }else{
+                    alert("支付操作异常,请稍后再试!");
+                }
+            },
+            error : function(XMLHttpRequest, textStatus, errorThrown) {
+                alert('支付异常,请联系客服!');
+            },
+            complete : function(XMLHttpRequest, textStatus) {
+            }
+        });
+    }
+}
+
+var aliPay = function (proId, amount) {
+    var jsonStr =  "{proId:" + proId + "," +
+        "amount:" + amount + "," +
+        //"uuid:" + uuid + "," +
+        "way:'支付宝'" +
+        "}";
+
+    //location.href="/alipay/pcPay?jsonStr=" + jsonStr;
+
+    var url = "/alipay/pcPay";
+
+    if (isMobile) {
+        url = "/alipay/wapPay";
+    }
+
+    $.ajax({
+        type : "POST",
+        url : url,
+        dataType : "html",
+        //contentType : "application/json;charset=UTF-8",
+        async: false,
+        data: {
+            jsonStr : jsonStr
+        },
+        success : function(data) {
+            document.write(data);
+        },
+        error : function() {
+            alert('支付异常,请联系客服!');
+        }
+    });
+}
+
+var unionPay  = function () {
+
+}
+
+
+
+