Merge pull request #79 from zoujingli/master

master 合并到 v3
This commit is contained in:
邹景立 2018-03-17 17:11:49 +08:00 committed by GitHub
commit 65b68d8b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 217 additions and 4 deletions

View File

@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\controller\api;
use controller\BasicAdmin;
use Endroid\QrCode\QrCode;
use service\WechatService;
/**
* 公众号测试工具
* Class Tools
* @package app\wechat\controller\api
*/
class Tools extends BasicAdmin
{
/**
* 网页授权测试
* @return string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function oauth()
{
$fans = WechatService::webOauth(1);
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
*/
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());
}
}

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title>JSSDK 功能测试</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href="__STATIC__/mobile/library.min.css" rel="stylesheet">
<script src="__STATIC__/mobile/library.min.js"></script>
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>wx.config(JSON.parse('{$options|json_encode|raw}'));</script>
</head>
<body>
<header style="padding: 35px 0">
<h1 style=" text-align: center;font-size: 34px;color: #3cc51f;font-weight:400;">JSSDK 功能测试</h1>
</header>
<div style="padding:15px">
<a id='show-alert' class="weui-btn weui-btn_primary weui-btn_disabled">调起摄像头扫码</a>
</div>
<script>
wx.error(function (err) {
$.toptip(err.errMsg, 100000, 'error');
});
wx.ready(function () {
$.toptip('JSSDK 初始化成功...', 'success');
$('#show-alert').removeClass('weui-btn_disabled').on('click', function () {
wx.scanQRCode({
needResult: 1,
scanType: ["qrCode", "barCode"],
success: function (res) {
$.toptip(res.resultStr, 'success');
}
});
});
});
</script>
</body>
</html>

View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>微信网页授权测试</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href="__STATIC__/mobile/library.min.css" rel="stylesheet">
<script src="__STATIC__/mobile/library.min.js"></script>
</head>
<body>
<!--{if empty($fans.fansinfo)}-->
<div class="weui-msg">
<div class="weui-msg__icon-area"><i class="weui-icon-cancel weui-icon_msg"></i></div>
<div class="weui-msg__text-area">
<h2 class="weui-msg__title">操作失败</h2>
<p class="weui-msg__desc">通过网页授权获取用户资料失败,请检查权限再试!</p>
</div>
<div class="weui-msg__opr-area">
<p class="weui-btn-area">
<a href="javascript:;" onclick="location.reload()" class="weui-btn weui-btn_default">重新获取(刷新)</a>
</p>
</div>
</div>
<!--{else}-->
<div class="header" style="padding:1rem 0 0.5rem 0;text-align:center">
<img style='width:132px;height:132px;border-radius:50%;border:0.5rem solid rgba(150,40,40,0.5)' src="{$fans.fansinfo.headimgurl}">
<h1>{$fans.fansinfo.nickname}</h1>
</div>
<div class="weui-cells__title">用户标识</div>
<div class="weui-cells">
<div class="weui-cell">
<div class="weui-cell__bd">OPENID</div>
<div class="weui-cell__ft" style="font-size:0.6rem">{$fans.fansinfo.openid}</div>
</div>
<div class="weui-cell">
<div class="weui-cell__bd">UNIONID</div>
<div class="weui-cell__ft" style="font-size:0.6rem">{$fans.fansinfo.unionid}</div>
</div>
</div>
<div class="weui-cells__title">详细资料</div>
<div class="weui-cells">
<div class="weui-cell">
<div class="weui-cell__bd">性别</div>
<div class="weui-cell__ft">{:[1=>'男',2=>'女'][$fans.fansinfo.sex]??'未知'}</div>
</div>
<div class="weui-cell">
<div class="weui-cell__bd">系统语言</div>
<div class="weui-cell__ft">{$fans.fansinfo.language}</div>
</div>
<div class="weui-cell">
<div class="weui-cell__bd">所在区域</div>
<div class="weui-cell__ft">{$fans.fansinfo.country}{$fans.fansinfo.province}{$fans.fansinfo.city}</div>
</div>
{if isset($fans.fansinfo.privilege.0)}
<div class="weui-cell">
<div class="weui-cell__bd">设备网络</div>
<div class="weui-cell__ft">{$fans.fansinfo.privilege.0}</div>
</div>
{/if}
</div>
<!--{/if}-->
</body>

View File

@ -19,6 +19,20 @@
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-10 padding-bottom-20">
<p class="help-block" style="margin-left:-5px">------- 公众号功能测试 -------</p>
<div class="pull-left padding-right-15 notselect">
<img data-tips-image src="{:url('@wechat/api.tools/oauth_qrc')}" style="width:80px;margin-left:-10px">
<p class="text-center" style="margin-left:-10px">网页授权</p>
</div>
<div class="pull-left padding-left-0">
<img data-tips-image src="{:url('@wechat/api.tools/jssdk_qrc')}" style="width:80px;">
<p class="text-center">JSSDK签名</p>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<!--{/if}-->

View File

@ -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];

View File

@ -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}