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)); }
public function synclistbysina($logger, $next_cursor = 0) { $total_number = 0; $error_count = 0; //粉丝写库错误计数器,当计数大于100时,停止写入数据 $single_count = 0; try { $c = new SaeTClientV2(Utils::$WB_AKEY, Utils::$WB_SKEY, $this->token); while (true) { if ($single_count >= 1000) { break; } $myfans = $c->followers_by_id($this->uid, $next_cursor, 200); //$logger->err("this->uid==================================".$this->uid); //$logger->err(json_encode($myfans)); if (!empty($myfans["error"])) { $logger->err(json_encode($myfans)); throw $myfans; } //解析列表 并写入数据库 $users = $myfans["users"]; for ($i = 0; $i < count($users); $i++) { $item = $users[$i]; try { //获取注册时间 $ins = "insert into we_weibo_sina_fans(uid,id,idstr,screen_name,name,province,city,gender,verified,followers_count,favourites_count,statuses_count,friends_count,created_at )values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; $para = array((string) $this->uid, (int) $item["id"], (string) $item["idstr"], (string) $item["screen_name"], (string) $item["name"], (int) $item["province"], (int) $item["city"], (string) $item["gender"], (string) $item["verified"], (int) $item["followers_count"], (int) $item["favourites_count"], (int) $item["statuses_count"], (int) $item["friends_count"], date("Y-m-d H:i:s", strtotime($item["created_at"]))); $this->conn->ExecSQL($ins, $para); $single_count++; } catch (\Exception $e) { $error_count++; if ($error_count >= 100) { return array("s" => 1, "next_cursor" => 0, "total_number" => $total_number); } } } $next_cursor = $myfans["next_cursor"]; $total_number = $myfans["total_number"]; //$logger->err("this->uid==================================".$this->uid." next_cursor:".$next_cursor); if (empty($next_cursor) || (int) $next_cursor == 0) { break; } } } catch (\Exception $e) { $logger->err($e); throw $e; } return array("s" => 1, "next_cursor" => $next_cursor, "total_number" => $total_number); }
public function getMyWeibo($uid, $reqnum = 20, $since_id) { $result = array('returncode' => '0000', 'data' => null, 'msg' => '', 'err' => array()); $da = $this->get("we_data_access"); $user = $this->get('security.context')->getToken()->getUser(); $SinaWeiboMgr = new SinaWeiboMgr($da); $token = $SinaWeiboMgr->getToken($uid, $user->eno); if ($token == null) { $result = array('returncode' => '0003', 'msg' => '令牌无效', 'err' => array()); return $result; } $SaeTClientV2 = new SaeTClientV2(SaeTOAuthV2::$appid, SaeTOAuthV2::$appkey, $token['access_token'], $token['refresh_token']); $re = $SaeTClientV2->user_timeline_by_id('', $page = 1, $reqnum, $since_id); if ($SaeTClientV2->hasError($re)) { $result['returncode'] = '0004'; $result['err'] = $SaeTClientV2->getError(); } else { $data = array(); foreach ($re['statuses'] as $row) { $data[] = array("blog_id" => $row["id"], "create_at" => $row["create_at"], "blog_content" => $row["text"], "source" => $row["source"], "comment_count" => $row["comments_count"], "repost_count" => $row["reposts_count"], "pic_urls" => $row["pic_urls"]); } $result['data'] = $data; } return $result; }