之前使用微信jsapi的接口做公众号支付,突然就不能使用返回页面了。是因为微信新推出了新的返回页面解决方案,就是所谓的点金计划。使用点金计划就可以更加丰富你的返回页面,可以在返回页面展示支付信息 小票和广告等。
如果之前已经对接了支付,升级也挺简单,不需要修改之前的代码。官方给的文档有点麻烦,这里简单记录下。
1,在公众号里申请开通点金计划,过程可以按官方文档指导来,最重要的是设置返回页面。
2,这个页面是微信支付成功后会返回的页面,在这个返回页面里写入如下代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="referrer" content="origin">
<meta name="viewport"
content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<title>支付完成</title>
<script type="text/javascript" charset="UTF-8" src="https://wx.gtimg.com/pay_h5/goldplan/js/jgoldplan-1.0.0.js">
</script>
<script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>
<script type="text/javascript" src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<style>
body {
font-family: PingFang SC, "Helvetica Neue", Arial, sans-serif;
}
.order_box {
text-align: center;
}
.order_box .bussiness_avt img {
width: 68px;
height: 68px;
border-radius: 100%;
border: 1px solid #E0E0E0;
}
.b_name {
font-size: 14px;
font-weight: 500;
color: #333333;
margin-top: 6px;
}
.col_box {
margin-top: 35px;
}
.col_box .col {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
font-size: 14px;
color: #333;
margin-bottom: 14px;
}
.col .ct.price {
color: #E61515
}
.btns {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
margin-top: 31px;
}
.btns .btn {
width: 147px;
height: 35px;
line-height: 35px;
font-size: 14px;
border-radius: 39px;
border: 1px solid #CD2314;
box-sizing: border-box;
color: #CD2314;
}
.btns .btn.detail {
background: linear-gradient(270deg, #D51010 0%, #EF4D2D 100%);
color: #fff;
}
</style>
</head>
<body>
<div>
<div>
<img id="b_avt" src="你的公司logo"
alt="">
</div>
<div id="b_name">
梦吉网络科技
</div>
<div>
<div>
<div>产品名称</div>
<div id="p_name">产品名称</div>
</div>
<div>
<div>购买数量</div>
<div id="count">3</div>
</div>
<div>
<div>实付金额</div>
<div id="price" class="ct price">¥</div>
</div>
</div>
<div>
<div id="backHome" class="btn home">返回首页</div>
<div id="toOrder" class="btn detail">查看详情</div>
</div>
</div>
<script>
//初始化console
var vConsole = new VConsole();
//获取返回页面参数
function getQueryString(name) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == name) {
return pair[1];
}
}
return null;
};
//获取参数
var sub_mch_id = getQueryString("sub_mch_id"); //特约商户号
console.log("sub_mch_id is " + sub_mch_id)
var out_trade_no = getQueryString("out_trade_no"); //商户订单号
console.log("out_trade_no is " + out_trade_no)
var check_code = getQueryString("check_code"); //md5 校验码
console.log("check_code is " + check_code)
$.ajax({
type: "GET",
url: "/api/afterdo",
data: {
sub_mch_id: sub_mch_id,
out_trade_no: out_trade_no
},
dataType: "json",
success: function (data) {
console.log(data)
if (data.status == "success") {
var info = data.data;
var homeLink = "您的首页返回链接";
var detailLink = "您的订单详情返回链接";
$("#b_avt").src = info.merchantIcon
$("#b_name").html(info.company)
$("#p_name").html(info.goodsName + "-" + info.skuName)
$("#count").html(info.num)
$("#price").html(info.payment)
//初始化小票
var initData = {
action: 'onIframeReady',
displayStyle: 'SHOW_CUSTOM_PAGE'
}
var initPostData = JSON.stringify(initData)
parent.postMessage(initPostData, 'https://payapp.weixin.qq.com')
//注册点击事件(去详情)
document.getElementById("toOrder").onclick = function () {
var mchData = {
action: 'jumpOut',
jumpOutUrl: detailLink //跳转的页面
}
var postData = JSON.stringify(mchData)
parent.postMessage(postData, 'https://payapp.weixin.qq.com')
}
//注册点击事件(去首页)
document.getElementById("backHome").onclick = function () {
var mchData = {
action: 'jumpOut',
jumpOutUrl: homeLink //跳转的页面
}
var postData = JSON.stringify(mchData)
parent.postMessage(postData, 'https://payapp.weixin.qq.com')
}
}
}
});
</script>
</body>
</html>
这个代码就是获取微信点金计划传过来的订单号和商户号,然后调用自己的接口(代码里ajax的请求),处理业务逻辑后设置返回链接就行了。确保
data.status == "success"
这个正确返回就行。这里贴下我的主要js代码和php接口代码
$.ajax({
type: "GET",
//url: "/api/TradeCommon/GetTradeInfoAfterWxPay",
url: "/api/getWxddhnew",
data: {
sub_mch_id: sub_mch_id,
out_trade_no: out_trade_no,
sp_mchid:"33333333",
},
dataType: "json",
success: function (data) {
var info=JSON.parse(data);
if (info.status == "success") {
var homeLink = "http://www.mdgc6.com";
var detailLink = "http://www.mdgc6.com";
$("#p_name").html(info.transaction_id)
$("#price").html(info.payer_total)
//初始化小票
var initData = {
action: 'onIframeReady',
displayStyle: 'SHOW_CUSTOM_PAGE'
}
var initPostData = JSON.stringify(initData)
parent.postMessage(initPostData, 'https://payapp.weixin.qq.com')
public function getWxddhnew(){
$data=Request::instance()->param();
$outno=$data['out_trade_no'];
$rtn=array();
$rtn['status']='success';
$rtn['transaction_id']=$outno;
//根据订单号查询订单信息处理业务逻辑
$rtn['payer_total']=888;
return json_encode($rtn);
}