content_type_id: 0 -> Text 1 -> Location 3 -> Image 4 -> Voice 5 -> Recommend 6 -> Animation 7 -> Share 8 -> Video 9 -> VideoCall 10 -> Redraw 11 -> Empty
(self, msg_type_id, msg)
| 233 | pass |
| 234 | |
| 235 | def extract_msg_content(self, msg_type_id, msg): |
| 236 | """ |
| 237 | content_type_id: |
| 238 | 0 -> Text |
| 239 | 1 -> Location |
| 240 | 3 -> Image |
| 241 | 4 -> Voice |
| 242 | 5 -> Recommend |
| 243 | 6 -> Animation |
| 244 | 7 -> Share |
| 245 | 8 -> Video |
| 246 | 9 -> VideoCall |
| 247 | 10 -> Redraw |
| 248 | 11 -> Empty |
| 249 | 99 -> Unknown |
| 250 | :param msg_type_id: The type of the received message. |
| 251 | :param msg: The received message. |
| 252 | :return: The extracted content of the message. |
| 253 | """ |
| 254 | mtype = msg['MsgType'] |
| 255 | content = msg['Content'].replace('<', '<').replace('>', '>') |
| 256 | msg_id = msg['MsgId'] |
| 257 | |
| 258 | msg_content = {} |
| 259 | if msg_type_id == 0: |
| 260 | return {'type': 11, 'data': ''} |
| 261 | elif msg_type_id == 2: # File Helper |
| 262 | return {'type': 0, 'data': content.replace('<br/>', '\n')} |
| 263 | elif msg_type_id == 3: # Group |
| 264 | sp = content.find('<br/>') |
| 265 | uid = content[:sp] |
| 266 | content = content[sp:] |
| 267 | content = content.replace('<br/>', '') |
| 268 | uid = uid[:-1] |
| 269 | msg_content['user'] = {'id': uid, 'name': self.get_prefer_name(self.get_account_name(uid))} |
| 270 | else: # Self, Contact, Special, Public, Unknown |
| 271 | pass |
| 272 | |
| 273 | msg_prefix = (msg_content['user']['name'] + ':') if 'user' in msg_content else '' |
| 274 | |
| 275 | if mtype == 1: |
| 276 | if content.find('http://weixin.qq.com/cgi-bin/redirectforward?args=') != -1: |
| 277 | r = self.session.get(content) |
| 278 | r.encoding = 'gbk' |
| 279 | data = r.text |
| 280 | pos = self.search_content('title', data, 'xml') |
| 281 | msg_content['type'] = 1 |
| 282 | msg_content['data'] = pos |
| 283 | msg_content['detail'] = data |
| 284 | if self.DEBUG: |
| 285 | print ' %s[Location] %s ' % (msg_prefix, pos) |
| 286 | else: |
| 287 | msg_content['type'] = 0 |
| 288 | msg_content['data'] = content.replace(u'\u2005', '') |
| 289 | if self.DEBUG: |
| 290 | print ' %s[Text] %s' % (msg_prefix, msg_content['data']) |
| 291 | elif mtype == 3: |
| 292 | msg_content['type'] = 3 |
no test coverage detected