Wechat.php
923 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace app\common\controller;
use app\common\controller\Frontend;
use EasyWeChat\Foundation\Application;
use think\Cache;
use think\Request;
use think\Session;
/**
* 微信公众号控制器基类
*/
class Wechat extends Frontend
{
protected $app = null;
protected $config = null;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->config = \config('wechat');
$this->app = new Application($this->config);
$this->oauth();
}
public function oauth() {
$user = Session::get('user');
if(!$user) {
$request = Request::instance();
Session::set('target_url',$request->url(true));
$response = $this->app->oauth->scopes(['snsapi_userinfo'])
->redirect();
$response->send();
}
}
}