作者 Administrator

网页授权

... ... @@ -17,7 +17,13 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
function isWechat(){
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
return true;
} else {
return false;
}
}
function isInArray($str , $arr){
... ...
... ... @@ -8,9 +8,12 @@ use app\common\model\TemplateView;
use app\school\model\basic\Teacher;
use app\school\model\content\Newscategory;
use app\school\model\ManystoreShop;
use EasyWeChat\Factory;
use Overtrue\Socialite\AuthorizeFailedException;
use think\Config;
use think\Cookie;
use think\Db;
use think\Exception;
use think\Request;
class Index extends Frontend
... ... @@ -73,6 +76,24 @@ class Index extends Frontend
$this->assign('elegant_product',$elegant_product);
$this->assign('links',$links);
$this->view->assign('index',$index='foot');//首页隐藏头部使用
if (isWechat()){
$config = [
'app_id' => 'wx401d047673f1c578',
'secret' => '2f99955f1964d30d6e962c345c268274',
'response_type' => 'array',
];
$app = Factory::officialAccount($config);
try {
$oauth = $app->oauth;
$user = $oauth->user();
session("open_id",$user->id);
}catch (AuthorizeFailedException $e){
$response = $app->oauth->scopes(['snsapi_userinfo'])
->redirect($this->request->domain());
$response->send();
}
}
return $this->view->fetch("/index/school/{$this->template}");
}
... ...