Пример #1
0
def webwxinit(wxWeb):
    """
    微信登陆初始化
    获取联系人信息,得到当前用户信息
    """
    # 组织请求url及数据
    view = 'webwxinit'
    query_params = dict(pass_ticket=wxWeb.pass_ticket,
                        skey=wxWeb.skey,
                        r=int(time.time()))
    params = {'BaseRequest': wxWeb.BaseRequest}

    # 调用
    data, data_unicode = url_invoke(wxWeb.base_uri, view, query_params, params)

    if DEBUG:
        f = open(os.path.join(os.getcwd(), 'webwxinit.json'), 'wb')
        f.write(data)
        f.close()

    # 转换json
    dic = json.loads(data_unicode)

    state = responseState('webwxinit', dic['BaseResponse'])

    wxWeb.My = dic['User']
    wxWeb.syncKey = dic['SyncKey']
    wxWeb.ContactList = dic['ContactList']
    return state
Пример #2
0
    def verifyUser(self, UserList, verify_info):
        """
        同时发送多个添加好友
        """
        # 组织url结构
        print("开始请求添加群组里好友")
        def generate_user(uList):
            _u_list = []
            for user in uList:
                d = {"Value": user["UserName"], "VerifyUserTicket": ""}
                _u_list.append(d)
            return _u_list

        _u_list = generate_user(UserList)

        view = 'webwxverifyuser'
        query_params = dict(r=int(time.time()), pass_ticket=self.pass_ticket)
        for u in _u_list:
            params = {
                "BaseRequest": self.BaseRequest,
                "Opcode": 2,
                "SceneList": [33],
                "SceneListCount": 1,
                "VerifyContent": verify_info,
                "VerifyUserList": u,
                "VerifyUserTicket": "",
                "VerifyUserListSize": 1,
                "skey": self.skey
            }
            # 调用
            data, data_unicode = url_invoke(self.base_uri, view, query_params, params, ensure_ascii=False)
            print data, 'dattttt'
            dic = json.loads(data_unicode)
            r = random.randint(2, 5)
            time.sleep(r)
Пример #3
0
    def webwxgetcontact(self):
        # 组织url数据结构
        view = 'webwxgetcontact'
        query_params = dict(pass_ticket=self.pass_ticket, skey=self.skey, r=int(time.time()))    
        params = {
            'BaseRequest': self.BaseRequest
        }
        # 调用
        data, data_unicode = url_invoke(self.base_uri, view, query_params, params)

        if DEBUG:
            f = open(os.path.join(os.getcwd(), 'webwxgetcontact.json'), 'wb')
            f.write(data)
            f.close()
     
        dic = json.loads(data_unicode)
        MemberList = dic['MemberList']
     
        # 倒序遍历,不然删除的时候出问题..
        SpecialUsers = ["newsapp", "fmessage", "filehelper", "weibo", "qqmail", "tmessage", "qmessage", "qqsync", "floatbottle", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp", "masssendapp",
                        "meishiapp", "feedsapp", "voip", "blogappweixin", "weixin", "brandsessionholder", "weixinreminder", "wxid_novlwrv3lqwv11", "gh_22b87fa7cb3c", "officialaccounts", "notification_messages", "wxitil", "userexperience_alarm"]

        temp_list =[]
        for i in range(len(MemberList) - 1, -1, -1):
            Member = MemberList[i]
            if Member['VerifyFlag'] & 8 != 0:  # 公众号/服务号
                MemberList.remove(Member)
            elif Member['UserName'] in SpecialUsers:  # 特殊账号
                MemberList.remove(Member)
            elif Member['UserName'] == self.My['UserName']:  # 自己
                MemberList.remove(Member)
        return MemberList
Пример #4
0
    def webwxUploadMedia(self, toUserName, upload_media=None):
        """
        上传文件
        """
        # 注册流句柄 wdf_urllib.bind()
        print("开始上传!")
        register_openers()
        # TODO: 参数化
        path = "/Users/admin/Desktop/timg.jpeg"
        view = 'webwxuploadmedia'
        w = open(path, "rb")
        filemd5 = hashlib.md5()
        f = w.read()
        filemd5.update(f)
        w.seek(0)
        md5 = filemd5.hexdigest()
        size = os.path.getsize(path)
        
        t = (("uploadmediarequest", json.dumps({"UploadType": 2, "BaseRequest": self.BaseRequest, "ClientMediaId": int(time.time()), "TotalLen": size, "StartPos": 0, "DataLen": size, "MediaType": 4, 
            "FromUserName": self.My["UserName"], "ToUserName": toUserName, "FileMd5": md5})), ("webwx_data_ticket", self.data_ticket), ("pass_ticket", self.pass_ticket), ("filename", w))

        datagen, headers = multipart_encode(t, boundary=self.boundary)
        query_params = dict(f='json')
       
        data, data_unicode = url_invoke(self.upload_uri, view, query_params, params=datagen, headers=headers, media=True)
        w.close()

        if DEBUG:
            f = open(os.path.join(os.getcwd(), 'uploadmedia.json'), 'wb')
            f.write(data)
            f.close()
        dic = json.loads(data_unicode)
        return dic, toUserName
Пример #5
0
    def sendMedia(self, media_dic, toUserName):
        """
        发送文件
        """
        # 组织url结构
        view = 'webwxsendmsgimg'
        query_params = {
            "fun": "async",
            "f": "json",
            "lang": "zh_CN",
            "pass_ticket": self.pass_ticket
        }
        _now_time = int(time.time())
        msg = dict(
                ClientMsgId=_now_time,
                FromUserName=self.My["UserName"],
                LocalID=_now_time,
                MediaId=media_dic['MediaId'],
                ToUserName=toUserName,
                Type=3,
            )
        params = {
            'BaseRequest': self.BaseRequest,
            'Msg': msg,
            'Scene': 0,
        }

        # 请求
        data, data_unicode = url_invoke(self.base_uri, view, query_params, params)
        dic = json.loads(data_unicode)
Пример #6
0
    def sendMedia(self, media_dic, toUserName):
        """
        发送文件
        """
        # 组织url结构
        view = 'webwxsendmsgimg'
        query_params = {
            "fun": "async",
            "f": "json",
            "lang": "zh_CN",
            "pass_ticket": self.pass_ticket
        }
        _now_time = int(time.time())
        msg = dict(
            ClientMsgId=_now_time,
            FromUserName=self.My["UserName"],
            LocalID=_now_time,
            MediaId=media_dic['MediaId'],
            ToUserName=toUserName,
            Type=3,
        )
        params = {
            'BaseRequest': self.BaseRequest,
            'Msg': msg,
            'Scene': 0,
        }

        # 请求
        data, data_unicode = url_invoke(self.base_uri, view, query_params,
                                        params)
        dic = json.loads(data_unicode)
Пример #7
0
    def do_send_msg(self, toUserName, message):
        # 组织url数据
        _now_time = int(time.time())
        msg = dict(ClientMsgId=_now_time,
                   Content=message,
                   FromUserName=self.My["UserName"],
                   LocalID=_now_time,
                   ToUserName=toUserName,
                   Type=1)
        print msg, 'msg'
        view = 'webwxsendmsg'
        query_params = dict(lang='zh_CN', pass_ticket=self.pass_ticket)
        params = {
            'BaseRequest': self.BaseRequest,
            'Msg': msg,
            'Scene': 0,
        }

        # 调用
        data, data_unicode = url_invoke(self.base_uri,
                                        view,
                                        query_params,
                                        params=params,
                                        ensure_ascii=False)
        print data, 'data'
        dic = json.loads(data_unicode)
Пример #8
0
def webwxinit(wxWeb):
    """
    微信登陆初始化
    获取联系人信息,得到当前用户信息
    """
    # 组织请求url及数据
    view = 'webwxinit'
    query_params = dict(pass_ticket=wxWeb.pass_ticket, skey=wxWeb.skey, r=int(time.time()))    
    params = {
        'BaseRequest': wxWeb.BaseRequest
    }

    # 调用
    data, data_unicode = url_invoke(wxWeb.base_uri, view, query_params, params)
 
    if DEBUG:
        f = open(os.path.join(os.getcwd(), 'webwxinit.json'), 'wb')
        f.write(data)
        f.close()
        
    # 转换json
    dic = json.loads(data_unicode)

    state = responseState('webwxinit', dic['BaseResponse'])

    wxWeb.My = dic['User']
    wxWeb.syncKey = dic['SyncKey']
    wxWeb.ContactList = dic['ContactList']
    return state
Пример #9
0
def webwxsync(wxWeb):
    # 组织url数据
    view = 'webwxsync'
    query_params = dict(
            lang='zh_CN',
            skey=wxWeb.skey,
            sid=wxWeb.wxsid,
            pass_ticket=quote_plus(wxWeb.pass_ticket)
        )
    params = {
        'BaseRequest': wxWeb.BaseRequest,
        'SyncKey': wxWeb.syncKey,
        'rr': ~int(time.time()),
    }
    # 调用
    data, data_unicode = url_invoke(wxWeb.base_uri, view, query_params, params)
    #print(data, '########')
 
    # print(data)
 
    dic = json.loads(data_unicode)
    wxWeb.syncKey = dic['SyncKey']
 
    state = responseState('webwxsync', dic['BaseResponse'])
    return state
Пример #10
0
    def webwxUploadMedia(self, toUserName, upload_media=None):
        """
        上传文件
        """
        # 注册流句柄 wdf_urllib.bind()
        print("开始上传!")
        register_openers()
        # TODO: 参数化
        path = "/Users/admin/Desktop/timg.jpeg"
        view = 'webwxuploadmedia'
        w = open(path, "rb")
        filemd5 = hashlib.md5()
        f = w.read()
        filemd5.update(f)
        w.seek(0)
        md5 = filemd5.hexdigest()
        size = os.path.getsize(path)

        t = (("uploadmediarequest",
              json.dumps({
                  "UploadType": 2,
                  "BaseRequest": self.BaseRequest,
                  "ClientMediaId": int(time.time()),
                  "TotalLen": size,
                  "StartPos": 0,
                  "DataLen": size,
                  "MediaType": 4,
                  "FromUserName": self.My["UserName"],
                  "ToUserName": toUserName,
                  "FileMd5": md5
              })), ("webwx_data_ticket", self.data_ticket),
             ("pass_ticket", self.pass_ticket), ("filename", w))

        datagen, headers = multipart_encode(t, boundary=self.boundary)
        query_params = dict(f='json')

        data, data_unicode = url_invoke(self.upload_uri,
                                        view,
                                        query_params,
                                        params=datagen,
                                        headers=headers,
                                        media=True)
        w.close()

        if DEBUG:
            f = open(os.path.join(os.getcwd(), 'uploadmedia.json'), 'wb')
            f.write(data)
            f.close()
        dic = json.loads(data_unicode)
        return dic, toUserName
Пример #11
0
    def webwxgetcontact(self):
        # 组织url数据结构
        view = 'webwxgetcontact'
        query_params = dict(pass_ticket=self.pass_ticket,
                            skey=self.skey,
                            r=int(time.time()))
        params = {'BaseRequest': self.BaseRequest}
        # 调用
        data, data_unicode = url_invoke(self.base_uri, view, query_params,
                                        params)

        if DEBUG:
            f = open(os.path.join(os.getcwd(), 'webwxgetcontact.json'), 'wb')
            f.write(data)
            f.close()

        dic = json.loads(data_unicode)
        MemberList = dic['MemberList']

        # 倒序遍历,不然删除的时候出问题..
        SpecialUsers = [
            "newsapp", "fmessage", "filehelper", "weibo", "qqmail", "tmessage",
            "qmessage", "qqsync", "floatbottle", "lbsapp", "shakeapp",
            "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp",
            "masssendapp", "meishiapp", "feedsapp", "voip", "blogappweixin",
            "weixin", "brandsessionholder", "weixinreminder",
            "wxid_novlwrv3lqwv11", "gh_22b87fa7cb3c", "officialaccounts",
            "notification_messages", "wxitil", "userexperience_alarm"
        ]

        temp_list = []
        for i in range(len(MemberList) - 1, -1, -1):
            Member = MemberList[i]
            if Member['VerifyFlag'] & 8 != 0:  # 公众号/服务号
                MemberList.remove(Member)
            elif Member['UserName'] in SpecialUsers:  # 特殊账号
                MemberList.remove(Member)
            elif Member['UserName'] == self.My['UserName']:  # 自己
                MemberList.remove(Member)
        return MemberList
Пример #12
0
    def verifyUser(self, UserList, verify_info):
        """
        同时发送多个添加好友
        """
        # 组织url结构
        print("开始请求添加群组里好友")

        def generate_user(uList):
            _u_list = []
            for user in uList:
                d = {"Value": user["UserName"], "VerifyUserTicket": ""}
                _u_list.append(d)
            return _u_list

        _u_list = generate_user(UserList)

        view = 'webwxverifyuser'
        query_params = dict(r=int(time.time()), pass_ticket=self.pass_ticket)
        for u in _u_list:
            params = {
                "BaseRequest": self.BaseRequest,
                "Opcode": 2,
                "SceneList": [33],
                "SceneListCount": 1,
                "VerifyContent": verify_info,
                "VerifyUserList": u,
                "VerifyUserTicket": "",
                "VerifyUserListSize": 1,
                "skey": self.skey
            }
            # 调用
            data, data_unicode = url_invoke(self.base_uri,
                                            view,
                                            query_params,
                                            params,
                                            ensure_ascii=False)
            print data, 'dattttt'
            dic = json.loads(data_unicode)
            r = random.randint(2, 5)
            time.sleep(r)
Пример #13
0
def webwxsync(wxWeb):
    # 组织url数据
    view = 'webwxsync'
    query_params = dict(lang='zh_CN',
                        skey=wxWeb.skey,
                        sid=wxWeb.wxsid,
                        pass_ticket=quote_plus(wxWeb.pass_ticket))
    params = {
        'BaseRequest': wxWeb.BaseRequest,
        'SyncKey': wxWeb.syncKey,
        'rr': ~int(time.time()),
    }
    # 调用
    data, data_unicode = url_invoke(wxWeb.base_uri, view, query_params, params)
    #print(data, '########')

    # print(data)

    dic = json.loads(data_unicode)
    wxWeb.syncKey = dic['SyncKey']

    state = responseState('webwxsync', dic['BaseResponse'])
    return state
Пример #14
0
def syncCheck(wxWeb):
    view = 'synccheck'
    query_params = {
        'skey': wxWeb.BaseRequest['Skey'],
        'sid': wxWeb.BaseRequest['Sid'],
        'uin': wxWeb.BaseRequest['Uin'],
        'deviceId': wxWeb.BaseRequest['DeviceID'],
        'synckey': syncKey(wxWeb),
        'r': int(time.time()),
    }

    data, data_unicode = url_invoke(wxWeb.push_uri, view, query_params)

    # print(data)

    # window.synccheck={retcode:"0",selector:"2"}
    regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
    pm = re.search(regx, data_unicode)

    retcode = pm.group(1)
    selector = pm.group(2)

    return selector
Пример #15
0
def syncCheck(wxWeb):
    view = 'synccheck'
    query_params = {
        'skey': wxWeb.BaseRequest['Skey'],
        'sid': wxWeb.BaseRequest['Sid'],
        'uin': wxWeb.BaseRequest['Uin'],
        'deviceId': wxWeb.BaseRequest['DeviceID'],
        'synckey': syncKey(wxWeb),
        'r': int(time.time()),
    }
 
    data, data_unicode = url_invoke(wxWeb.push_uri, view, query_params)
 
    # print(data)
 
    # window.synccheck={retcode:"0",selector:"2"}
    regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
    pm = re.search(regx, data_unicode)
 
    retcode = pm.group(1)
    selector = pm.group(2)
 
    return selector
Пример #16
0
 def do_send_msg(self, toUserName, message):
     # 组织url数据
     _now_time = int(time.time())
     msg = dict(
             ClientMsgId=_now_time,
             Content=message,
             FromUserName=self.My["UserName"],
             LocalID=_now_time,
             ToUserName=toUserName,
             Type=1
         )
     print msg, 'msg'
     view = 'webwxsendmsg'
     query_params = dict(lang='zh_CN', pass_ticket=self.pass_ticket)
     params = {
         'BaseRequest': self.BaseRequest,
         'Msg': msg,
         'Scene': 0,
     }
     
     # 调用
     data, data_unicode = url_invoke(self.base_uri, view, query_params, params=params, ensure_ascii=False)
     print data, 'data'
     dic = json.loads(data_unicode)