diff --git a/application/wechat/controller/api/Tools.php b/application/wechat/controller/api/Tools.php index f24686f11..644c52a24 100644 --- a/application/wechat/controller/api/Tools.php +++ b/application/wechat/controller/api/Tools.php @@ -15,6 +15,7 @@ namespace app\wechat\controller\api; use controller\BasicAdmin; +use Endroid\QrCode\QrCode; use service\WechatService; /** @@ -36,6 +37,19 @@ class Tools extends BasicAdmin return $this->fetch('', ['fans' => $fans]); } + /** + * 显示网页授权二维码 + * @return \think\Response + * @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException + * @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException + * @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException + */ + public function oauth_qrc() + { + $url = url('@wechat/api.tools/oauth', '', true, true); + return $this->createQrc($url); + } + /** * JSSDK测试 * @return string @@ -47,4 +61,32 @@ class Tools extends BasicAdmin return $this->fetch('', ['options' => $options]); } + /** + * 显示网页授权二维码 + * @return \think\Response + * @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException + * @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException + * @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException + */ + public function jssdk_qrc() + { + $url = url('@wechat/api.tools/jssdk', '', true, true); + return $this->createQrc($url); + } + + /** + * 创建二维码响应对应 + * @param string $url 二维码内容 + * @return \think\Response + * @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException + * @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException + * @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException + */ + protected function createQrc($url) + { + $qrCode = new QrCode(); + $qrCode->setText($url)->setSize(300)->setPadding(20)->setImageType(QrCode::IMAGE_TYPE_PNG); + return \think\facade\Response::header('Content-Type', 'image/png')->data($qrCode->get()); + } + } \ No newline at end of file diff --git a/application/wechat/view/config/index.html b/application/wechat/view/config/index.html index dec8ee245..b9454155d 100644 --- a/application/wechat/view/config/index.html +++ b/application/wechat/view/config/index.html @@ -19,6 +19,19 @@ +
+
+
+
+ +

网页授权

+
+
+ +

JSSDK签名

+
+
+