{"action":"opened","issue":{"url":"https://api.github.com/repos/Urinx/WeixinBot/issues/202","repository_url":"https://api.github.com/repos/Urinx/WeixinBot","labels_url":"https://api.github.com/repos/Urinx/WeixinBot/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/Urinx/WeixinBot/issues/202/comments","events_url":"https://api.github.com/repos/Urinx/WeixinBot/issues/202/events","html_url":"https://github.com/Urinx/WeixinBot/issues/202","id":230918411,"number":202,"title":"关于发送视频会失败的一个解决方法","user":{"login":"fangfsz","id":19644061,"avatar_url":"https://avatars1.githubusercontent.com/u/19644061?v=3","gravatar_id":"","url":"https://api.github.com/users/fangfsz","html_url":"https://github.com/fangfsz","followers_url":"https://api.github.com/users/fangfsz/followers","following_url":"https://api.github.com/users/fangfsz/following{/other_user}","gists_url":"https://api.github.com/users/fangfsz/gists{/gist_id}","starred_url":"https://api.github.com/users/fangfsz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fangfsz/subscriptions","organizations_url":"https://api.github.com/users/fangfsz/orgs","repos_url":"https://api.github.com/users/fangfsz/repos","events_url":"https://api.github.com/users/fangfsz/events{/privacy}","received_events_url":"https://api.github.com/users/fangfsz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-24T04:37:46Z","updated_at":"2017-05-24T04:37:46Z","closed_at":null,"body":"监控Web微信数据发送，发现： 当发现消息是一个视频文件时，Both会提示类型可能为XXX。也就是说未能成功检测到消息类型，那就也谈不上保存了。不知道是不是作者当时的情况是这样所导致如此。\r\n\r\n现根据所测数据，给出一个解决方法。 注意： \r\n\r\n> 粗体是改动部分，请仔细比对和注意缩进。\r\n\r\n1. 原文第1110行附近。\r\n   补充几个协议头，对于Web请求来说，通常我们发送的视频是mp4格式，也够了。所以这里加上好些。\r\n def _get(self, url: object, api: object = None, timeout: object = None) -> object:\r\n        request = urllib.request.Request(url=url)\r\n        request.add_header('Referer', 'https://wx.qq.com/')\r\n        if api == 'webwxgetvoice':\r\n            request.add_header('Range', 'bytes=0-')\r\n        if api == 'webwxgetvideo':\r\n            request.add_header('Range', 'bytes=0-')\r\n            **request.add_header('Accept', 'video/webm,video/ogg,video/*;q=0.9,application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5')**\r\n        if api == 'webwxgetmsgimg':\r\n            request.add_header('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5')\r\n        try:\r\n            response = urllib.request.urlopen(request, timeout=timeout) if timeout else urllib.request.urlopen(request)\r\n            if api == 'webwxgetvoice' or api == 'webwxgetvideo' or api =='webwxgetmsgimg' :\r\n                data = response.read()\r\n            else:\r\n                data = response.read().decode('utf-8')\r\n            logging.debug(url)\r\n            return data\r\n        except urllib.error.HTTPError as e:\r\n            logging.error('HTTPError = ' + str(e.code))\r\n        except urllib.error.URLError as e:\r\n            logging.error('URLError = ' + str(e.reason))\r\n        except http.client.HTTPException as e:\r\n            logging.error('HTTPException')\r\n        except timeout_error as e:\r\n            pass\r\n        except ssl.CertificateError as e:\r\n            pass\r\n        except Exception:\r\n            import traceback\r\n            logging.error('generic exception: ' + traceback.format_exc())\r\n        return ''\r\n2. 修改消息类型，原文第860行附近。  修改视频消息类型为 43. 这是目前Web抓包分析所得。\r\n elif **msgType == 43**:\r\n                video = self.webwxgetvideo(msgid)\r\n                raw_msg = {'raw_msg': msg,\r\n                           'message': '%s 发了一段小视频: %s' % (name, video)}\r\n                self._showMsg(raw_msg)\r\n                self._safe_open(video)"}}
{"actor":{"display_login":"fangfsz"}}