瀏覽代碼

微信H5支付页面回调以及小程序支付Demo

小柒2012 7 年之前
父節點
當前提交
966ea54eaa

+ 0 - 0
log/spring-boot-pay-error.log


File diff suppressed because it is too large
+ 95 - 0
log/spring-boot-pay-info.log


+ 8 - 2
src/main/java/com/itstyle/modules/weixinpay/controller/WeixinMobilePayController.java

@@ -50,7 +50,7 @@ public class WeixinMobilePayController {
 	//公众号H5支付主页
 	@RequestMapping(value = "payPage")
 	public String pay(HttpServletRequest request, HttpServletResponse response) throws Exception {
-		return "weixin/pay";
+		return "weixin/payPage";
 	}
 	@RequestMapping("/h5pay")
     public String  h5pay(Product product,ModelMap map) {
@@ -63,6 +63,12 @@ public class WeixinMobilePayController {
 			return "redirect:https://blog.52itstyle.com";//自定义错误页面
 		}
     }
+	@RequestMapping("/smallRoutine")
+    public String  smallRoutine(Product product,ModelMap map) {
+		logger.info("小程序支付(需要HTTPS)、不需要支付目录和授权域名");
+		String url =  weixinPayService.weixinPayMobile(product);
+		return "redirect:"+url;
+    }
 	/**
 	 * 预下单(对于已经产生的订单)
 	 * @Author  科帮网
@@ -85,7 +91,7 @@ public class WeixinMobilePayController {
 		//获取用户openID(JSAPI支付必须传openid)
 		String openId = MobileUtil.getOpenId(code);
 		String notify_url =server_url+"/weixinMobile/WXPayBack";//回调接口
-		String trade_type = "JSAPI";// 交易类型H5支付
+		String trade_type = "JSAPI";// 交易类型H5支付 也可以是小程序支付参数
 		SortedMap<Object, Object> packageParams = new TreeMap<Object, Object>();
 		ConfigUtil.commonParams(packageParams);
 		packageParams.put("body","报告");// 商品描述

+ 3 - 3
src/main/resources/application-dev.properties

@@ -13,9 +13,9 @@ server.tomcat.max-threads=100
 server.tomcat.uri-encoding=UTF-8
 
 #HTTPS\u8bc1\u4e66  \u5982\u679c\u4e0d\u9700\u8981 https\u8bbf\u95ee \u6ce8\u91ca\u6389\u5373\u53ef \u7531\u4e8e\u67d0\u4e9b\u6d4f\u89c8\u5668\u8bbf\u95ee\u4e0d\u652f\u6301
-server.ssl.key-store: classpath:keystore.p12
-server.ssl.key-store-password: 123456
-server.ssl.keyStoreType: PKCS12
+#server.ssl.key-store: classpath:keystore.p12
+#server.ssl.key-store-password: 123456
+#server.ssl.keyStoreType: PKCS12
 
 #spring boot\u4ece\u63a7\u5236\u53f0\u6253\u5370\u51fa\u6765\u7684\u65e5\u5fd7\u7ea7\u522b\u53ea\u6709ERROR, WARN \u8fd8\u6709INFO\uff0c\u5982\u679c\u4f60\u60f3\u8981\u6253\u5370debug\u7ea7\u522b\u7684\u65e5\u5fd7
 #debug=true

+ 110 - 0
src/main/resources/templates/weixinpay/payPage.jsp

@@ -0,0 +1,110 @@
+<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
+<%
+String path = request.getContextPath();
+String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
+String appId = request.getParameter("appid");
+String timeStamp = request.getParameter("timeStamp");
+String nonceStr = request.getParameter("nonceStr");
+String packageValue = request.getParameter("package");
+String paySign = request.getParameter("paySign");
+
+String orderNo = request.getParameter("orderNo");
+String totalFee  = request.getParameter("totalFee");
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<title>微信支付</title>
+<meta charset="UTF-8"/>
+<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
+<meta name="apple-mobile-web-app-capable" content="yes"/>
+<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
+<meta name="format-detection" content="telephone=no"/>
+<link   rel="stylesheet" type="text/css" href="<%=basePath%>static/css/pay.css"/>
+<script type="text/javascript" src="<%=basePath%>static/js/flexible.js" ></script>
+<script type="text/javascript" src="<%=basePath%>static/js/jquery-1.10.2.min.js"></script>
+<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
+</head>
+<body>
+		<article class="order-main ">
+			<div class="ph_order">
+				<div class=" affirm-info">
+					<h4 id="orderNo"></h4>
+					<h3 id="totalFee"></h3>
+					<div class="detail-dl">
+						<dl>
+							<dt>收款方</dt>
+							<dd>科帮网</dd>
+						</dl>
+						<dl>
+							<dt>商&nbsp;&nbsp;&nbsp;品</dt>
+							<dd id="productName">在线订单</dd>
+						</dl>
+					</div>
+					<div  onclick="callpay()" class="pay-info">立即支付</div>
+				</div>
+
+			</div>
+		</article>
+</body>
+<script type="text/javascript">
+var orderNo = '<%=orderNo%>';
+var totalFee  = '<%=totalFee%>';
+$(function(){
+	$(".affirm-info").height($(window).height());
+	$(window).resize(function(){
+		//main-body高度适应屏幕
+		$(".affirm-info").height($(window).height());
+	});
+	init();
+});
+function onBridgeReady(){
+    WeixinJSBridge.invoke('getBrandWCPayRequest',{
+		     "appId" : "<%=appId%>",
+		     "timeStamp" : "<%=timeStamp%>",
+		     "nonceStr" : "<%=nonceStr%>", 
+		     "package" : "<%=packageValue%>",
+		     "signType" : "MD5",
+		     "paySign" : "<%=paySign%>" 
+	     },function(res){
+		    //使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回    ok,但并不保证它绝对可靠。
+         if(res.err_msg == "get_brand_wcpay_request:ok"){
+        	 //微信 自带 支付成功效果
+             var url = "自定义http 跳转到支付系统页面";
+             window.location.href=url;
+         }else if(res.err_msg == "get_brand_wcpay_request:cancel"){  
+             alert("用户取消支付!");  
+         }else if(res.err_msg == "get_brand_wcpay_request:fail"){  
+             alert("支付失败!");  
+         }  
+	})
+}
+function callpay(){  
+      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();
+       }
+}
+function init(){
+	$("#orderNo").html("科帮网-订单编号:"+orderNo);
+	totalFee = accDiv(totalFee,100);
+	$("#totalFee").html("¥"+totalFee);
+}
+function accDiv(arg1,arg2){
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length;}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length;}catch(e){}
+    with(Math){
+        r1=Number(arg1.toString().replace(".",""));
+        r2=Number(arg2.toString().replace(".",""));
+        return (r1/r2)*pow(10,t2-t1);
+    }
+}
+</script>
+</html>

+ 64 - 0
src/main/resources/templates/weixinpay/smallRoutine.jsp

@@ -0,0 +1,64 @@
+<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html>
+<head>
+<title>小程序伪代码</title>
+<meta charset="UTF-8"/>
+<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
+<meta name="apple-mobile-web-app-capable" content="yes"/>
+<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
+<meta name="format-detection" content="telephone=no"/>
+<link   rel="stylesheet" type="text/css" href="<%=basePath%>static/css/pay.css"/>
+<script type="text/javascript" src="<%=basePath%>static/js/flexible.js" ></script>
+<script type="text/javascript" src="<%=basePath%>static/js/jquery-1.10.2.min.js"></script>
+<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
+</head>
+<body>
+		<article class="order-main ">
+			<div class="ph_order">
+				<div class=" affirm-info">
+					<h4 id="orderNo"></h4>
+					<h3 id="totalFee"></h3>
+					<div class="detail-dl">
+						<dl>
+							<dt>收款方</dt>
+							<dd>科帮网</dd>
+						</dl>
+						<dl>
+							<dt>商&nbsp;&nbsp;&nbsp;品</dt>
+							<dd id="productName">在线订单</dd>
+						</dl>
+					</div>
+					<div  onclick="callpay()" class="pay-info">立即支付</div>
+				</div>
+
+			</div>
+		</article>
+</body>
+<script type="text/javascript">
+//小程序伪代码  请自行获取 complete、fail、success回调函数
+	const
+	wechatData = payRes.data.payment;//wechatData就是上面的验证信息
+	console.log(wechatData);
+	wx.requestPayment({
+		'appId' : wechatData.appId,
+		'timeStamp' : wechatData.timeStamp,
+		'nonceStr' : wechatData.nonceStr,
+		'package' : wechatData.package,
+		'signType' : 'MD5',
+		'paySign' : wechatData.paySign,
+		'success' : function(res) {
+			console.log(res);
+			console.log('success');
+		},
+		'fail' : function(res) {
+			console.log(res);
+			console.log('fail');
+		},
+		'complete' : function(res) {
+			console.log(res);
+			console.log('complete');
+		}
+	});
+</script>
+</html>