From 3dba53a719bff9a8495260dfa1cf950ff305ac2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Mon, 1 Mar 2021 13:12:59 +0800 Subject: [PATCH] Update Test.php --- app/wechat/controller/api/Test.php | 54 ++++++++++++++---------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/app/wechat/controller/api/Test.php b/app/wechat/controller/api/Test.php index d589e7407..25ca39d9f 100644 --- a/app/wechat/controller/api/Test.php +++ b/app/wechat/controller/api/Test.php @@ -176,7 +176,6 @@ class Test extends Controller /** * 微信JSAPI支付测试 * @return string - * @return void|string * @throws \WeChat\Exceptions\LocalCacheException * @throws \think\admin\Exception * @throws \think\db\exception\DataNotFoundException @@ -184,11 +183,11 @@ class Test extends Controller * @throws \think\db\exception\ModelNotFoundException * @throws \WeChat\Exceptions\InvalidResponseException */ - public function jsapi() + public function jsapi(): string { $this->url = $this->request->url(true); $this->pay = WechatService::WePayOrder(); - $user = WechatService::instance()->getWebOauthInfo($this->url, 0); + $user = WechatService::instance()->getWebOauthInfo($this->url); if (empty($user['openid'])) return '

网页授权获取OPENID失败!

'; // 生成预支付码 $result = $this->pay->create([ @@ -200,32 +199,29 @@ class Test extends Controller 'out_trade_no' => CodeExtend::uniqidDate(18), 'spbill_create_ip' => $this->request->ip(), ]); - // 创建JSAPI参数签名 - $options = $this->pay->jsapiParams($result['prepay_id']); - // JSSDK 签名配置 - $optionJSON = json_encode($options, JSON_UNESCAPED_UNICODE); - $configJSON = json_encode(WechatService::instance()->getWebJssdkSign(), JSON_UNESCAPED_UNICODE); - - echo '
';
-        echo "当前用户OPENID: {$user['openid']}";
-        echo "\n--- 创建预支付码 ---\n";
-        var_export($result);
-        echo "\n\n--- JSAPI 及 H5 参数 ---\n";
-        var_export($options);
-        echo '
'; - echo ""; - echo " - - "; + // 数据参数格式化 + $resultJson = var_export($result, true); + $optionJson = json_encode($this->pay->jsapiParams($result['prepay_id']), JSON_UNESCAPED_UNICODE); + $configJson = json_encode(WechatService::instance()->getWebJssdkSign(), JSON_UNESCAPED_UNICODE); + return << + 当前用户OPENID: {$user['openid']} + \n\n--- 创建微信预支付码结果 ---\n {$resultJson} + \n\n--- JSAPI 及 H5 支付参数 ---\n {$optionJson} + + + + +HTML; } /**