最新活动:电脑PC端+手机端+微网站+自适应网页多模板选择-建站388元起价!!!
当前位置:主页 > 网站建设 > 使用JavaScript实现手机QQ在线状态代码实现分享前

使用JavaScript实现手机QQ在线状态代码实现分享前

时间:2023-05-27 11:05:27 阅读: 文章分类: 网站建设 作者: 建站小能手

导读:前端开发前端开发手机QQ是一款非常流行的即时通讯应用程序,在这个应用中,我们可以看到好友的在线状态,如在线、离线、忙碌等。这个在线状态是通过与服务器交互来实现的,因此我们可以使网站建设seo网站优化。

网站建设seo网站优化

手机QQ是一款非常流行的即时通讯应用程序,在这个应用中,我们可以看到好友的在线状态,如在线、离线、忙碌等。这个在线状态是通过与服务器交互来实现的,因此我们可以使用JavaScript模拟这个过程,以获取好友的在线状态。

以下是一份基于JavaScript的手机QQ在线状态查询代码示例:

// 配置变量 var account = "your_account"; // 填写要查询的好友账号 var loginUrl = "http://ptlogin2.qq.com/login"; // QQ登录页面的URL var checkUrl = "http://d1.web2.qq.com/channel/poll2"; // QQ查询好友状态的URL var appId = "1003903"; // 应用ID号 var clientVer = "0.0.1"; // 应用版本号 var psessionid = ""; // 会话ID号 var vfwebqq = ""; // vfwebqq参数 var pollingInterval = 5000; // 检查好友状态的时间间隔,单位为毫秒 // 使用JSONP获取QQ登录页面的COOKIE信息 function getQqLoginCookie() { var script = document.createElement('script'); script.src = loginUrl + '?appid=' + appId + '&js_type=0&login_type=3&'; script.type = 'text/javascript'; script.async = true; document.body.appendChild(script); } // 从COOKIE中提取ptwebqq和uin参数 function getCookie(key, content) { var regex = new RegExp('\\b' + key + '\\s*=([^;]*)', 'i'); var match = regex.exec(content || document.cookie); return match && match[1]; } // 登录QQ并获取Cookie信息 function loginQq(username, password) { var iframe = document.createElement("iframe"); iframe.src = "about:blank"; document.body.appendChild(iframe); var form = iframe.contentDocument.createElement("form"); form.method = "post"; form.action = loginUrl; var input1 = iframe.contentDocument.createElement("input"); input1.type = "hidden"; input1.name = "u"; input1.value = username; form.appendChild(input1); var input2 = iframe.contentDocument.createElement("input"); input2.type = "hidden"; input2.name = "p"; input2.value = password; form.appendChild(input2); var input3 = iframe.contentDocument.createElement("input"); input3.type = "hidden"; input3.name = "verifycode"; input3.value = ""; form.appendChild(input3); var input4 = iframe.contentDocument.createElement("input"); input4.type = "hidden"; input4.name = "webqq_type"; input4.value = "10"; form.appendChild(input4); var input5 = iframe.contentDocument.createElement("input"); input5.type = "hidden"; input5.name = "remember_uin"; input5.value = "1"; form.appendChild(input5); var input6 = iframe.contentDocument.createElement("input"); input6.type = "hidden"; input6.name = "login2qq"; input6.value = "1"; form.appendChild(input6); var input7 = iframe.contentDocument.createElement("input"); input7.type = "hidden"; input7.name = "aid"; input7.value = appId; form.appendChild(input7); var input8 = iframe.contentDocument.createElement("input"); input8.type = "hidden"; input8.name = "u1"; input8.value = "http://w.qq.com/proxy.html?login2qq=1&webqq_type=10"; form.appendChild(input8); var input9 = iframe.contentDocument.createElement("input"); input9.type = "hidden"; input9.name = "ptredirect"; input9.value = "0"; form.appendChild(input9); var input10 = iframe.contentDocument.createElement("input"); input10.type = "hidden"; input10.name = "ptlang"; input10.value = "2052"; form.appendChild(input10); var input11 = iframe.contentDocument.createElement("input"); input11.type = "hidden"; input11.name = "daid"; input11.value = "164"; form.appendChild(input11); var input12 = iframe.contentDocument.createElement("input"); input12.type = "hidden"; input12.name = "from_ui"; input12.value = "1"; form.appendChild(input12); var input13 = iframe.contentDocument.createElement("input"); input13.type = "hidden"; input13.name = "pttype"; input13.value = "1"; form.appendChild(input13); var input14 = iframe.contentDocument.createElement("input"); input14.type = "hidden"; input14.name = "dumy"; input14.value = "公司网站建设"; form.appendChild(input14); iframe.contentDocument.body.appendChild(form); form.submit(); } // 初始化会话信息 function initSessionInfo() { // 从登录成功的COOKIE中解析出ptwebqq和uin参数 var ptwebqq = getCookie("ptwebqq"); var qqUin = getCookie("uin"); qqUin = qqUin.substring(1, qqUin.length - 1); // 请求一个随机值获取vfwebqq参数 var xhr = new XMLHttpRequest(); xhr.open("GET", "http://s.web2.qq.com/api/getvfwebqq?ptwebqq=" + ptwebqq + "&clientid=seo网站优化软件" + appId + "&psessionid=&t=" + (new Date()).valueOf() + "&vfwebqq=", false); xhr.send(); // 从JSON结果中解析出vfwebqq参数 var resp = eval("(" + xhr.responseText + ")"); vfwebqq = resp["result"]["vfwebqq"]; // 请求ptwebqq和psessionid参数 xhr = new XMLHttpRequest(); xhr.open("GET", checkUrl + "?clientid=" + appId + "&psessionid=&t=" + (new Date()).valueOf() + "&vfwebqq=" + vfwebqq, false); xhr.send(); // 从JSON结果中解析出ptwebqq和psessionid参数 resp = eval("(" + xhr.responseText + ")"); psessionid = resp["result"]["psessionid"]; } // 获取好友的JSON字符串 function getFriendJson() { var xhr = new XMLHttpRequest(); xhr.open("POST", checkUrl + "?clientid=" + appId + "&psessionid=" + psessionid + "&t=" + (new Date()).valueOf(), false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xhr.send("r={\"ptwebqq\":\"" + getCookie("ptwebqq") + "\",\"clientid\":\"" + appId + "\",\"psessionid\":\"" + psessionid + "\",\"key\":\"\"}"); return xhr.responseText; } // 解析好友JSON字符串,返回好友在线状态 function getFriendStatus(friendJson, friendAccount) { var decoded = eval("(" + friendJson + ")"); var friends = decoded["result"][0]["value"]["info"]; for (var i = 0; i < friends.length; i++) { var friend = friends[i]; if (friend["uin"] == friendAccount) { return friend["stat"]["name"]; } } return ""; } // 定时查询好友状态 function pollFriendStatus() { var friendJson = getFriendJson(); var friendStatus = getFriendStatus(网站seo优化课程friendJson, account); console.log("Friend " + account + " is " + friendStatus); setTimeout(pollFriendStatus, pollingInterval); } // 执行查询好友状态的主函数 function queryFriendStatus() { getQqLoginCookie(); // 获取QQ登录页面的COOKIE信息 loginQq("your_username", "your_password"); // 使用QQ账户登录 initSessionInfo(); // 初始化会话信息 pollFriendStatus(); // 定时查询好友状态 } queryFriendStatus(); // 运行主程序

关键词标签: 手机 状态 在线

声明: 本文由我的SEOUC技术文章主页发布于:2023-05-27 ,文章使用JavaScript实现手机QQ在线状态代码实现分享前主要讲述在线,状态,手机网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_11191.html

我的IDC 网站建设技术SEOUC.COM
专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
  • 5000+合作客服
  • 8年从业经验
  • 150+覆盖行业
  • 最新热门源码技术文章