Пример #1
0
 public function saveAction()
 {
     $reslt = array();
     $request = $this->get("request");
     $uid = isset($_SESSION["uid"]) ? $_SESSION["uid"] : "";
     if (empty($uid)) {
         $reslt["s"] = "0";
         $reslt["msg"] = "微博登录失败或超时,请重新通过微博登录!";
         $response = new Response(json_encode($reslt));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     }
     $type = $request->get("bind_type");
     $login_account = $request->get("login_account");
     $pwd = $request->get("pwd");
     try {
         //校验wefafa帐号和密码
         $staffMgr = new Staff($this->get('we_data_access'), null, $login_account, $this->get('logger'));
         $staffInfo = $staffMgr->getInfo();
         if (empty($staffInfo)) {
             $reslt["s"] = "0";
             $reslt["msg"] = "帐号[" . $login_account . "]不存在!";
         } else {
             $tcode = $staffInfo["t_code"];
             $p_code = DES::encrypt($pwd);
             if ($tcode != $p_code) {
                 $reslt["s"] = "0";
                 $reslt["msg"] = "帐号或密码不正确!";
             } else {
                 $accountbind = new \Justsy\BaseBundle\Management\StaffAccountBind($this->get('we_data_access'), null, $this->get('logger'));
                 $r = $accountbind->Bind($type, "", $login_account, $uid);
                 $this->get('logger')->err($type . "," . $uid . "," . $login_account . "," . $uid);
                 $reslt["s"] = $r;
             }
         }
     } catch (\Exception $e) {
         $this->get('logger')->err($e);
         $reslt["s"] = "0";
         $reslt["msg"] = "绑定失败,请检查帐号是否填写正确!";
     }
     $response = new Response(json_encode($reslt));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Пример #2
0
 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));
 }