public function authorizeAction() { try { $da = $this->get("we_data_access"); $user = $this->get('security.context')->getToken()->getUser(); $request = $this->get("request"); $code = $request->get("code"); if (empty($code)) { $Auth = new SaeTOAuthV2(SaeTOAuthV2::$appid, SaeTOAuthV2::$appkey); $get_code_url = $Auth->getAuthorizeURL($this->generateUrl("JustsyBaseBundle_weibo_sina_authorize"), "code", "123456"); $response = new Response(''); $response->headers->set('location', $get_code_url); return $response; } else { $Auth = new SaeTOAuthV2(SaeTOAuthV2::$appid, SaeTOAuthV2::$appkey); $token = $Auth->getAccessToken('code', array('code' => $code, 'redirect_uri' => 'http://' . $_SERVER["HTTP_HOST"] . $this->generateUrl("JustsyBaseBundle_weibo_sina_authorize"))); $SinaWeiboMgr = new SinaWeiboMgr($da, $token["UID"], $token["Token"]); $SinaWeiboMgr->saveToken($token, $user->getUserName(), $user->eno); return $this->render("JustsyBaseBundle:Weibo:sinaback.html.twig", array('s' => '1', 'm' => '', 'curr_network_domain' => $user->edomain)); } } catch (\Exception $e) { var_dump($e->getMessage()); return $this->render("JustsyBaseBundle:Weibo:sinaback.html.twig", array('s' => '0', 'm' => $e->getMessage(), 'curr_network_domain' => $user->edomain)); } }
public function weibocallbackAction() { $request = $this->get("request"); $o = new SaeTOAuthV2(Utils::$WB_AKEY, Utils::$WB_SKEY); $login_type = $request->get('_wefafa_t'); $code_url = $o->getAuthorizeURL("http://we.fafatime.com/api/weibo/callback?_wefafa_t=" . $login_type); $keys = array(); $keys['code'] = $request->get('code'); $keys['redirect_uri'] = "http://we.fafatime.com"; try { $token = $o->getAccessToken('code', $keys); $c = new SaeTClientV2(Utils::$WB_AKEY, Utils::$WB_SKEY, $token["access_token"]); $info = $c->show_user_by_id($token["uid"]); if (!empty($info["error"])) { $this->get("logger")->err(json_encode($info)); } $province = Utils::do_post_request("http://api.t.sina.com.cn/provinces.json", ""); //查询当前用户的已获取粉丝列表 //$mgr = new SinaWeiboMgr($this->get('we_data_access'),$token["uid"],$token["access_token"]); //$myfans = $mgr->getlist(); //$wangbin_fans = $c->followers_by_id("2793358674"); $accountbind = new \Justsy\BaseBundle\Management\StaffAccountBind($this->get('we_data_access'), null, $this->get('logger')); $bind = $accountbind->GetBind_By_Uid($login_type, $token["uid"], empty($info["error"]) ? $info : null); //判断是否绑定帐号,没有则跳转到绑定页面,已绑定则获取对应wefafa帐号自动登录 $_SESSION["uid"] = $token["uid"]; //$_SESSION["weibo_account"]= $info["uid"]; $_SESSION["token"] = $token["access_token"]; return $this->render('JustsyBaseBundle:Login:weibo_auth.html.twig', array('code' => $keys['code'], 'token' => $token["access_token"], "uid" => $token["uid"], "info" => $info, "code_url" => $code_url, "province" => $province, "isbind" => empty($bind) ? "0" : "1", "error" => empty($info["error"]) ? "" : "帐号异常,无法调用微博API!", "error_msg" => empty($info["error"]) ? "" : $info["error"])); } catch (\Exception $e) { $this->get("logger")->err($e); } return $this->render('JustsyBaseBundle:Login:default.html.twig', array('code_url' => $code_url)); }