发起支付
请求地址
请求方式
POST/GET
参数说明名称
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
notifyUrl | String | 可选 | 接口异步请求地址绝对地址, 适用于:(支付宝支付、微信公众支付、微信扫码支付) 支付宝默认回调地址:mpay/alipay/notify.do, 微信默认回调:mapy/weixin/notify.do 开发者根据实际情况可以自定义回调地址,详细见:自定义回调 描述 |
returnUrl | String | 当支付类型是支付宝参数必填 | 返回地址绝对地址(支付宝必填) |
orderNo | String | 当自定义支付了回调方法,推荐必填 | 订单编号,不传时会自动生成 |
orderName | String | 当支付类型支付宝参数必填 | 订单标题 |
type | String | 必填 | 支付类型 weixin:微信 alipay:支付宝 alipay_app: app支付宝 |
orderPrice | String | 必填 | 订单价格 |
orderDesc | String | 必填 | 订单描述 |
showUrl | String | 当支付宝类型是支付宝参数必填 | 商品显示地址,绝对地址 |
authCode | String | 当支付类型是微信且是扫描支付参数必填 | 授权码 ,微信扫码支付授权码,设备读取用户微信中的条码或者二维码信息注:用户刷卡条形码规则:18位纯数字,以10、11、12、13、14、15开头) |
page | String | 当支付类型是微信且公众号支付参数必填 | 微信支付调用时调用,微信支付实现通过接口获取支付的凭证,再将凭证填充到page页面在发起支付 |
返回值
微信扫码支付、微信刷卡支付
名称 | 描述 |
---|---|
result | false:失败 true:成功 |
resultMsg | 1.微信公众号支付:需定义好page参数 ,会直接调转支付页面 2.微信扫码支付:返回微信短连接:weixin://wxpay/bizpayurl?pr=dB2zwN5 。 (可以采用系统里面方法生成二维码http://项目地址/qrcode?contents=weixin://xxx?pr=xxx) |
微信公众号支付、支付宝支付
由第三方平台异步请求notifyUrl对应地址
范例
首先必须配置微信支付或支付宝支付配置;
支付宝支付
alipay.html
...
<!--支付宝支付,提交成功后直接跳转支付宝支付-->
<form action="http://项目地址/mpay/pay/gateway.do" method="post">
<input type="hidden" name="returnUrl" value="http://项目地址/ok.jsp"/><!--支付成功返回地址-->
<input type="hidden" name="orderNo" value="8888888"/><!--订单号-->
<input type="hidden" name="orderName" value="铭飞开源赞助"/><!--订单名称-->
<input type="hidden" name="type" value="alipay"/><!--支付类型-->
<input type="hidden" name="orderPrice" value="0.01"/><!--价格-->
<input type="hidden" name="orderDesc" value="价值源自分享"/><!--商品描述-->
<input type="hidden" name="showUrl" value="http://www.mingsoft.net"/><!--商品展示网址-->
<input type="submit" value="确认">
</form>
...
微信扫码支付
根据表单提交的结果显示二维码图片,通常结合ajax来实现
wx-qr-pay.html
...
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<form>
<input type="hidden" name="orderNo" value="8888888"/><!--订单号-->
<input type="hidden" name="type" value="weixin"/><!--支付类型-->
<input type="hidden" name="orderPrice" value="0.01"/><!--价格-->
<input type="hidden" name="orderDesc" value="价值源自分享"/><!--商品描述-->
<input type="submit" value="确认">
</form>
<!--显示二维码-->
<img width="100" height="100"/>
<script>
$.ajax({
type: "POST",
dataType:"json",
url: "http://项目地址/mpay/pay/gateway.do",
data: $("form").serialize(),
success: function(json){
$("img").attr("src","http://项目地址/qrcode?contents="+json.resultMsg)
}
});
</script>
...
微信公众号支付
微信公众号支付需要在公众号内部完成,同时用户需要进行授权登录
参考微信官方文档https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1
wx-mp-pay.html
...
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<!--创建支付表单页面-->
<form id="weixin" name="weixin" >
<input type="hidden" name="orderNo" value="888888888"/><!--订单编号-->
<input type="hidden" name="type" value="weixin"/><!--支付类型-->
<input type="hidden" name="orderPrice" value="0.01"/><!--价格-->
<input type="hidden" name="orderDesc" value="测试公众号支付"/><!--描述-->
<input type="hidden" name="page" value="http://项目地址/wx-mp-pay.jsp"/><!--接收微信支付授权信息的页面-->
<input type="submit" value="确认">
</form>
...
<script>
//授权登录,需要用户配置微信appid和项目请求支付地址
function weixinPay(){
location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=微信appid&redirect_uri=" + encodeURIComponent("http://项目地址/mpay/pay/gateway.do?" + $("#weixin").serialize()) + "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
}
</script>
...
wx-mp-pay.jsp
...
<!--确认支付页面-->
<input type="button" onclick="pay()" value="支付"/>
<script>
function pay() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId":<%=request.getParameter("appId")%>, //公众号名称,由商户传入
"timeStamp":"<%=request.getParameter("timeStamp")%>", //时间戳,自1970年以来的秒数
"nonceStr":"<%=request.getParameter("nonceStr")%>", //随机串
"package":"<%=request.getParameter("package")%>",
"signType":"MD5", //微信签名方式:
"paySign":"<%=request.getParameter("sign")%>" //微信签名
},
function(res){
if (res.err_msg == "get_brand_wcpay_request:ok") {
alert("微信支付成功!");
} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
alert("用户取消支付!");
} else {
alert(JSON.stringify(res));
}
}
);
}
</script>
...
微信刷卡支付
刷卡支付场景描述:用户出示微信付款二维码 、 商户使用扫码枪扫码,用户输入支付密码(小额免密),商务系统提示支付成功。
开发者需要制作一张支付表单页面,提交后直接返回支付结果
wx-card-pay.html
...
<!-- 微信刷卡支付,刷卡成功后会直接扣款,金额过大或其他原因会需要支付密码 -->
<!-- 具体参考微信官方文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_1 -->
<form id="submit" name="weixin" action="http://域名/项目/mpay/pay/gateway.do" method="post">
<input type="hidden" name="orderNo" value="888888"/><!--订单编号-->
<input type="hidden" name="type" value="weixin"/><!--支付类型-->
<input type="hidden" name="orderPrice" value="0.01"/>
<input type="hidden" name="orderDesc" value="铭飞商超系统"/>
<input type="text" name="authCode" value="45454XXXX3FF"/> <!--通过扫描枪扫码获取,可手动输入付款码底部对应的字符串-->
<input type="submit" value="确认">
</form>
...