您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

[分享]模拟新浪微博自动登陆,该如何处理

2025/2/9 10:35:01发布18次查看
[分享]模拟新浪微博自动登陆
博客原文地址: http://blog.csdn.net/lgg201/article/details/8050606
/**
 * 功能: 模拟新浪微博登陆
 * 用途: 模拟用户登陆, 以便进行后续操作, 比如自动化的控制自己的新浪app刷新某些数据
 * 注意事项: 
 *  1. 需要安装nodejs
 *  2. 需要下载新浪的加密js文件, 请到新浪登陆页查看网络请求自己下载最新版本(我当时用的: http://js.t.sinajs.cn/t35/miniblog/static/js/sso.js?version=e482ef2bbdaa8bc2)
 *  3. 对新浪加密js文件进行修改, 以便让nodejs可以运行它
 * 1) 在文件前面增加下面内容
var window = {
location : {
hash : '', 
host : 'weibo.com', 
hostname : 'weibo.com', 
href : 'http://weibo.com/', 
pathname : '/', 
port : '', 
protocol : 'http:', 
search : ''
}, 
navigator : {
appcodename : 'mozilla', 
appname : 'netscape', 
appversion : '5.0 (macintosh)', 
buildid : '20120713134347', 
cookieenabled : true, 
donottrack : 'unspecified', 
language : 'en-us'
}
};
var location = window.location;
var navigator = window.navigator;
 * 2) 在文件后面增加下面内容
var argv = process.argv.splice(2);
var pubkey = argv[0],
servertime = argv[1],
nonce = argv[2],
password = argv[3];
var rsakey = new sinassoencoder.rsakey();
rsakey.setpublic(pubkey, '10001');
password = rsakey.encrypt([servertime, nonce].join(\t) + \n + password); 
console.log(password);
process.exit();
 * 4. 修改encode_password函数中的nodejs程序路径和修改后的新浪js文件路径
 *  5. 修改用户名密码
 * author: selfimpr
 * blog: http://blog.csdn.net/lgg201
 * mail: lgg860911@yahoo.com.cn
 */
define('request_method_get', 'get');
define('request_method_post', 'post');
define('request_method_head', 'head');
define('cookie_file', '/tmp/sina.login.cookie');
function curl_switch_method($curl, $method) {
switch ( $method) {
case request_method_post:
curl_setopt($curl, curlopt_post, true);
break;
case request_method_head:
curl_setopt($curl, curlopt_nobody, true);
break;
case request_method_get:
default:
curl_setopt($curl, curlopt_httpget, true);
break;
}
}
function curl_set_headers($curl, $headers) {
if ( empty($headers) ) return ;
if ( is_string($headers) ) 
$headers = explode(\r\n, $headers);
#类型修复
foreach ( $headers as &$header ) 
if ( is_array($header) ) 
$header = sprintf('%s: %s', $header[0], $header[1]);
curl_setopt($curl, curlopt_httpheader, $headers);
}
function curl_set_datas($curl, $datas) {
if ( empty($datas) ) return ;
curl_setopt($curl, curlopt_postfields, $datas);
}
function curl_request($url, $method = request_method_get, $datas = null, $headers = null) {
static $curl;
if ( !$curl )
$curl = curl_init();
curl_switch_method($curl, $method);
curl_setopt($curl, curlopt_url, $url);
curl_setopt($curl, curlopt_returntransfer, true);
curl_setopt($curl, curlopt_followlocation, true);

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product