ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 微信支付 - JSAPI chooseWXPay chooseWXPay 接口依赖于 JSSDK,因此需要先注入 JSSDK 配置: ```php use Thenbsp\Wechat\Jssdk; /** * 生成 JSSDK 配置文件 */ $jssdk = new Jssdk($accessToken); $jssdk->addApi('chooseWXPay'); $jssdkConfigJSON = $jssdk->getConfig(); ``` PHP: ```php use Thenbsp\Wechat\Payment\JsChooseWXPay; $options = array( 'body' => 'iphone 6 plus', 'total_fee' => 1, 'out_trade_no' => date('YmdHis').mt_rand(10000, 99999), 'notify_url' => 'Your notify url', 'openid' => $_SESSION['openid'] ); $o = new JsChooseWXPay($wechat, $options); $paymentConfigJSON = $o->getConfig(); ``` Javascript: ```javascript // 注入 JSSDK 配置 wx.config(<?php echo $jssdkConfigJSON; ?>); // 点击支付按款 var WXPayment = function() { var config = <?php echo $paymentConfigJSON; ?>; config.success = function() { alert('支付成功!'); } config.cancel = function() { alert('用户取消成功!'); } wx.chooseWXPay(config); } ``` HTML: ```html <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <button type="button" onclick="WXPayment()">支付 ¥<?php echo ($options['total_fee'] / 100); ?> 元</button> ```