Browse Source

1.支付宝支付完成页面跳转
2. 支付前端页面参数调整
3. 微信扫码支付生成二维码图片
4. 调整微信扫码异步通知

huangct 7 years ago
parent
commit
d193cf86fc

+ 1 - 0
donate-service/MP_verify_BMkQAHplMGROBlAn.txt


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

@@ -383,7 +383,9 @@ public class AlipayController {
             } else {
                 if ("10000".equals(tradeQueryResponse.getCode())) {
                     if ("TRADE_SUCCESS".equals(tradeQueryResponse.getTradeStatus())) {
-                        String url = "/project#/donationsOver/" +  notifyOutTradeNo;
+                        String requestUrlMessage = request.getScheme() +"://" + request.getServerName() + ":" + request.getServerPort();
+                        logger.info("服务器路径:" + requestUrlMessage);
+                        String url = requestUrlMessage + "/project#/donationsOver/" +  notifyOutTradeNo;
                         modelAndView.setViewName("redirect:" + url);
                     }
                     //TODO 其他状态判断

+ 48 - 8
donate-service/src/main/java/com/uas/service/donate/controller/WxpayController.java

@@ -63,7 +63,7 @@ public class WxpayController {
     private ProjectRecodeService projectRecodeService;
 
     private Logger logger = LoggerFactory.getLogger(WxpayController.class);
-    private static String redirectUrl = "http://5087452.nat123.cc/wxpay/redirectUrl";
+    private static String redirectUrl = "http://lj.ubtob.com/wxpay/redirectUrl";
     //private String orderNumber = NumberGenerator.generateId();
 
     /**
@@ -80,6 +80,7 @@ public class WxpayController {
             projectRecode = this.createProjectRecode(jsonStr);
         } catch (Exception e) {
             response.getWriter().write(e.getMessage());
+            logger.error("生成商户订单错误,原因:{}", e.getMessage());
             return null;
         }
 
@@ -104,6 +105,7 @@ public class WxpayController {
             projectRecode = this.createProjectRecode(jsonStr);
         } catch (Exception e) {
             response.getWriter().write(e.getMessage());
+            logger.error("生成商户订单错误,原因:{}", e.getMessage());
             map.put("error", "参数错误");
             return map;
         }
@@ -154,6 +156,7 @@ public class WxpayController {
             projectRecode = this.createProjectRecode(jsonStr);
         } catch (Exception e) {
             response.getWriter().write(e.getMessage());
+            logger.error("生成商户订单错误,原因:{}", e.getMessage());
             map.put("error", "参数错误");
             return map;
         }
@@ -234,6 +237,10 @@ public class WxpayController {
         try {
             String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
             WxPayOrderNotifyResult result = wxPayApi.parseOrderNotifyResult(xmlResult);
+
+            //商户系统订单默认支付状态
+            short projectRecodePayStatus = 1;
+
             if ("SUCCESS".equals(result.getReturnCode())) {
                 if ("SUCCESS".equals(result.getResultCode())) {
                     returnResult = setXml("SUCCESS", "OK");
@@ -247,21 +254,33 @@ public class WxpayController {
 
                         //校验返回的订单金额是否与商户侧的订单金额一致
                         //TODO 先注释这两句
-//                        ProjectRecode projectRecode = projectRecodeService.findOne(Long.parseLong(result.getOutTradeNo()));
-//                        if (!(projectRecode != null && ((int) (projectRecode.getAmount()*100)) == result.getTotalFee().intValue())) {
-                        if (false) {
+                        ProjectRecode projectRecode = projectRecodeService.findOne(Long.parseLong(result.getOutTradeNo()));
+                        if (!(projectRecode != null && ((int) (projectRecode.getAmount()*100)) == result.getTotalFee().intValue())) {
                             logger.warn("防止数据泄漏导致出现“假通知”,以免造成资金损失");
                             map.put("warning", "防止数据泄漏导致出现“假通知”,以免造成资金损失");
                             returnResult = setXml("FAIL", "商户侧的订单金额与返回的订单金额不一致");
+
+                            projectRecodePayStatus = 3;
+                            projectRecode.setStatus(projectRecodePayStatus);
+                            projectRecode.setExceptionMsg("{'AmountMsg' : '支付宝返回金额(单位分)与订单金额不相等', 'notifyTotalFee' : " + result.getTotalFee().intValue() + "}");
+
                         } else {
                             WxPayOrderQueryResult wxPayOrderQueryResult = wxPayApi.queryOrder(result.getTransactionId(),null);//二选一填
                             if (wxPayOrderQueryResult != null) {
-                                map.put("tradeState", wxPayOrderQueryResult.getTradeState());
-                                map.put("tradeStateDesc", wxPayOrderQueryResult.getTradeStateDesc());
+                                map.put("tradeState", wxPayOrderQueryResult.getTradeState());//微信订单状态
+                                map.put("tradeStateDesc", wxPayOrderQueryResult.getTradeStateDesc());//微信订单状态详情
                             }
-                            wechatOrder = wechatOrderService.save(WechatOrder.WxPayOrderNotifyResultToConvert(result, (short) 1, wxPayOrderQueryResult));
+
+                            if ("SUCCESS".equals(wxPayOrderQueryResult.getTradeState())) {
+                                projectRecodePayStatus = 2;
+                                projectRecode.setStatus(projectRecodePayStatus);
+                            }
+
+                            wechatOrderService.save(WechatOrder.WxPayOrderNotifyResultToConvert(result, (short) 1, wxPayOrderQueryResult));
                             returnResult = setXml("SUCCESS", "OK");
                         }
+                        //更新订单状态
+                        projectRecodeService.update(projectRecode);
                     }
                     //String totalFee = WxPayBaseResult.feeToYuan(result.getTotalFee());
                 } else {
@@ -330,6 +349,8 @@ public class WxpayController {
      * @param request
      * @return
      */
+    @ResponseBody
+    @RequestMapping("/getUserInfo")
     public String getOpenId(HttpServletRequest request){
         try {
             //TODO 授权方式  是否需要电话号码  名字等信息
@@ -449,7 +470,8 @@ public class WxpayController {
         wxPayUnifiedOrderRequest.setTotalFee((int)(projectRecode.getAmount() * 100));//是 订单总金额,只能为整数
 
         //wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtils.getIpFromRequest(request));//是 APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP
-        wxPayUnifiedOrderRequest.setSpbillCreateIp("218.17.158.219");
+        wxPayUnifiedOrderRequest.setSpbillCreateIp(getIp(request));
+        //wxPayUnifiedOrderRequest.setSpbillCreateIp("10.10.100.200");
 
         //wxPayUnifiedOrderRequest.setTimeStart(null);//否 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
         //wxPayUnifiedOrderRequest.setTimeExpire(null);//否 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。
@@ -477,4 +499,22 @@ public class WxpayController {
         ProjectRecode newProjectRecode = projectRecodeService.join(projectRecode);
         return newProjectRecode;
     }
+
+    public String getIp(HttpServletRequest request) {
+
+        String ip = request.getHeader("X-Forwarded-For");
+        if(ip!=null && !"unKnown".equalsIgnoreCase(ip)){
+            int index = ip.indexOf(",");
+            if(index != -1){
+                return ip.substring(0,index);
+            }else{
+                return ip;
+            }
+        }
+        ip = request.getHeader("X-Real-IP");
+        if(ip!=null && !"unKnown".equalsIgnoreCase(ip)){
+            return ip;
+        }
+        return request.getRemoteAddr();
+    }
 }

+ 1 - 1
donate-service/src/main/resources/config/wechat.properties

@@ -4,7 +4,7 @@ pay.mchKey=huangchengtianusoftchina12345678
 #subAppId=
 #subMchId=
 pay.keyPath=D://apiclient_cert.p12
-pay.notifyURL=http://5087452.nat123.cc/wxpay/notifyUrl
+pay.notifyURL=http://lj.ubtob.com/wxpay/notifyUrl
 
 mp.appId=wxbc1f8607137d3b8a
 mp.appSecret=

+ 39 - 26
donate-service/src/main/webapp/resources/js/pay.js

@@ -10,7 +10,7 @@
 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 pay =function (proId, amount, payWay, uuid) {
      var customAmount = $("#custom-amount" + proId).val();
      console.log(customAmount);
     if ($.trim(customAmount) != "") {
@@ -32,17 +32,17 @@ var pay =function (proId, amount, payWay) {
 
     //获取支付方式
     if(payWay == "支付宝") {
-        aliPay(proId, amount);
+        aliPay(proId, amount, payWay, uuid);
     } else if (payWay == "微信支付") {
-        wxPay(proId, amount);
+        wxPay(proId, amount, payWay, uuid);
     } else if (payWay == "网银支付") {
         unionPay();
     }
 }
 
 
-var wxPay = function (proId, amount) {
-    var jsonStr = getJson(proId, amount);
+var wxPay = function (proId, amount, payWay, uuid) {
+    var jsonStr = getJson(proId, amount, payWay, uuid);
 
     //公众号支付js模板 需引入http://res.wx.qq.com/open/js/jweixin-1.0.0.js
     //对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
@@ -52,7 +52,7 @@ var wxPay = function (proId, amount) {
         $.ajax({
             url : "/wxpay/webPay",
             type : "POST",
-            dataType : 'json',
+            dataType : "json",
             async: false,
             data: {
                 jsonStr : jsonStr
@@ -79,16 +79,19 @@ var wxPay = function (proId, amount) {
 
 
                 //这个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();
-                // }
+                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();
+                }
+            },
+            error : function() {
+                alert('系统异常,请联系客服!');
             }
         });
     }else{
@@ -106,6 +109,7 @@ var wxPay = function (proId, amount) {
             type : "POST",
             url : url,
             dataType : dataType,
+            async: false,
             //contentType : 'application/json;charset=UTF-8',
             data: {
                 jsonStr : jsonStr
@@ -124,14 +128,14 @@ var wxPay = function (proId, amount) {
                 }
             },
             error : function() {
-                alert('支付异常,请联系客服!');
+                alert('系统异常,请联系客服!');
             }
         });
     }
 }
 
-var aliPay = function (proId, amount) {
-    var jsonStr = getJson(proId, amount);
+var aliPay = function (proId, amount, payWay, uuid) {
+    var jsonStr = getJson(proId, amount, payWay, uuid);
     var url = "/alipay/pcPay";
 
     if (isMobile) {
@@ -151,7 +155,7 @@ var aliPay = function (proId, amount) {
             document.write(data);
         },
         error : function() {
-            alert('支付异常,请联系客服!');
+            alert('系统异常,请联系客服!');
         }
     });
 }
@@ -160,12 +164,21 @@ var unionPay  = function () {
 
 }
 
-var getJson = function (proId, amount) {
-    return jsonStr = "{proId:" + proId + "," +
-        "amount:" + amount + "," +
-        //"uuid:" + uuid + "," +
-        "way:'支付宝'" +
-        "}";
+var getJson = function (proId, amount, payWay, uuid) {
+    if (typeof uuid == 'undefined') {
+        return jsonStr = "{proId:" + proId + "," +
+            "amount:" + amount + "," +
+            "way:" + "\"" + payWay + "\"" +
+            "}";
+    } else {
+        return jsonStr = "{proId:" + proId + "," +
+            "amount:" + amount + "," +
+            "way:" + "\"" + payWay + "\"" +
+            "uuid:" + uuid +
+            "}";
+    }
+
+
 }