根据微信支付的公告,微信支付特约商户下的JSSDK支付,在支付完成后自动关闭页面,无法根据业务需要在页面里设置跳转到页面,微信的公告地址:https://pay.weixin.qq.com/index.php/public/cms/content_detail?platformType=1&lang=zh&id=121505
由此可见,需要使用微信的“点金计划”进行开发。
开发指引文档:https://wx.gtimg.com/pay/download/goldplan/goldplan_developer_guideline_v1.pdf
实例:
后端验证校验码(Laravel):
//根据微信传过来的商户订单号,获取微信支付的订单号(需要在支付后的回调讲微信支付订单号记录下来)
$transaction = Transaction::whereNo($request->out_trade_no)->first();
//设置默认验证状态不通过
$success = 0;
if(!empty($transaction)){
//组合字符串
$str = 'https://test.domain.com/jgoldplan?sub_mch_id='.config('wechat.payment.sub.sub_mch_id').'&out_trade_no='.$request->out_trade_no.'&transaction_id='.$transaction->wx_transaction_id;
//对字符串进行md5加密
$key = md5($str);
//当md5后的字符串跟微信支付传过来的校验码一致时,验证通过
if($key == $request->check_code){
$success = 1;
}
}
return view('wap.jgoldplan',compact('success','transaction'));前端展示
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>点金计划</title>
<meta name="author" content="http://www.doxincn.com" />
<script type="text/javascript" charset="UTF-8" src="https://wx.gtimg.com/pay_h5/goldplan/js/jgoldplan-1.0.0.js"></script>
</head>
<body>
@if($success == 1)
<div style="margin: 40px auto;">
<p><img src="{{ asset('images/suc.png') }}" style="width: 80px;" /></p>
<h3>支付完成</h3>
<div style="display: flex;justify-content: space-between;">
<div id="back3" style="font-size: 20px;border:#4582fd 1px solid;color: #4582fd;height: 50px;line-height:50px;width: 100px;margin:20px auto;text-align: center;border-radius: 25px;margin-right: 20px;">返回</div>
<div id="back2" style="font-size: 20px;background:#4582fd;color: #fff;height: 50px;line-height:50px;width: 250px;margin:20px auto;text-align: center;border-radius: 25px;">其他地址</div>
</div>
</div>
@else
<h4>请求非法</h1>
@endif
<script src="{{asset('js/jquery.min.js')}}"></script>
<script type="text/javascript">
$(document).ready(function(){
let mchData ={action:'onIframeReady',displayStyle:'SHOW_CUSTOM_PAGE'}
let postData = JSON. stringify(mchData)
parent.postMessage(postData,'https://payapp.weixin.qq.com')
$("#back2").click(function(){
let mchData2 ={action:'jumpOut', jumpOutUrl:'https://test.com/url1'}
let postData2 = JSON. stringify(mchData2)
parent.postMessage(postData2,'https://payapp.weixin.qq.com')
})
$("#back3").click(function(){
let mchData3 ={action:'jumpOut', jumpOutUrl:'https://test.com/url2'}
let postData3 = JSON. stringify(mchData3)
parent.postMessage(postData3,'https://payapp.weixin.qq.com')
})
});
</script>
</body>
</html>