小黑龙搞事情
2017 年12 月 21 日
一些家境清寒的无业游民组成的滑雪组织
概述
来自雪上的友谊 、 来自雪上的灵感
目标
微信公众号的创建
python 实现的微信机器人
打通任(微信公众号在线报名)督(微信群机器人实时提醒)二脉
里程碑
公众号的创建
应该具备
已经备案好的域名、空间
已经申请的公众号、注意一定要是组织、公司号不能是个人订阅号
https://mp.weixin.qq.com/cgi-bin/registermidpage?action=index&lang=zh_CN
在线报名m站
之后应该是这样的 :
python 实现微信机器人
应该具备 :
一台可用于微信挂机的智能手机
一个微信号
一台服务器
python 基础
以下:试验成功的微信机器人源码 :
#!/usr/bin/python
#coding=utf-8
import pymysql
import datetime
from wxpy import *
conn=pymysql.connect(
host="192.168.*.*",
port=3306,
user="**",
password="**",
db="db1",
charset="utf8")
#try:
# cur=conn.cursor()
# print ('Insert name 1' )
# cur.execute("Insert into wx (name, num,group_name) values ( %s, %s ,%s )", ('zs', 1 ,'123' ) )
# conn.commit()
#finally:
# conn.close()
bot = Bot(console_qr=True, cache_path=True)
nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
bot.file_helper.send('Hello from wxpy is : {} !'.format(nowTime))
tuling = Tuling(api_key='***')
cur=conn.cursor()
try:
@bot.register([ Group], TEXT)
def auto_reply(msg):
currentMember=str(msg.member)
currentGroupName=str(msg.sender)
cur.execute("Insert into wx (name, num,group_name) values ( %s, %s ,%s )", (currentMember, 1 ,currentGroupName ) )
conn.commit()
print('群:{} 消息 保存成功'.format(currentGroupName))
if isinstance(msg.chat, Group) and msg.is_at:
tuling.do_reply(msg)
print('消息回复成功')
#result= (currentMember.index('二')>=0)
#if result:
#return '{} 吃屎'.format(currentMember)
finally:
print ('end' )
bot.join()
CREATE TABLE `wx` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`num` int(11) DEFAULT NULL,
`group_name` varchar(288) DEFAULT NULL,
`datetime` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1099 DEFAULT CHARSET=utf8
python微信机器人API请查阅 :
https://wxpy.readthedocs.io/zh/latest/图灵机器人网站 :
http://www.tuling123.com/