public function loginAction() { if ($this->request->isAjax()) { if (!$this->getCookie('openid')) { $this->end(json_encode(['code' => -1, 'num' => 0])); } $data['openid'] = $this->getCookie('openid'); $weixin = new \Weixin(); $code = $weixin->getReward($data['openid']); $detail = $weixin->getDetail($data['openid']); $num = $detail == 404 ? 0 : $detail['num']; $this->end(json_encode(['code' => $code, 'num' => $num])); } //判断是否存在分享者 $validate = new \Validate(); $f_openid = $validate->getQuery('fopenid'); if ($f_openid) { $this->setCookie('f_openid', $f_openid, time() + 3600); } //判断是否登录过 $weixin = new \Weixin(); if (!$weixin->is_weixin()) { $this->end("请用微信访问!"); } if (!$this->getCookie('openid') or $weixin->getDetail($this->getCookie('openid')) == 404) { $this->response->redirect($weixin->empower('http://www.51sxwang.com/weixin/oauth2')); } $detail = $weixin->getDetail($this->getCookie('openid')); $flag = ''; if ($detail != 404) { $flag = "?fopenid=" . $detail['user_openid']; } $get_url = 'http://' . $this->request->getHttpHost() . $this->request->getURI(); $share_url = 'http://www.51sxwang.com/weixin/login' . $flag; if ($get_url != $share_url) { $this->response->redirect($share_url); } $list = $weixin->getList(10); $reward = $weixin->getRewardList($detail['user_id']); $frends = $weixin->getFrendsReward($detail['user_openid']); $data = $this->getSignature($share_url); $this->view->setLayout(''); $this->view->setVars(['wx_config' => $data, 'detail' => $detail, 'list' => $list, 'reward' => $reward, 'frends' => $frends]); }