Closed wblbird closed 7 years ago
正常显示了认证页面,然后返回我的业务页面就出错了 业务页写了2个版本,1页面按着你的示例代码来,2页面按着easywechat的示例代码来的,均出错, 代码如下 `
'oauth' => [//配置代码 'scopes' => ['snsapi_userinfo'], 'callback' => 'site/callback', ],`
`
public function actionCallback()//认证回调页面 { $app = Yii::$app->wechat; $oauth = $app->oauth; // 获取 OAuth 授权结果用户信息 $user = $oauth->user(); $_SESSION['wechat_user'] = $user->toArray(); $targetUrl = empty($_SESSION['target_url']) ? '/' : $_SESSION['target_url']; header('location:'. $targetUrl); // 跳转到 user/profile }
public function actionMyapp1()//业务页面1 { if(Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) { return Yii::$app->wechat->authorizeRequired()->send(); } echo '111'; } public function actionMyapp2()//业务页面2 { $this->layout = false; $app = Yii::$app->wechat; $oauth = $app->oauth; // 未登录 if (empty($_SESSION['wechat_user'])) { $_SESSION['target_url'] = 'site/myapp'; return $oauth->redirect(); // 这里不一定是return,如果你的框架action不是返回内容的话你就得使用 // $oauth->redirect()->send(); } // 已经登录过 $user = $_SESSION['wechat_user']; }
正常显示了认证页面,然后返回我的业务页面就出错了 业务页写了2个版本,1页面按着你的示例代码来,2页面按着easywechat的示例代码来的,均出错, 代码如下 `
`
`