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 '
'; - 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; } /**