function change_token($c, $dbo, $bottom = 10, $mail = true, $write = true) { $sql = "select sina_token as st, unix_timestamp(token_update_at) as tua, token_expires_in as tei, user_id as uid from user_info_sina where sina_token IS NOT NULL limit 10"; $sql_res = $dbo->getRs($sql); while (1) { foreach ($sql_res as $res) { $token = $res['st']; $uid = $res['uid']; $tua = $res['tua']; $tei = $res['tei']; $now = time(); $left_time = $tua + $tei - $now; if ($left_time < 3600 && $left_time > 2650) { $msg = "user {$uid} 's token will expire in an hour."; $sub = "微动力提醒"; if ($mail) { mail_to_master($msg, $sub); } else { $write_msg = "{$sub}: {$msg} \n"; write_line_with_time_and_newline($write_msg); } } // var_dump($token); // debug $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token); $api_left = api_left($c); // var_dump($api_left); // debug if ($api_left['user'] > $bottom) { $msg = 'token changed, user_id:' . "{$uid}\n"; // echo $msg; if ($write) { write_line_with_time_and_newline($msg); } return $c; } } // 当前没有可用token了 $msg = "no avilable token, exit."; // echo $msg; write_line_with_time_and_newline($msg); exit; } }
function change_token($c, $dbo) { $sql = "select sina_token as st, user_id as uid from user where sina_token IS NOT NULL limit 10"; $sql_res = $dbo->getRs($sql); while (1) { foreach ($sql_res as $res) { $token = $res['st']; // var_dump($token); // debug $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token); $api_left = api_left($c); // var_dump($api_left); // debug if ($api_left['user'] > 10) { $msg = 'token changed, user_id:' . "{$res['uid']}\n"; // echo $msg; write_log($msg); return $c; } } // 当前没有可用token了 $msg = "no avilable token, exit.\n"; // echo $msg; write_line($msg); exit; } }