2019独角兽企业重金招聘Python工程师标准>>>
public function actionCallback()
{
$this->enableCsrfValidation = false;
$config = [
'corp_id' => 'wxa81293306951ce69',
'debug' => true,
'agents' => [
'foox' => [
'agent_id' => 1000004,
'secret' => 'mXyyz0haLT8Y-uDyT1ST_8zGOvUSJhQC-5_PiEdI-v0',
'token' => 'oNKodUuPdreVu1ZcrSA9v',
'aes_key' => '8kjF1guL1mmCza6NkH7H595o2goAklcfvWTfdUvqFM4',
],
],
'oauth' => [
'scopes' => ['snsapi_base'],
'callback' => 'https://oa.abc.com/sign-in/callback',
],
'log' => [
'level' => 'debug',
'permission' => 0777,
'file' => '/home/wwwroot/oa.abc.com/a.log',
],
];
$app = Factory::work($config);
$oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
$user = $oauth->user();
$session=Yii::$app->session;
$session->set('wechat_user', $user->toArray());//这里是错误原因,这个数据太大塞不进session!!!
$targetUrl = empty($session->get('target_url')) ? '/' : $session->get('target_url');
header('location:'. $targetUrl);
}
public function actionLoginwx()
{ //var_dump($_SESSION);die;
$this->enableCsrfValidation = false;
$config = [
'corp_id' => 'wxa81293306951ce69',
'debug' => true,
// 应用列表
'agents' => [
'foox' => [
'agent_id' => 1000004,
'secret' => 'mXyyz0haLT8Y-uDyT1ST_8zGOvUSJhQC-5_PiEdI-v0',
// server config
'token' => 'oNKodUuPdreVu1ZcrSA9v',
'aes_key' => '8kjF1guL1mmCza6NkH7H595o2goAklcfvWTfdUvqFM4',
//...
],
//...
],
'oauth' => [
'scopes' => ['snsapi_base'],
'callback' => 'https://oa.abc.com/sign-in/callback',
],
'log' => [
'level' => 'debug',
'permission' => 0777,
'file' => '/home/wwwroot/oa.qyzg.com/a.log',
],
//...
];
$app = Factory::work($config);
$oauth = $app->oauth;
// 未登录
$session=Yii::$app->session;
if (empty($session->get('wechat_user'))) {
$session->set('target_url', 'https://oa.abc.com/sign-in/loginwx');
return $oauth->redirect();
// 这里不一定是return,如果你的框架action不是返回内容的话你就得使用
// $oauth->redirect()->send();
}
// 已经登录过
$user = $session->get('wechat_user');
var_dump($user);
/* $work = Factory::work($config);
$app = $work->agent('foox');
$app->server->push(function(){
return 'Hello easywechat.';
});
$response = $app->server->serve();
$response->send();*/
}