diff --git a/README.md b/README.md index bb7e2ec..6a6de5d 100644 --- a/README.md +++ b/README.md @@ -784,6 +784,15 @@ Content: ``` + +这个分支的维护者是maze,如果你对这个分支感兴趣或者想讨论如何earn money,可以加机器人 + +
+join us +
+ +- association_login + 目前网页版微信已经可以脱离扫码,但是依然需要在客户端进行确认登录。 ## Discussion Group 如果你希望和 WeixinBot 的其他开发者交流,或者有什么问题和建议,欢迎大家加入微信群【Youth fed the dog】一起讨论。扫描下面的二维码添加机器人为好友,并回复【Aidog】获取入群链接。 @@ -794,6 +803,3 @@ Content: 注:这个不是群的二维码,是机器人拉你入群,记得回复机器人【Aidog】哦~ (secret code: Aidog) ## Recent Update - -- association_login - 目前网页版微信已经可以脱离扫码,但是依然需要在客户端进行确认登录。 diff --git a/imgs/auto.jpg b/imgs/auto.jpg new file mode 100644 index 0000000..90d0713 Binary files /dev/null and b/imgs/auto.jpg differ diff --git a/wxbot_demo_py3/weixin.py b/wxbot_demo_py3/weixin.py old mode 100755 new mode 100644 index 53ba474..9bbadac --- a/wxbot_demo_py3/weixin.py +++ b/wxbot_demo_py3/weixin.py @@ -105,10 +105,11 @@ def __init__(self): self.GroupMemeberList = [] # 群友 self.PublicUsersList = [] # 公众号/服务号 self.SpecialUsersList = [] # 特殊账号 + self.list_name = [] #同一人说话不超过三句 self.autoReplyMode = False self.syncHost = '' self.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36' - self.interactive = False + self.interactive = True self.autoOpen = False self.saveFolder = os.path.join(os.getcwd(), 'saved') self.saveSubFolders = {'webwxgeticon': 'icons', 'webwxgetheadimg': 'headimgs', 'webwxgetmsgimg': 'msgimgs', @@ -435,6 +436,7 @@ def webwxsync(self): if dic['BaseResponse']['Ret'] == 0: self.SyncKey = dic['SyncKey'] + #self.SyncKey = dic['SyncCheckKey'] self.synckey = '|'.join( [str(keyVal['Key']) + '_' + str(keyVal['Val']) for keyVal in self.SyncKey['List']]) return dic @@ -649,6 +651,7 @@ def getGroupName(self, id): if name == '未知群': # 现有群里面查不到 GroupList = self.getNameById(id) +#print('maze',GroupList) for group in GroupList: self.GroupList.append(group) if group['UserName'] == id: @@ -706,6 +709,7 @@ def _showMsg(self, message): dstName = None groupName = None content = None + hot_package = None msg = message logging.debug(msg) @@ -759,6 +763,8 @@ def _showMsg(self, message): # 收到了红包 if content == '收到红包,请在手机上查看': msg['message'] = content + hot_package = 123 + print('maze',hot_package) # 指定了消息内容 if 'message' in list(msg.keys()): @@ -772,6 +778,7 @@ def _showMsg(self, message): print('%s %s -> %s: %s' % (message_id, srcName.strip(), dstName.strip(), content.replace('
', '\n'))) logging.info('%s %s -> %s: %s' % (message_id, srcName.strip(), dstName.strip(), content.replace('
', '\n'))) + return hot_package def handleMsg(self, r): for msg in r['AddMsgList']: @@ -789,22 +796,67 @@ def handleMsg(self, r): name = self.getUserRemarkName(msg['FromUserName']) content = msg['Content'].replace('<', '<').replace('>', '>') msgid = msg['MsgId'] +#自己加的代码-------------------------------------------# +#print("maze sync ok") +#每个人至多回复三句话 +#if name != "" +#self.list_name.append(name) +#print (self.list_name) + # if self.list_name.count(name) >= 8: + # break if msgType == 1: + ret = 0 + if name == "陌生人": + self.add_friend(msg['FromUserName'],2) + self.add_friend(msg['FromUserName'],3) + self.webwxgetcontact() + self.webwxsync() + self.webwxsendmsg("请问您需要什么资源呢?初次见面,还请您多多包涵。", msg['FromUserName']) + if "淘盟" in name: + break raw_msg = {'raw_msg': msg} self._showMsg(raw_msg) -#自己加的代码-------------------------------------------# #if self.autoReplyRevokeMode: # store -#自己加的代码-------------------------------------------# if self.autoReplyMode: - ans = self._xiaodoubi(content) + '\n[微信机器人自动回复]' - if self.webwxsendmsg(ans, msg['FromUserName']): - print('自动回复: ' + ans) - logging.info('自动回复: ' + ans) + #ans = self._simsimi(content) + '\n[微信机器人自动回复]' + #ans = self._xiaodoubi(content) + '\n[微信机器人自动回复]' +######################################### +#############add other movie resource +######################################### + if "摔跤" in content: + self.webwxsendmsg("http://pan.baidu.com/s/1midq9WO 密码:j2x6", msg['FromUserName']) + ret = 1 + elif "银河" in content: + self.webwxsendmsg("http://pan.baidu.com/s/1gfginoJ 密码: vyy1,", msg['FromUserName']) + elif "春娇救志明" in content: + self.webwxsendmsg("https://pan.baidu.com/s/1o8foioU 密码: rypp", msg['FromUserName']) + elif "喜欢你" in content: + self.webwxsendmsg("http://pan.baidu.com/s/1jHLJuC2 密码:cfjh", msg['FromUserName']) + elif "拆弹专家" in content: + self.webwxsendmsg("http://pan.baidu.com/s/1skGLvy9 密码:ew74", msg['FromUserName']) +######################################### +#############add other movie resource +######################################### + elif "谢谢" in content: + self.webwxsendmsg("不客气。", msg['FromUserName']) else: - print('自动回复失败') - logging.info('自动回复失败') + ans = self._tulin(content) + if ans != '': + if self.webwxsendmsg(ans, msg['FromUserName']): + print('自动回复: ' , ans) + logging.info('自动回复: ' , ans) + else: + print('自动回复失败') + logging.info('自动回复失败') + else: + pass + if ret == 1: + self.webwxsendmsg("如果资源您还满意,顺便发个小小的红包鼓励一下吧!", msg['FromUserName']) + time.sleep(1) + self.webwxsendmsg("请留我在您的通讯录里面,以便于与下一场热门电影不期而遇~有时间看看朋友圈。朋友圈代表最新收录", msg['FromUserName']) +#自己加的代码-------------------------------------------# elif msgType == 3: image = self.webwxgetmsgimg(msgid) raw_msg = {'raw_msg': msg, @@ -817,6 +869,7 @@ def handleMsg(self, r): 'message': '%s 发了一段语音: %s' % (name, voice)} self._showMsg(raw_msg) self._safe_open(voice) + self.webwxsendmsg("我现在不方便听语音", msg['FromUserName']) elif msgType == 42: info = msg['RecommendInfo'] print('%s 发送了一张名片:' % name) @@ -867,6 +920,11 @@ def handleMsg(self, r): raw_msg = {'raw_msg': msg, 'message': '%s 撤回了一条消息' % name} self._showMsg(raw_msg) else: + raw_msg = {'raw_msg': msg} + xyz = self._showMsg(raw_msg) + #print('maze in hot',xyz) + if xyz == 123: + self.webwxsendmsg("谢谢你的红包哦。么么哒。永远爱你", msg['FromUserName']) logging.debug('[*] 该消息类型为: %d,可能是表情,图片, 链接或红包: %s' % (msg['MsgType'], json.dumps(msg))) raw_msg = { @@ -882,6 +940,9 @@ def listenMsgMode(self): while True: self.lastCheckTs = time.time() [retcode, selector] = self.synccheck() + #print ('maze' , self.synccheck) + #print ('maze' , retcode) + #print ('maze' , selector) if self.DEBUG: print('retcode: %s, selector: %s' % (retcode, selector)) logging.debug('retcode: %s, selector: %s' % (retcode, selector)) @@ -898,16 +959,20 @@ def listenMsgMode(self): r = self.webwxsync() if r is not None: self.handleMsg(r) + elif selector == '3': + r = self.webwxsync() elif selector == '6': # TODO - redEnvelope += 1 - print('[*] 收到疑似红包消息 %d 次' % redEnvelope) - logging.debug('[*] 收到疑似红包消息 %d 次' % redEnvelope) - elif selector == '7': - playWeChat += 1 - print('[*] 你在手机上玩微信被我发现了 %d 次' % playWeChat) - logging.debug('[*] 你在手机上玩微信被我发现了 %d 次' % playWeChat) r = self.webwxsync() +# redEnvelope += 1 +# print('[*] 收到疑似红包消息 %d 次' % redEnvelope) +# logging.debug('[*] 收到疑似红包消息 %d 次' % redEnvelope) + elif selector == '7': + r = self.webwxsync() +# playWeChat += 1 +# print('[*] 你在手机上玩微信被我发现了 %d 次' % playWeChat) +# logging.debug('[*] 你在手机上玩微信被我发现了 %d 次' % playWeChat) +# r = self.webwxsync() elif selector == '0': time.sleep(1) if (time.time() - self.lastCheckTs) <= 20: @@ -1008,6 +1073,10 @@ def start(self): print('[*] 自动回复模式 ... 关闭') logging.debug('[*] 自动回复模式 ... 关闭') + if input('[*] 是否全员说话(y/n): ') == 'y': +#self.sendMsgToAll("由于有人恶意举报我分享的链接。现在摔跤吧爸爸链接已经失效。需要晚上才能有新的。抱歉。如果这种恶意举报次数多了。我将不再免费给大家分享了") + self.sendMsgToAll("新的链接已经给出,大家可以正常使用了") + if sys.platform.startswith('win'): import _thread _thread.start_new_thread(self.listenMsgMode()) @@ -1151,24 +1220,124 @@ def _post(self, url: object, params: object, jsonfmt: object = True) -> object: return '' - def _xiaodoubi(self, word): - url = 'http://www.xiaodoubi.com/bot/chat.php' - try: - r = requests.post(url, data={'chat': word}) - return r.content - except: - return "让我一个人静静 T_T..." - - def _simsimi(self, word): - key = '' - url = 'http://sandbox.api.simsimi.com/request.p?key=%s&lc=ch&ft=0.0&text=%s' % ( - key, word) - r = requests.get(url) - ans = r.json() - if ans['result'] == '100': - return ans['response'] - else: - return '你在说什么,风太大听不清列' +# def _xiaodoubi(self, word): +# #url = 'http://www.xiaodoubi.com/bot/chat.php' +# #onstant.BOT_TULING_BOT_REPLY +# # r = requests.post(url, data={'chat': word}) +# # return r.content +# #except: +# print (word) +# return word +# +# def _simsimi(self, word): +# key = '' +# url = 'http://sandbox.api.simsimi.com/request.p?key=%s&lc=ch&ft=0.0&text=%s' % ( +# key, word) +# r = requests.get(url) +# ans = r.json() +# if ans['result'] == '100': +# return ans['response'] +# else: +# return '你在说什么,风太大听不清列' +# + def _tulin(self, text): + EMOTICON = [ + '[Smile]', '[Grimace]', '[Drool]', '[Scowl]', '[CoolGuy]', '[Sob]', '[Shy]', + '[Silent]', '[Sleep]', '[Cry]', '[Awkward]', '[Angry]', '[Tongue]', '[Grin]', + '[Surprise]', '[Frown]', '[Ruthless]', '[Blush]', '[Scream]', '[Puke]', + '[Chuckle]', '[Joyful]', '[Slight]', '[Smug]', '[Hungry]', '[Drowsy]', '[Panic]', + '[Sweat]', '[Laugh]', '[Commando]', '[Determined]', '[Scold]', '[Shocked]', '[Shhh]', + '[Dizzy]', '[Tormented]', '[Toasted]', '[Skull]', '[Hammer]', '[Wave]', + '[Relief]', '[DigNose]', '[Clap]', '[Shame]', '[Trick]',' [Bah!L]','[Bah!R]', + '[Yawn]', '[Lookdown]', '[Wronged]', '[Puling]', '[Sly]', '[Kiss]', '[Uh-oh]', + '[Whimper]', '[Cleaver]', '[Melon]', '[Beer]', '[Basketball]', '[PingPong]', + '[Coffee]', '[Rice]', '[Pig]', '[Rose]', '[Wilt]', '[Lip]', '[Heart]', + '[BrokenHeart]', '[Cake]', '[Lightning]', '[Bomb]', '[Dagger]', '[Soccer]', '[Ladybug]', + '[Poop]', '[Moon]', '[Sun]', '[Gift]', '[Hug]', '[Strong]', + '[Weak]', '[Shake]', '[Victory]', '[Admire]', '[Beckon]', '[Fist]', '[Pinky]', + '[Love]', '[No]', '[OK]', '[InLove]', '[Blowkiss]', '[Waddle]', '[Tremble]', + '[Aaagh!]', '[Twirl]', '[Kotow]', '[Lookback]', '[Jump]', '[Give-in]', + u'\U0001f604', u'\U0001f637', u'\U0001f639', u'\U0001f61d', u'\U0001f632', u'\U0001f633', + u'\U0001f631', u'\U0001f64d', u'\U0001f609', u'\U0001f60c', u'\U0001f612', u'\U0001f47f', + u'\U0001f47b', u'\U0001f49d', u'\U0001f64f', u'\U0001f4aa', u'\U0001f4b5', u'\U0001f382', + u'\U0001f388', u'\U0001f4e6', + ] + BOT_TULING_API_KEY = '55e7f30895a0a10535984bae5ad294d1' + BOT_TULING_API_URL = 'http://www.tuling123.com/openapi/api?key=%s&info=%s&userid=%s' + BOT_TULING_BOT_REPLY = u'麻烦说的清楚一点,我听不懂你在说什么' + APIKEY = BOT_TULING_API_KEY + api_url = BOT_TULING_API_URL % (APIKEY, text, '12345678') + #print (api_url) + #r = json.loads(get(api_url)) + r = requests.get(api_url) + r = r.json() + if r.get('code') == 100000 and r.get('text') != BOT_TULING_BOT_REPLY: + p = random.randint(1, 10) + if p > 3: + return r['text'] + elif p > 1: + # send emoji + if random.randint(1, 10) > 5: + n = random.randint(0, len(EMOTICON)-1) + m = random.randint(1, 3) + reply = EMOTICON[n]* m + print('maze',EMOTICON[n]) + print('maze',EMOTICON[n].encode('utf-8')) + return reply + return '' + + def add_friend(self, userName, status=2, verifyContent='', autoUpdate=1): + #''' Add a friend or accept a friend + # * for adding status should be 2 + # * for accepting status should be 3 + #''' + url = '%s/webwxverifyuser?r=%s&pass_ticket=%s' % ( + self.base_uri, int(time.time()), self.pass_ticket) + print(url) + data = { + 'BaseRequest': self.BaseRequest, + 'Opcode': status, # 3 + 'VerifyUserListSize': 1, + 'VerifyUserList': [{ + 'Value': userName, + 'VerifyUserTicket': '', }], + 'VerifyContent': verifyContent, + 'SceneListCount': 1, + 'SceneList': [33], + 'skey': self.skey, } + headers = { + 'content-type': 'application/json; charset=UTF-8', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:42.0) Gecko/20100101 Firefox/42.0'} + r = requests.post(url, headers=headers, + data=json.dumps(data, ensure_ascii=False).encode('utf8', 'replace')) + print('maze_function add_friend') + if autoUpdate: + self.update_friend(userName) + #return ReturnValue(rawResponse=r) + + def update_friend(self, userName): + if not isinstance(userName, list): + userName = [userName] + url = '%s/webwxbatchgetcontact?type=ex&r=%s' % ( + self.base_uri, int(time.time())) + headers = { + 'content-type': 'application/json; charset=UTF-8', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:42.0) Gecko/20100101 Firefox/42.0'} + data = { + 'BaseRequest': self.BaseRequest, + 'Count': len(userName), + 'List': [{ + 'UserName': u, + 'EncryChatRoomId': '', } for u in userName], } + friendList = json.loads(requests.post(url, data=json.dumps(data), headers=headers + ).content.decode('utf8', 'replace')).get('ContactList') + + print('maze_funciton update_friend') +#update_local_friends(self, friendList) +# r = [self.storageClass.search_friends(userName=f['UserName']) +# for f in friendList] +# return r if len(r) != 1 else r[0] + def _searchContent(self, key, content, fmat='attr'): if fmat == 'attr': diff --git a/wxbot_project_py2.7/config/constant.py b/wxbot_project_py2.7/config/constant.py index f3aa544..1d842df 100644 --- a/wxbot_project_py2.7/config/constant.py +++ b/wxbot_project_py2.7/config/constant.py @@ -7,7 +7,9 @@ class Constant(object): @brief All used constants are listed here """ - WECHAT_CONFIG_FILE = 'config/wechat.conf' +#WECHAT_CONFIG_FILE = 'config/wechat.conf' +#D:\Nyeti\WeixinBot\wxbot_project_py2.7\config + WECHAT_CONFIG_FILE = './config/wechat.conf.bak' LOGGING_LOGGER_NAME = 'WeChat' QRCODE_BLACK = '\033[40m \033[0m' diff --git a/wxbot_project_py2.7/config/wechat.conf.bak b/wxbot_project_py2.7/config/wechat.conf.bak index 2dba3e0..b85f4a6 100644 --- a/wxbot_project_py2.7/config/wechat.conf.bak +++ b/wxbot_project_py2.7/config/wechat.conf.bak @@ -1,13 +1,14 @@ [wechat] host = wx.qq.com -uuid = -redirect_uri = -uin = -sid = -skey = -pass_ticket = -device_id = -last_login = +uuid = oapPDnJdxw== +redirect_uri = https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=ATulQQeCil-MWPTJRm5u6Nm0@qrticket_0&uuid=IeBciVJGKA==&lang=zh_CN&scan=1493261718&fun=new +uin = 958021414 +sid = l5x1dpMfwIoEIQ42 +skey = @crypt_61bd19cf_2b33b10fbd4e331e088189f588835130 +pass_ticket = bXeq47%2FO%2FeI6Zu2%2FkZVwR%2FdX4ou7uupJBUOM3fVwAT%2FQSwJWMzbYE0Ihrq7ZGMro +device_id = e654278747631844 +last_login = 1493261974.02 +synckey = 1_658451454|2_658451727|3_658451296|1000_1493253001 [setting] prefix = tmp_data/ diff --git a/wxbot_project_py2.7/wechat/__init__.py b/wxbot_project_py2.7/wechat/__init__.py index 1877c14..aa3b1e5 100644 --- a/wxbot_project_py2.7/wechat/__init__.py +++ b/wxbot_project_py2.7/wechat/__init__.py @@ -1,4 +1,5 @@ #!/usr/bin/env python # coding: utf-8 -from wechat import WeChat \ No newline at end of file +from wechat import WeChat +#from wechat import * diff --git a/wxbot_project_py2.7/wechat/wechat.py b/wxbot_project_py2.7/wechat/wechat.py index b68ab7f..661bd1e 100644 --- a/wxbot_project_py2.7/wechat/wechat.py +++ b/wxbot_project_py2.7/wechat/wechat.py @@ -149,13 +149,13 @@ def start(self): if self.msg_handler: self.msg_handler.check_schedule_task() - # if self.bot: - # r = self.bot.time_schedule() - # if r: - # for g in self.GroupList: - # echo('[*] 推送 -> %s: %s' % (g['NickName'], r)) - # g_id = g['UserName'] - # self.webwxsendmsg(r, g_id) + if self.bot: + r = self.bot.time_schedule() + if r: + for g in self.GroupList: + echo('[*] 推送 -> %s: %s' % (g['NickName'], r)) + g_id = g['UserName'] + self.webwxsendmsg(r, g_id) def get_run_time(self): """ diff --git a/wxbot_project_py2.7/wechat/wechat_apis.py b/wxbot_project_py2.7/wechat/wechat_apis.py index 6f02c42..069f0f5 100644 --- a/wxbot_project_py2.7/wechat/wechat_apis.py +++ b/wxbot_project_py2.7/wechat/wechat_apis.py @@ -203,6 +203,8 @@ def genqrcode(self): if data == '': return qrcode_path = save_file('qrcode.jpg', data, './') + qrcode_path = os.path.abspath(qrcode_path) + print(qrcode_path) os.startfile(qrcode_path) else: str2qr_terminal(self.wx_conf['API_qrcode'] + self.uuid) diff --git a/wxbot_project_py2.7/weixin_bot.py b/wxbot_project_py2.7/weixin_bot.py index 96bb745..d9d0ed6 100755 --- a/wxbot_project_py2.7/weixin_bot.py +++ b/wxbot_project_py2.7/weixin_bot.py @@ -2,6 +2,7 @@ # coding: utf-8 #=================================================== +#from wechat import * from wechat import WeChat from wechat.utils import * from wx_handler import WeChatMsgProcessor diff --git a/wxbot_project_py2.7/wx_handler/wechat_msg_processor.py b/wxbot_project_py2.7/wx_handler/wechat_msg_processor.py index d70f54b..de0be14 100644 --- a/wxbot_project_py2.7/wx_handler/wechat_msg_processor.py +++ b/wxbot_project_py2.7/wx_handler/wechat_msg_processor.py @@ -218,12 +218,12 @@ def handle_command(self, cmd, msg): else: # reply bot # --------- - # if wechat.bot: - # r = wechat.bot.reply(cmd) - # if r: - # wechat.webwxsendmsg(r, g_id) - # else: - # pass + if wechat.bot: + r = wechat.bot.reply(cmd) + if r: + wechat.webwxsendmsg(r, g_id) + else: + pass img_name = [ '0.jpg', '1.jpeg', '2.gif', '3.jpg', '4.jpeg', '5.gif', '6.gif', '7.gif', '8.jpg', '9.jpg'