[更新]修改微信支付demo

This commit is contained in:
邹景立 2017-04-14 17:56:39 +08:00
parent 8ea7017ff2
commit 74c420f2f3
2 changed files with 16 additions and 1 deletions

View File

@ -67,6 +67,9 @@ class Wap extends BasicWechat {
}
$pay = &load_wechat('pay');
$options = PayService::createWechatPayJsPicker($pay, $this->openid, $order_no, 1, 'JSAPI支付测试');
if ($options === false) {
$options = ['code' => 3, 'msg' => "创建支付失败,{$pay->errMsg}[$pay->errCode]"];
}
return json($options);
case 'reset':
session('pay-test-order-no', null);

View File

@ -17,7 +17,7 @@
<p class="orderno">订单号13412341234</p>
<hr/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="col-sm-offset-2 col-sm-10" id="test">
<button type="submit" class="btn btn-success">立即支付</button>
</div>
</div>
@ -35,9 +35,21 @@
wx.ready(function () {
$('[type="submit"]').on('click', function () {
$.get('{:url("payjs")}', {'action': 'options'}, function (ret) {
if (ret.code && ret.code === 2) {
$('#test').append('<button type="button" class="btn btn-success">已支付,刷新支付号</button>');
return $('[type="submit"]').remove();
}
if (ret.code && ret.code === 3) {
return alert(ret.msg);
}
wx.chooseWXPay(ret);
});
});
$('body').on('click', '[type="button"]', function () {
$.get('{:url("payqrc")}', {'action': 'reset'}, function () {
window.location.reload();
});
});
});
</script>
</html>