def new_textmsg(FromUserName, ToUserName, Content, retxml=True): ''' 创建文本回复 ''' dic = { 'ToUserName':str(ToUserName), 'FromUserName':str(FromUserName), 'CreateTime':int(time.time()), 'MsgType':'text', 'Content':str(Content) } if retxml: return dict2xml(dic) else: return dic
def new_articlesmsg(FromUserName, ToUserName, Articles, retxml=True): ''' 创建图文回复 @Articles 图文项数组,每项含:Title、Description、PicUrl、Url ''' dic = { 'ToUserName':str(ToUserName), 'FromUserName':str(FromUserName), 'CreateTime':int(time.time()), 'MsgType':'news', 'ArticleCount':len(Articles), 'Articles':Articles } if retxml: return dict2xml(dic).replace('<Article>', '<item>').replace('</Article>', '</item>') else: return dic
def new_musicmsg(FromUserName, ToUserName, Title, Description, MusicUrl, HQMusicUrl, retxml=True): ''' 创建音乐回复 ''' dic = { 'ToUserName':str(ToUserName), 'FromUserName':str(FromUserName), 'CreateTime':int(time.time()), 'MsgType':'music', 'Music':{ 'Title':Title, 'Description':Description, 'MusicUrl':MusicUrl, 'HQMusicUrl':HQMusicUrl } } if retxml: return dict2xml(dic) else: return dic