[更新]修改微信支付demo

This commit is contained in:
邹景立 2017-04-14 17:27:54 +08:00
parent 05508cd504
commit aa9e329a1a
3 changed files with 45 additions and 50 deletions

View File

@ -53,7 +53,27 @@ class Wap extends BasicWechat {
}
public function payjs() {
$this->oAuth();
$this->assign('jsSign', load_wechat('script')->getJsSign($this->url));
switch ($this->request->get('options')) {
case 'options':
$pay = &load_wechat('pay');
$order_no = session('pay-test-order-no');
if (empty($order_no)) {
$order_no = DataService::createSequence(10, 'wechat-pay-test');
session('pay-test-order-no', $order_no);
}
if (PayService::isPay($order_no)) {
return json(['code' => 2, 'order_no' => $order_no]);
}
$options = PayService::createWechatPayJsPicker($pay, $this->openid, $order_no, 1, 'JSAPI支付测试');
return json($options);
case 'reset':
session('pay-test-order-no', null);
break;
default:
return view();
return view();
}
}
}

View File

@ -10,60 +10,32 @@
<body style="text-align:center">
<div class="contrainer">
<h3>扫码支付DEMO</h3>
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
<h3>JSAPI支付DEMO</h3>
<hr/>
<p class="price">金额: 0.01元</p>
<hr/>
<p class="orderno">订单号13412341234</p>
<hr/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">立即支付</button>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
</div>
</div>
</body>
<script src="//cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
$(function () {
payTest.call(this), setInterval(payTest, 3000);
/*! 支付测试动作 */
function payTest() {
$.get('{:url("payqrc")}', {'action': 'payqrc'}, function (ret) {
if (ret.code === 2) {
ret.url = '__STATIC__/theme/default/img/wechat/qrc_payed.jpg';
}
console.log(ret);
$('#showbox').html('<img style="width:300px" class="img-thumbnail" src="' + ret.url + '"/>');
$('#orderno').html('订单号:' + ret.order_no);
});
}
$('[data-reset]').on('click', function () {
$.get('{:url("payqrc")}', {'action': 'reset'}, function () {
window.location.reload();
wx.error(function (e) {
console.log(e);
});
wx.config($.parseJSON('{$jsSign|json_encode}'));
wx.ready(function () {
$('[type="submit"]').on('click', function () {
$.get('{:url("payjs")}', {'action': 'options'}, function (ret) {
wx.chooseWXPay(ret);
});
});
});

View File

@ -11,9 +11,12 @@
<div class="contrainer">
<h3>扫码支付DEMO</h3>
<hr/>
<p id="showbox"></p>
<hr/>
<p id="orderno"></p>
<button data-reset class="btn btn-default">重置订单号</button>
<hr/>
<button data-reset class="btn btn-default hide">重置订单号</button>
</div>
</body>
@ -28,9 +31,9 @@
function payTest() {
$.get('{:url("payqrc")}', {'action': 'payqrc'}, function (ret) {
if (ret.code === 2) {
$('[data-reset]').removeClass('hide');
ret.url = '__STATIC__/theme/default/img/wechat/qrc_payed.jpg';
}
console.log(ret);
$('#showbox').html('<img style="width:300px" class="img-thumbnail" src="' + ret.url + '"/>');
$('#orderno').html('订单号:' + ret.order_no);
});