mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改微信支付demo
This commit is contained in:
parent
05508cd504
commit
aa9e329a1a
@ -53,7 +53,27 @@ class Wap extends BasicWechat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function payjs() {
|
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();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,60 +10,32 @@
|
|||||||
<body style="text-align:center">
|
<body style="text-align:center">
|
||||||
|
|
||||||
<div class="contrainer">
|
<div class="contrainer">
|
||||||
<h3>扫码支付DEMO</h3>
|
<h3>JSAPI支付DEMO</h3>
|
||||||
<form class="form-horizontal">
|
<hr/>
|
||||||
<div class="form-group">
|
<p class="price">金额: 0.01元</p>
|
||||||
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
|
<hr/>
|
||||||
<div class="col-sm-10">
|
<p class="orderno">订单号:13412341234</p>
|
||||||
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
|
<hr/>
|
||||||
</div>
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
<button type="submit" class="btn btn-success">立即支付</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
</div>
|
||||||
<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>
|
</body>
|
||||||
<script src="//cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
|
<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="//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>
|
<script>
|
||||||
$(function () {
|
wx.error(function (e) {
|
||||||
|
console.log(e);
|
||||||
payTest.call(this), setInterval(payTest, 3000);
|
});
|
||||||
|
wx.config($.parseJSON('{$jsSign|json_encode}'));
|
||||||
/*! 支付测试动作 */
|
wx.ready(function () {
|
||||||
function payTest() {
|
$('[type="submit"]').on('click', function () {
|
||||||
$.get('{:url("payqrc")}', {'action': 'payqrc'}, function (ret) {
|
$.get('{:url("payjs")}', {'action': 'options'}, function (ret) {
|
||||||
if (ret.code === 2) {
|
wx.chooseWXPay(ret);
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
|
|
||||||
<div class="contrainer">
|
<div class="contrainer">
|
||||||
<h3>扫码支付DEMO</h3>
|
<h3>扫码支付DEMO</h3>
|
||||||
|
<hr/>
|
||||||
<p id="showbox"></p>
|
<p id="showbox"></p>
|
||||||
|
<hr/>
|
||||||
<p id="orderno"></p>
|
<p id="orderno"></p>
|
||||||
<button data-reset class="btn btn-default">重置订单号</button>
|
<hr/>
|
||||||
|
<button data-reset class="btn btn-default hide">重置订单号</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
@ -28,9 +31,9 @@
|
|||||||
function payTest() {
|
function payTest() {
|
||||||
$.get('{:url("payqrc")}', {'action': 'payqrc'}, function (ret) {
|
$.get('{:url("payqrc")}', {'action': 'payqrc'}, function (ret) {
|
||||||
if (ret.code === 2) {
|
if (ret.code === 2) {
|
||||||
|
$('[data-reset]').removeClass('hide');
|
||||||
ret.url = '__STATIC__/theme/default/img/wechat/qrc_payed.jpg';
|
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 + '"/>');
|
$('#showbox').html('<img style="width:300px" class="img-thumbnail" src="' + ret.url + '"/>');
|
||||||
$('#orderno').html('订单号:' + ret.order_no);
|
$('#orderno').html('订单号:' + ret.order_no);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user