{"id":18972412,"url":"https://github.com/galan99/wechat-robot","last_synced_at":"2026-05-15T20:32:24.226Z","repository":{"id":154858054,"uuid":"139094394","full_name":"galan99/wechat-robot","owner":"galan99","description":"js微信聊天机器人（使用个人账号，非公众号） Wechat chat robot write by js.","archived":false,"fork":false,"pushed_at":"2018-06-29T03:13:34.000Z","size":2149,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T21:10:06.126Z","etag":null,"topics":["casperjs","js","nodejs","phantomjs","wechat","wechat-bot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galan99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-29T03:05:14.000Z","updated_at":"2019-02-13T03:06:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"898221d6-03c7-45ef-82ee-8fb023a69707","html_url":"https://github.com/galan99/wechat-robot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/galan99/wechat-robot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galan99%2Fwechat-robot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galan99%2Fwechat-robot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galan99%2Fwechat-robot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galan99%2Fwechat-robot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galan99","download_url":"https://codeload.github.com/galan99/wechat-robot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galan99%2Fwechat-robot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["casperjs","js","nodejs","phantomjs","wechat","wechat-bot"],"created_at":"2024-11-08T15:08:26.022Z","updated_at":"2026-05-15T20:32:24.214Z","avatar_url":"https://github.com/galan99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [查看源码](https://github.com/doterlin/wechat-robot)\n\n![](http://upload-images.jianshu.io/upload_images/3169607-74099cb906bf59f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n[![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://github.com/doterlin/wechat-robot)\n[![MIT](https://img.shields.io/npm/l/express.svg)](https://github.com/doterlin/wechat-robot/blob/master/LICENSE)\n[![copyRight](https://img.shields.io/badge/power%20by-doterlin-orange.svg)](https://github.com/doterlin)\n\n\n\u003e基于`phantomjs`和web端微信开发的聊天机器人。使用的微信账号（即充当机器人的账号）为个人账号，可自定义指令。\n# 效果\n可以指定一个微信账号：\n\n![撩妹](http://upload-images.jianshu.io/upload_images/3169607-2068f9382b4f9f29.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n自定义指令不会交给AI处理：\n\n![自定义指令](http://upload-images.jianshu.io/upload_images/3169607-a92574f783093df2.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n独乐乐不如众乐乐，可以指定到群聊上：\n\n![微信群](http://upload-images.jianshu.io/upload_images/3169607-7c929617f3b2a790.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n\n在后台程序查看log：\n\n![命令行输出](http://upload-images.jianshu.io/upload_images/3169607-c80a66d579e79279.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n\n\n# 使用场景\n\u003e + 微信智能回复，监控，统计等\n\u003e + 便捷查询\n\u003e + 娱(liao)乐(mei)\n\n\n# 如何使用\n### 1.安装环境\n下载[源码](https://github.com/doterlin/wechat-robot):\n```\ngit clone https://github.com/doterlin/wechat-robot.git\n```\n\n安装以下环境：\n\n1.[node.js](https://nodejs.org/)\n\n2.[phantomjs](http://phantomjs.org/)\n\n3.[casperjs](http://casperjs.org/)\n\n\n### 2.配置\n找到并配置好`/config/const.js`\n```\n//机器人名字\nvar ROBOT_NAME = \"小强\";\n\nmodule.exports = {\n    //微信web版地址\n    'URL'          : 'https://wx.qq.com/',\n\n    //机器人名字\n    'ROBOT_NAME'   : ROBOT_NAME,\n    \n    //图灵机器人apiKey和api地址\n    //AI部分使用的是第三方机器人图灵（http://www.tuling123.com/）\n    //这里只是示例，请大家自行到图灵官网注册并替换掉apikey免费版限5000次调用/天。有条件的同学可以付费支持下好产品\n    'TURING_APIKEY': '99fecec3424d416898b91b0998e2b26a',\n    'TURING_URL'   : 'http://www.tuling123.com/openapi/api',\n\n    //锁定的微信号备注，注意是备注；如果是群聊则填群聊名称即可。\n    //填写的名称请预先在手机微信上搜索确认搜索结果是否出现在第一个\n    'TARGET_NICK'  : '二十投小分队',\n\n    //启动时打招呼消息\n    'HELLO_WORLD'  : '[闪电]' + ROBOT_NAME + '[闪电]已启动...',\n\n}\n```\n\n\n### 3.运行和登录微信\n**安装依赖和运行命令：**\n```\nnpm install\n```\n```\ncapserjs index.js\n```\n*如果提示`python找不到`之类的话请安装一下[python](https://www.python.org/)并保证其能运行在全局*\n\n**扫码登录微信**\n运行后看到如下提示时则扫一下弹出来的二维码：\n```\n正在加载二维码...\n已保存二维码，路径：\"static/img/qr.jpg\".\n正在使用默认软件打开二维码，请用手机微信扫一扫确认登录 (若没有请手动打开)\n```\n请在`一分钟内`使用手机扫码并确认登录。出现`登录成功`和`发送欢迎语`提示后即可。这样就完成了使用步骤。下面的章节是介绍如何去扩展功能。\n\n# 指令和AI\n在这之前你可能需要两个方法：\n\n**message.send()**\n```\n//路径：src/utils/message.js\n//回复消息的方法message.send\n//使用如：\nvar message = require('/src/utils/message');\n...\ncasper.then(function(){\n   message.send(this, '你好');\n})\n```\n\n**ajax() / ajax.get()  / ajax.post() / ajax.getJSON()**\n```\n//路径：src/utils/ajax.js\n//在聊天器调ajax的方法\n//使用如：\nvar  ajax= require('/src/utils/ajax');\n...\ncasper.then(function(){\n   ajax(this, \"http://example.com/getInfo\", 'get', {uid: 123}, function(res){\n        console.log(JSON.stringify(res));\n    });\n  \n   //或者\n   ajax.get(this, \"http://example.com/getInfo\", {uid: 123}, function(res){\n        console.log(JSON.stringify(res));\n    });\n\n   //jsonp\n   ajax.getJSON(this, \"http://example.com/getInfo?calback=?\", {uid: 123}, function(res){\n        console.log(JSON.stringify(res));\n   });\n})\n```\n你可以根据需要按以下方面扩充机器人的功能：\n##### 编写指令\n```\n//你可以写一些指令而不是交给AI处理\n//指令分为精确匹配指令和模糊匹配指令\n\n//-------------------------------------------------------------------\n//精确匹配\n//精确指令在`/src/directive/exact.js`下编写。\n//key是指令名称，值是一个方法，接受参数msgContent(用户发送的消息)和casperIns(casper实例)，如：\n//当对方发送'关闭'指令时程序提示并退出。\nmodule.exports = {\n    '关闭': function (msgContent, casperIns) {\n        message.send(casperIns, '[玫瑰]感谢您的使用[玫瑰]\\n\\r([闪电]需要开启请在控制台启动程序[闪电])');\n        casperIns.echo('微信发出关闭口令，程序退出。')\n        return casperIns.exit();\n    }\n}\n\n//-------------------------------------------------------------------\n//模糊匹配\n//模糊匹配指令在`/src/directive/fuzzy.js`下编写。\n//接收参数前两个同精确指令，第三个是当前的正则表达式；\n//指令可单独防在src/directive/explain下方便维护，如weather.js：\n//匹配'地名 + 天气'，调用天气api\nvar weather = require('./explain/weather');\nmodule.exports = {\n    '/天气/g': weather \n}\n//weather.js实现如下：\nvar ajax = require('../../utils/ajax');\nvar message = require('../../utils/message');\n\nvar formatWeather = function(local, weather) {\n    //此方法对返回的json格式化，详情请查看源码\n}\n\nvar weather = function(msgContent, casperIns, regex) {\n    var local = msgContent.replace(/ |天气/, '');\n    var resource = 'http://wthrcdn.etouch.cn/weather_mini?city=' + encodeURIComponent(local);\n\n    ajax.get(casperIns, resource, {}, function(res){\n        var weather = JSON.parse(res);\n        if (weather.status == 1000) {\n            message.send(casperIns, formatWeather(local, weather));\n        } else {\n            message.send(casperIns, '未查找到相关天气信息。请尝试输入格式如\"广州天气\"。')\n        }\n    });\n   \n}\nmodule.exports = weather;\n//-------------------------------------------------------------------\n```\n\n##### 完善AI\n这个我目前也没研究。\n\n##### 调试\n调试代码时可将`capserjs`配置选像中的`logLevel`字段设为`info`将会显示更多`phantomjs`log，更多配置请移步[casperjs](http://casperjs.org/)文档。\n```\n//路径：config/casper.js\nmodule.exports =  {\n    clientScripts:  [\n        'static/js/jquery.js'\n    ],\n    pageSettings: {\n        loadImages: true,\n        userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.14 Safari/537.36',\n    },\n    logLevel: \"info\", //here\n    viewportSize: {width: 1300, height: 900},\n    verbose: true,\n    waitTimeout: 1000 * 60 * 60 * 24 * 365,\n    onWaitTimeout: function(){\n        console.log( 'waitFor*方法超时...' )\n    }\n}\n\n```\n另外，在执行各个步骤时会把浏览器截图保存到`/static/img`，方便查看浏览器渲染情况。比如每获取到一条新消息时会截图并覆盖为`lastNewMsgContent.png`。\n\n\n\u003e **二次开发若方便请`Fork`贡献给本[Github](https://github.com/doterlin/wechat-robot)，共同完善项目！**\n\n\n# 版本预告\n下一版本更新但不限于以下内容：\n\u003e 1.支持绑定多个微信帐号  \n\u003e 2.UI化控制台（`node.js web`同步命令log及部分操作）  \n\u003e 3.支持图片识别和回复（如斗图）  \n\u003e 4.更多实用指令  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalan99%2Fwechat-robot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalan99%2Fwechat-robot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalan99%2Fwechat-robot/lists"}