自动回复

来源:互联网 发布:html5翻牌小游戏源码 编辑:程序博客网 时间:2024/06/02 18:44

注: 这里说的自动回复是依赖第三方 API的

我这里用的API是 www.xiaohuangji.com
它的API(API我自己用chrome console 看的)有两种 POSTGET

POST

type : posturl: http://www.xiaohuangji.com/ajax.php参数: para

GET

Type : gethttp://www.xiaohuangji.com/ajax.php?para=1234

如果自己在写一些测试的时候发现 cross origin 类似的错误,可以把浏览器的跨域安全给关掉或者直接用一些专门发request 的工具(在线的也可以). 在Mac 下关掉 chrome 跨域安全是 open -a /Applications/Google\ Chrome.app --args --disable-web-security(其它的一些自己搜索 关掉chrome 跨哉)

我自己用这个API做了一个web QQ自动回复的,比较简陋,是用javascript 写的. 使用很简单,登陆好 WebQQ,把窗口拖小一点, 然后打一个好友聊天的对话框,QQ群也可以,但是计论组不可以. 然后打开 Chrome 控制台,运行所有的 javascript 代码就好.

xmlHttpReg = new XMLHttpRequest();lastM = '';    //获取最后一条消息function getLastMessage(){    chatContent = document.getElementsByClassName('buddy');    last = chatContent[chatContent.length-1];    lastAllChildren = last.children;    lastMsg = lastAllChildren[lastAllChildren.length - 1];    lastMsgContent = lastMsg.innerText;    //lastM = lastMsgContent;    console.log("getLastMessage success!! " + lastMsgContent);    return lastMsgContent;}    //发送消息function sendContent(content) {    document.getElementById('chat_textarea').value=content;    document.getElementById('send_chat_btn').click();    console.log("sendContent success!! " + content);}    //根据上面说的API去获取自动回复的消息然后发给好友function getReplyMsg(sendMsg) {    if (sendMsg != lastM) {        console.log("begin send request !");        var para = "para=" + sendMsg;        xmlHttpReg.open('post','http://www.xiaohuangji.com/ajax.php',                    true);        xmlHttpReg.setRequestHeader("Content-Type",                     "application/x-www-form-urlencoded;");        xmlHttpReg.onreadystatechange = doResult;        xmlHttpReg.send(para);        lastM = sendMsg;    };}function doResult() {          if (xmlHttpReg.readyState == 4) {//4代表执行完成      if (xmlHttpReg.status == 200) {//200代表执行成功          console.log("send success!! " + xmlHttpReg.responseText);         sendContent(xmlHttpReg.responseText);      }  }}function doReply() {    getReplyMsg(getLastMessage());}    //每隔3秒执行一次~~var timerID = window.setInterval("doReply()",3000);

详细请见~

0 0
原创粉丝点击