<?php
/**
 *
 */

include_once(dirname(dirname(__FILE__)) . "/library/publicBase.php");

class callback extends publicBase {

    public function wxlogin() {
        if (empty($this->get('code'))) $this->show_message('登录失败,请重新登录', 'goback');

        $state = explode('-', $this->get('state'));
        if ($state[0] == CALLBACK_KNOWLEDGE_LOGIN) {
            $obj = new mManage();
            $res = $obj->weixinLogin($this->get('code'), $this->get('state'));
            if (!$res) $this->show_message($obj->getError(), 'goback');

            session_start();
            $_SESSION['nickname'] = $res['nickname'];
            $_SESSION['openid'] = $res['openid'];
            $_SESSION['token'] = $res['jwttoken'];
            session_write_close();

            header('Location:' . urldecode($state[1]));
            exit;
        }
        exit;
    }
}