normal operation procedure to be implemented:
1, click forum page (no authorization, forum/index)
2, click personal center (authorization required, member/index)
3, jump to user login (user/login)
4, click below third party authorization (such as Wechat user/auth?client=wechat)
5, Wechat authorization jumps to personal center (member/index);
currently (with Yii2 and yii-wx), you cannot jump to the personal center page through Yii::$app- > request- > getUrl ()
and Yii::$app- > request- > referrer
.
protected function oauth()
{
$conf = Yii::$app->params["wx"]["mp"];
//$url = Yii::$app->request->getUrl();
$url = Yii::$app->request->referrer;
//var_dump($url);die;
$callback = Yii::$app->urlManager->createAbsoluteUrl(["/wechat/oauth", "url" => $url]);
$conf["oauth"]["callback"] = urlencode($callback);
$app = new Application(["conf" => $conf]);
$oauth = $app->driver("mp.oauth");
if (Yii::$app->user->isGuest) {
$oauth->send();
die;
}
}