Update Test.php

This commit is contained in:
Anyon 2019-12-30 18:40:26 +08:00
parent 8e25786e06
commit d50180d93e

View File

@ -183,21 +183,23 @@ class Test extends Controller
*/ */
public function jsapi() public function jsapi()
{ {
$url = $this->request->url(true);
$pay = WechatService::WePayOrder(); $pay = WechatService::WePayOrder();
$user = WechatService::instance()->getWebOauthInfo($this->request->url(true), 0); $user = WechatService::instance()->getWebOauthInfo($url, 0);
$options = [ if (empty($user['openid'])) return '<h3>网页授权获取OPENID失败</h3>';
// 生成预支付码
$result = $pay->create([
'body' => '测试商品', 'body' => '测试商品',
'out_trade_no' => time(), 'out_trade_no' => time(),
'total_fee' => '1', 'total_fee' => '1',
'openid' => $user['openid'], 'openid' => $user['openid'],
'trade_type' => 'JSAPI', 'trade_type' => 'JSAPI',
'notify_url' => url('@wechat/api.test/notify', [], false, true), 'notify_url' => url('@wechat/api.test/notify', [], false, true),
'spbill_create_ip' => request()->ip(), 'spbill_create_ip' => $this->request->ip(),
]; ]);
// 生成预支付码
$result = $pay->create($options);
// 创建JSAPI参数签名 // 创建JSAPI参数签名
$options = $pay->jsapiParams($result['prepay_id']); $options = $pay->jsapiParams($result['prepay_id']);
$optionJSON = json_encode($options, JSON_UNESCAPED_UNICODE); $optionJSON = json_encode($options, JSON_UNESCAPED_UNICODE);
// JSSDK 签名配置 // JSSDK 签名配置
$configJSON = json_encode(WechatService::instance()->getWebJssdkSign(), JSON_UNESCAPED_UNICODE); $configJSON = json_encode(WechatService::instance()->getWebJssdkSign(), JSON_UNESCAPED_UNICODE);