Example #1
0
def weather_time():
    """定时任务,一天拉取一次天气m信息,检测是否有报警天气"""
    time.sleep(6 * 60 * 60)
    rlt_cur = db_read.get_all_baseinfo()
    for info in rlt_cur:
        city = info[2]
        wx_user_id = info[1]
        msg = weather.get_weather(city, only_today=False)
        itchat.send_raw_msg(1, rsp_msg + "^(* ̄(oo) ̄)^", wx_user_id)
Example #2
0
def send_weixin_msg(msg, group_id, file_name=None):
    if msg['Type'] in [TEXT]:
        out = itchat.send_raw_msg(msg['MsgType'], msg['Content'], group_id)
        #time.sleep(5)
    elif msg['Type'] in [PICTURE, ATTACHMENT, VIDEO, RECORDING]:
        out = itchat.send('@%s@%s' % ({'Picture': 'img', 'Video': 'vid'}.get(
            msg['Type'], 'fil'), file_name), group_id)
        #time.sleep(10)
    else:
        print("%s message do not support!" % msg['Type'])
        out = {'BaseResponse': {'Ret': 0, 'ErrMsg': '', 'RawMsg': ''}}
    return out
Example #3
0
    def Send_Msg(self,
                 usrID,
                 usrName="",
                 msgInfo="",
                 typeMsg="TEXT",
                 typeUser=0):
        #用户检测(@开头为用户名,filehelper,其他需要检索实际用户名)
        userName = usrName
        if (usrID == None): usrID = ""
        if (userName != "filehelper"):
            if (typeUser == 0):
                pUser = self.Get_User(usrID, usrName)
            else:
                pUser = self.Get_User_group(usrID, usrName)
            userName = pUser['UserName']
            if (userName == ""): return

        #发送消息
        typeMsg = typeMsg.upper()
        if (typeMsg == "TEXT"):
            itchat.send('%s' % (msgInfo), userName)
        elif (typeMsg == "IMAGE"):
            itchat.send_image(msgInfo, userName)
            if (os.path.exists(msgInfo) == False):
                myDebug.Error("No this Image" + msgInfo + ".")
        elif (typeMsg == "FILE"):
            itchat.send_file(msgInfo, userName)
            if (os.path.exists(msgInfo) == False):
                myDebug.Error("No this File" + msgInfo + ".")
        elif (typeMsg == "VIDEO"):
            itchat.send_video(msgInfo, userName)
            if (os.path.exists(msgInfo) == False):
                myDebug.Error("No this File" + msgInfo + ".")
        elif (typeMsg == "CARD1"):  #未实现
            Content = "<?xml version=\"1.0\"?>\n<msg bigheadimgurl=\"http://wx.qlogo.cn/mmhead/ver_1/UuYfjibTFM2RFQsy5hvdojN8qeSqghGeONUBib34ucEWpztQOM18xFicVYK02lfNYLFdiaYZww71H6oDgiaBPhVm9vCgXXB1bP9XoPgE8jOibJcko/0\" smallheadimgurl=\"http://wx.qlogo.cn/mmhead/ver_1/UuYfjibTFM2RFQsy5hvdojN8qeSqghGeONUBib34ucEWpztQOM18xFicVYK02lfNYLFdiaYZww71H6oDgiaBPhVm9vCgXXB1bP9XoPgE8jOibJcko/132\" username=\"v1_cd9b652b5b54d225963c03833cef2f27e2a1e7b9b55f5659ac9210eb315cca20@stranger\" nickname=\"MlNA\"  shortpy=\"MLNA\" alias=\"\" imagestatus=\"3\" scene=\"17\" province=\"广东\" city=\"广州\" sign=\"\" sex=\"2\" certflag=\"0\" certinfo=\"\" brandIconUrl=\"\" brandHomeUrl=\"\" brandSubscriptConfigUrl=\"\" brandFlags=\"0\" regionCode=\"CN_Guangdong_Guangzhou\" antispamticket=\"v2_2ced7b6604ee323f392d80574d0de3db9f4b52048d9bb0a3c231dc36f9285c02212ad1a52bcf0968b17bde1e4d8c167a153b52d5b9ff638a1cdf560d5f9d5e1a014792f12a7a6189768f049d47ca18ebb66e0bc34578bef58ce3602817a355f07c891384ee03a11f5639f39ba61ccac48bdaeaf0e3ebf06b707af8c6328d3de5834a7a89f03601ae0bc8fb5d0e8216acd0d50b8bd8e3fac6c9dad59253b829f74688d6fa701259f7ded3a108304cd7cd@stranger\" />\n"
            itchat.send_raw_msg(42, Content, userName)
            '''
                MsgType: 42
    FromUserName: 发送方ID
    ToUserName: 接收方ID
    Content:
        <?xml version="1.0"?>
        <msg bigheadimgurl="" smallheadimgurl="" username="" nickname=""  shortpy="" alias="" imagestatus="3" scene="17" province="" city="" sign="" sex="1" certflag="0" certinfo="" brandIconUrl="" brandHomeUrl="" brandSubscriptConfigUrl="" brandFlags="0" regionCode="" />
    RecommendInfo:
        {
            "UserName": "******", # ID
            "Province": "xxx",
            "City": "xxx",
            "Scene": 17,
            "QQNum": 0,
            "Content": "",
            "Alias": "xxx", # 微信号
            "OpCode": 0,
            "Signature": "",
            "Ticket": "",
            "Sex": 0, # 1:男, 2:女
            "NickName": "xxx", # 昵称
            "AttrStatus": 4293221,
            "VerifyFlag": 0
        }
        '''
        elif (typeMsg == "SHARING1"):  #未实现
            Content = '<?xml version="1.0"?>\n<msg>\n\t<appmsg appid="" sdkver="0">\n\t\t<title>【生活·吃·01】叹茶,一盅两件!曾经,我们插肩而过。10年后的重逢,才发现,你是这样的广式早茶!</title>\n\t\t<des>为名忙,为利忙,忙里偷闲,饮杯茶去;劳心苦,劳力苦,苦中作乐,拿壶酒来。</des>\n\t\t<username />\n\t\t<action>view</action>\n\t\t<type>5</type>\n\t\t<showtype>0</showtype>\n\t\t<content />\n\t\t<url>http://mp.weixin.qq.com/s?__biz=MzAxMDQ3MTk4Nw==&amp;mid=2247483741&amp;idx=1&amp;sn=8fb62dd901ca3f1eb1a89566af3abb53&amp;chksm=9b4e9e01ac391717ed0c9d726f7a66d2d7ce1e84aa052995997cabf21fb6db96040a60747062&amp;mpshare=1&amp;scene=1&amp;srcid=&amp;sharer_sharetime=1575551329214&amp;sharer_shareid=d369241c24472101fffbbbe1df71790e#rd</url>\n\t\t<lowurl />\n\t\t<dataurl />\n\t\t<lowdataurl />\n\t\t<contentattr>0</contentattr>\n\t\t<streamvideo>\n\t\t\t<streamvideourl />\n\t\t\t<streamvideototaltime>0</streamvideototaltime>\n\t\t\t<streamvideotitle />\n\t\t\t<streamvideowording />\n\t\t\t<streamvideoweburl />\n\t\t\t<streamvideothumburl />\n\t\t\t<streamvideoaduxinfo />\n\t\t\t<streamvideopublishid />\n\t\t</streamvideo>\n\t\t<canvasPageItem>\n\t\t\t<canvasPageXml><![CDATA[]]></canvasPageXml>\n\t\t</canvasPageItem>\n\t\t<appattach>\n\t\t\t<attachid />\n\t\t\t<cdnthumburl>305d0201000456305402010002044a17792502033d11fe020432f516d202045de90173042f6175706170706d73675f303961666430663738306163343663375f313537353535313334363837375f3236343734320204010400030201000400</cdnthumburl>\n\t\t\t<cdnthumbmd5>36cca8f5a144a3ef508a2d041b17237e</cdnthumbmd5>\n\t\t\t<cdnthumblength>32522</cdnthumblength>\n\t\t\t<cdnthumbheight>120</cdnthumbheight>\n\t\t\t<cdnthumbwidth>120</cdnthumbwidth>\n\t\t\t<cdnthumbaeskey>a8ff2b1290888ee1aa0653469b609ab8</cdnthumbaeskey>\n\t\t\t<aeskey>a8ff2b1290888ee1aa0653469b609ab8</aeskey>\n\t\t\t<encryver>1</encryver>\n\t\t\t<fileext />\n\t\t\t<islargefilemsg>0</islargefilemsg>\n\t\t</appattach>\n\t\t<extinfo />\n\t\t<androidsource>3</androidsource>\n\t\t<sourceusername></sourceusername>\n\t\t<sourcedisplayname>简易生活号</sourcedisplayname>\n\t\t<commenturl />\n\t\t<thumburl />\n\t\t<mediatagname />\n\t\t<messageaction><![CDATA[]]></messageaction>\n\t\t<messageext><![CDATA[]]></messageext>\n\t\t<emoticongift>\n\t\t\t<packageflag>0</packageflag>\n\t\t\t<packageid />\n\t\t</emoticongift>\n\t\t<emoticonshared>\n\t\t\t<packageflag>0</packageflag>\n\t\t\t<packageid />\n\t\t</emoticonshared>\n\t\t<designershared>\n\t\t\t<designeruin>0</designeruin>\n\t\t\t<designername>null</designername>\n\t\t\t<designerrediretcturl>null</designerrediretcturl>\n\t\t</designershared>\n\t\t<emotionpageshared>\n\t\t\t<tid>0</tid>\n\t\t\t<title>null</title>\n\t\t\t<desc>null</desc>\n\t\t\t<iconUrl>null</iconUrl>\n\t\t\t<secondUrl>null</secondUrl>\n\t\t\t<pageType>0</pageType>\n\t\t</emotionpageshared>\n\t\t<webviewshared>\n\t\t\t<shareUrlOriginal>http://mp.weixin.qq.com/s?__biz=MzAxMDQ3MTk4Nw==&amp;mid=2247483741&amp;idx=1&amp;sn=8fb62dd901ca3f1eb1a89566af3abb53&amp;chksm=9b4e9e01ac391717ed0c9d726f7a66d2d7ce1e84aa052995997cabf21fb6db96040a60747062&amp;scene=0&amp;xtrack=1&amp;clicktime=1575551321&amp;enterid=1575551321#rd</shareUrlOriginal>\n\t\t\t<shareUrlOpen>https://mp.weixin.qq.com/s?__biz=MzAxMDQ3MTk4Nw==&amp;mid=2247483741&amp;idx=1&amp;sn=8fb62dd901ca3f1eb1a89566af3abb53&amp;chksm=9b4e9e01ac391717ed0c9d726f7a66d2d7ce1e84aa052995997cabf21fb6db96040a60747062&amp;scene=0&amp;xtrack=1&amp;clicktime=1575551321&amp;enterid=1575551321&amp;ascene=7&amp;devicetype=android-27&amp;version=27000934&amp;nettype=WIFI&amp;abtest_cookie=AAACAA%3D%3D&amp;lang=zh_CN&amp;exportkey=AUVRoLcGAshgpownvyOek%2Bg%3D&amp;pass_ticket=H3X23ZwHOD05zFxqyys3F3YWCRWy5%2BRN%2B%2BFoP3lJfZW6PrO5vamVdlYXLm4XlGv2&amp;wx_header=1</shareUrlOpen>\n\t\t\t<jsAppId />\n\t\t\t<publisherId>msg_8659705440921183578</publisherId>\n\t\t</webviewshared>\n\t\t<template_id />\n\t\t<md5>36cca8f5a144a3ef508a2d041b17237e</md5>\n\t\t<weappinfo>\n\t\t\t<username />\n\t\t\t<appid />\n\t\t\t<appservicetype>0</appservicetype>\n\t\t\t<videopageinfo>\n\t\t\t\t<thumbwidth>120</thumbwidth>\n\t\t\t\t<thumbheight>120</thumbheight>\n\t\t\t\t<fromopensdk>0</fromopensdk>\n\t\t\t</videopageinfo>\n\t\t</weappinfo>\n\t\t<statextstr />\n\t\t<mmreadershare>\n\t\t\t<itemshowtype>0</itemshowtype>\n\t\t</mmreadershare>\n\t\t<directshare>0</directshare>\n\t\t<websearch>\n\t\t\t<rec_category>0</rec_category>\n\t\t\t<channelId>0</channelId>\n\t\t</websearch>\n\t</appmsg>\n\t<fromusername></fromusername>\n\t<scene>0</scene>\n\t<appinfo>\n\t\t<version>1</version>\n\t\t<appname></appname>\n\t</appinfo>\n\t<commenturl></commenturl>\n</msg>\n'
            params = {
                "AppMsgType": 5,
                "Url":
                'http://mp.weixin.qq.com/s?__biz=MzAxMDQ3MTk4Nw==&amp;mid=2247483741&amp;idx=1&amp;sn=8fb62dd901ca3f1eb1a89566af3abb53&amp;chksm=9b4e9e01ac391717ed0c9d726f7a66d2d7ce1e84aa052995997cabf21fb6db96040a60747062&amp;mpshare=1&amp;scene=1&amp;srcid=&amp;sharer_sharetime=1575551329214&amp;sharer_shareid=d369241c24472101fffbbbe1df71790e#rd',
                "FileName": "【生活·吃·01】叹茶,一盅两件!........"
            }
            itchat.send_raw_msg(49, Content, userName, params)
        else:
            myDebug.Print("No this type.")
            return False
        return True
Example #4
0
def text_reply(msg):
    """回复他人消息"""
    global ACTIVE_SIGN
    global MEID
    LOGGER.write_dict2json(msg)
    user_name = msg["FromUserName"]
    rsp_msg = ''
    if "猪头是我我是猪头" in msg.text:
        MEID = msg["FromUserName"]
    if "猪头" in msg.text and not actived(msg["FromUserName"]):
        ACTIVE_SIGN[msg["FromUserName"]] = 1
        rsp_msg = "hHi~ o(* ̄▽ ̄*)ブ  我是猪头."
    if ("再见" in msg.text or "拜" in msg.text or "bye" in msg.text or "退"
            in msg.text or "下" in msg.text) and actived(msg["FromUserName"]):
        ACTIVE_SIGN[msg["FromUserName"]] = 0
        rsp_msg = "ヾ( ̄▽ ̄)Bye~Bye~, 猪头会乖乖的."

    if "图" in msg.text and actived(msg["FromUserName"]) == 1:
        if "的" in msg.text:
            image_key = msg.text.split("的")[0]
        else:
            image_key = msg.text.split("图")[0]
        sign = crawl_image(image_key, 1)
        file_path = f'/home/ubuntu/misaka_back/donwload/crawl_image/{image_key}/'
        if sign:
            for i in range(1):
                file_name = os.listdir(file_path)[i]
                file_path = f'{file_path}{file_name}'
                itchat.send_image(file_path, msg["FromUserName"])
    if "天气" in msg.text and actived(user_name):
        if "的" in msg.text:
            city_name = msg.text.split("的")[0]
        else:
            city_name = msg.text.split("天气")[0]
        if not city_name or not weather.get_city_id(city_name):
            city_name = msg["User"]["City"]
        rsp_msg = weather.get_weather(city_name)
    if "在哪儿" in msg.text and actived(user_name):
        all_nickname = db_read.get_all_nickname()
        for nickname in all_nickname.keys():
            if nickname in msg.text:
                break
            else:
                nickname = ''
        if not nickname:
            wx_user_id = msg["ToUserName"]
            base_info = db_read.get_base_info(wx_user_id=wx_user_id)
            nickname = base_info.get("nickname") or ''
        city = all_nickname[nickname].get("city")
        rsp_msg = f'{nickname}在{city}呢.'
    if (msg.text[0] == '"' and msg.text[-1] == '"') or (
            msg.text[0] == '“' and msg.text[-1] == '”') and actived(user_name):
        words = msg.text[1:-1]
        rsp_msg = ''
        if len(words) == 1:
            info_ = chinese_xinhua_dict.get_word(words)
        elif len(words) > 1:
            info_ = chinese_xinhua_dict.get_words(words)
        else:
            info_ = chinese_xinhua_dict.get_words("沉默")
        if info_:
            rsp_msg = json.dumps(info_,
                                 ensure_ascii=False,
                                 sort_keys=True,
                                 indent=4)
        rsp_msg = rsp_msg or ''

    if (user_name == MEID and "^(* ̄(oo) ̄)^" not in rsp_msg
            and actived(user_name)):
        itchat.send_raw_msg(msg['MsgType'], rsp_msg + "^(* ̄(oo) ̄)^",
                            msg['ToUserName'])
        rsp_msg = ''

    return rsp_msg
Example #5
0
def share(msg):
    itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])
Example #6
0
import itchat, time, sys


import itchat

c = itchat.auto_login()
# def send(self, msg, toUserName=None, mediaId=None)
print c
r = itchat.send_msg(msg='succeed!', toUserName='******')
print r
r2 = itchat.send_raw_msg(msgType=1, content='123', toUserName='******')
print r2