/** * 当前用户 * @return [type] [description] */ function getMe() { $user = Openid::with('user')->where('openid', $this->openid)->first(); $left = 2; if ($user && $user->user && $user->user->last && $this->isToday($user->user->last)) { $left = 2 - $user->user->times; } return ['user' => $user, 'left' => $left]; }
public function index() { $code = Input::get("code"); $state = Input::get("state"); $goto = Cache::get('wechat:state:' . $state); $url = $this->getTokenURI($code); $res = Requests::get($url); $response = json_decode($res->body, true); Cache::put('wechat:auth:access_token', $response['access_token'], intval($response['expires_in']) / 60 - 1); Cache::put('wechat:auth:openid', $response['openid'], intval($response['expires_in']) / 60 - 1); if ($response['scope'] == 'snsapi_userinfo') { $userinfo = $this->getUserInfo($response['access_token'], $response['openid']); $userinfo['privilege'] = json_encode($userinfo['privilege']); if (Openid::openid_exists($response['openid'])) { Openid::_update($response['openid'], $userinfo); } else { $openid = new Openid(); $openid->setRawAttributes($userinfo); $openid->save(); } } return redirect()->away($goto . '?openid=' . $response['openid'])->withCookie(cookie('_openid', $response['openid'])); }
/** * Create a new profile composer. * * @param UserRepository $users * @return void */ public function __construct(Request $req) { // Dependencies automatically resolved by service container... $user = Openid::where('openid', session('wechat_openid'))->first(); $this->user = $this->user ? ['login' => true] : false; }
public function getAnimation() { $openid = Openid::one($this->openid); return view('wechat.enjoy.animation')->with('openid', $openid); }