diff --git a/application/wechat/controller/api/Tools.php b/application/wechat/controller/api/Tools.php new file mode 100644 index 000000000..644c52a24 --- /dev/null +++ b/application/wechat/controller/api/Tools.php @@ -0,0 +1,92 @@ +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 + */ + public function jssdk() + { + $wechat = WechatService::wechat(); + $options = $wechat->jsSign($this->request->url(true)); + 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/api/tools/jssdk.html b/application/wechat/view/api/tools/jssdk.html new file mode 100644 index 000000000..c18a560e4 --- /dev/null +++ b/application/wechat/view/api/tools/jssdk.html @@ -0,0 +1,43 @@ + + + + JSSDK 功能测试 + + + + + + + + + + + +
+

JSSDK 功能测试

+
+ +
+ 调起摄像头扫码 +
+ + + + + diff --git a/application/wechat/view/api/tools/oauth.html b/application/wechat/view/api/tools/oauth.html new file mode 100644 index 000000000..f16bc3016 --- /dev/null +++ b/application/wechat/view/api/tools/oauth.html @@ -0,0 +1,66 @@ + + + + + 微信网页授权测试 + + + + + + + + + + +
+
+
+

操作失败

+

通过网页授权获取用户资料失败,请检查权限再试!

+
+
+

+ 重新获取(刷新) +

+
+
+ +
+ +

{$fans.fansinfo.nickname}

+
+
用户标识
+
+
+
OPENID
+
{$fans.fansinfo.openid}
+
+
+
UNIONID
+
{$fans.fansinfo.unionid}
+
+
+
详细资料
+
+
+
性别
+
{:[1=>'男',2=>'女'][$fans.fansinfo.sex]??'未知'}
+
+
+
系统语言
+
{$fans.fansinfo.language}
+
+
+
所在区域
+
{$fans.fansinfo.country}{$fans.fansinfo.province}{$fans.fansinfo.city}
+
+ {if isset($fans.fansinfo.privilege.0)} +
+
设备网络
+
{$fans.fansinfo.privilege.0}
+
+ {/if} +
+ + \ No newline at end of file diff --git a/application/wechat/view/config/index.html b/application/wechat/view/config/index.html index dec8ee245..3b67f7d96 100644 --- a/application/wechat/view/config/index.html +++ b/application/wechat/view/config/index.html @@ -19,6 +19,20 @@ +
+
+
+

------- 公众号功能测试 -------

+
+ +

网页授权

+
+
+ +

JSSDK签名

+
+
+
diff --git a/extend/service/WechatService.php b/extend/service/WechatService.php index a0589e1ac..2690a23ad 100644 --- a/extend/service/WechatService.php +++ b/extend/service/WechatService.php @@ -79,8 +79,8 @@ class WechatService } $service = self::instance('wechat'); $result = $service->oauth(session_id(), request()->url(true), $fullMode); - session("{$appid}_openid", $result['openid']); - session("{$appid}_fansinfo", $result['fans']); + session("{$appid}_openid", $openid = $result['openid']); + session("{$appid}_fansinfo", $fansinfo = $result['fans']); if ((empty($fullMode) && !empty($openid)) || (!empty($fullMode) && !empty($fansinfo))) { empty($fansinfo) || FansService::set($fansinfo); return ['openid' => $openid, 'fansinfo' => $fansinfo]; diff --git a/static/theme/css/console.css b/static/theme/css/console.css index d357367b6..38790ed71 100644 --- a/static/theme/css/console.css +++ b/static/theme/css/console.css @@ -106,8 +106,6 @@ input[type=checkbox]:focus,input[type=radio]:focus{outline:none} .mobile-footer .sub-menu ul li{padding:0;display:block;width:100%;float:none;z-index:11} .mobile-footer .sub-menu ul li a{border:1px solid #fff} .mobile-footer .sub-menu ul li a.bottom-border{border-bottom:1px solid #e7e7eb} -.mobile-footer .sub-menu ul li:nth-last-child(2) a{border-bottom-color:#fff;} -.mobile-footer .sub-menu ul li:last-child a{border-top-color:#e7e7eb} .mobile-footer .arrow{position:absolute;left:50%;margin-left:-6px} .mobile-footer .arrow_in,.mobile-footer .arrow_out{z-index:10;width:0;height:0;display:inline-block;border-width:6px;border-style:dashed;border-color:transparent;border-bottom-width:0;border-top-style:solid} .mobile-footer .arrow_in{bottom:-5px;border-top-color:#fafafa}.mobile-footer .arrow_out{bottom:-6px;border-top-color:#d0d0d0}