def tag_demo(content_dict):
    base_url = ''
    text = content_dict["Content"]
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    article_list = json.loads(requests.get(base_url + '/wechat_articles').content)
    a_url_map = {
        'tfboy': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956548&idx=1&sn=cc52b85072fefa296a7c5cb82dc62d34&scene=0&key=dffc561732c22651ddec47d91a219c794d0b204ef1258177ff8c11b3a77ba4188a6f8460a018e3f3e4bce4f5d8842b1f&ascene=0&uin=NDEyNTkyMzIw&devicetype=iMac+MacBookAir7%2C2+OSX+OSX+10.10.5+build(14F27)&version=11020201&pass_ticket=TzKtzXhA0l8eQjH%2F6GQzDu0eUG3q2CfimIMMueJ6COMF%2FlRyv63DyQgfdczmq0lj',
        'media': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956583&idx=1&sn=136dd5735898adb03dc017af6a4ad1a5#rd',
        'sportclass': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956618&idx=1&sn=34d1f00231abc79bb6d5e530e681f8f2#rd',
        'prod': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956649&idx=1&sn=f25062f29eb6bc779bf1b15a3690603c#rd',
        'wenzhou': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956662&idx=1&sn=da827726c75655d826be3c348bc88549#rd',
        'qiuyi': 'http://mp.weixin.qq.com/s?__biz=MzI1NTAxMTQwNQ==&mid=209956662&idx=1&sn=da827726c75655d826be3c348bc88549#rd'}
    news_list = [WeixinUtils.NewsItem(a_url_map['tfboy'], 'TFBOYS为什么这样红',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 WeixinUtils.NewsItem(a_url_map['media'], '注意力时代不可不知的新媒体8人',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 WeixinUtils.NewsItem(a_url_map['sportclass'], '体育与阶层',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 WeixinUtils.NewsItem(a_url_map['prod'], '无人见过我们真正的产品',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 WeixinUtils.NewsItem(a_url_map['wenzhou'], '温州话能成为军事密码么',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 WeixinUtils.NewsItem(a_url_map['qiuyi'], '球衣往事',
                                      'http://mmbiz.qpic.cn/mmbiz/SWL3EF8DbcxQPnJYStuemOSNdvf8ia7gxFIu394xfL2xmgqVWQxutZZVXWYJpU2DdXM3Z5Huu8sTgia1icYZbtSBw/640?wx_fmt=jpeg&wxfrom=5'),
                 ]

    # songname = re.compile(r'/[^ ]* ').sub("", text)
    # if len(songname) > 0 and songname != "/听歌":
    #     songlist = music_utils.get_searchlist(songname, 5)
    #     if songlist != None:
    return WeixinUtils.make_news(news_list, tousername, fromusername)
def get_error_resp(content_dict={}):
    """
    输入的指令以-开头,但是没有找到相应的指令关键字
    :param content_dict:
    :return:
    """
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    return WeixinUtils.make_singletext(tousername, fromusername, "指令有误,输入 /帮助 查看指令列表")
def get_music(content_dict={}):
    """
    返回云音乐爬取结果
    :param content_dict:
    :return:
    """
    text = content_dict["Content"]
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    songname = re.compile(r'/[^ ]* ').sub("", text)
    if len(songname) > 0 and songname != "/听歌":
        songlist = music_utils.get_searchlist(songname, 5)
        if songlist != None:
            return WeixinUtils.make_news(songlist, tousername, fromusername)
        else:
            return WeixinUtils.make_singletext(tousername, fromusername, "未找到相应的歌曲!")
    else:
        return WeixinUtils.make_singletext(tousername, fromusername, "请输入歌曲名!")
def get_commandmenu(content_dict={}):
    """
    返回指令列表
    :param content_dict:
    :return:
    """
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    str_commandmenu = "/帮助或/help:查看所有指令"
    return WeixinUtils.make_singletext(tousername, fromusername, str_commandmenu)
def get_defaultresp(content_dict={}):
    """
    返回指令列表
    :param content_dict:
    :return:
    """
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    reply = "你好,可以使用 “/”前缀+短语 进行指令操作,例如:/帮助"
    return WeixinUtils.make_singletext(tousername, fromusername, reply)
def user_login(content_dict={}):
    tousername = content_dict["FromUserName"]
    fromusername = content_dict["ToUserName"]
    re_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?' \
             'appid=%s' \
             '&redirect_uri=%s' \
             '&response_type=code' \
             '&scope=%s' \
             '&state=STATE#wechat_redirect' % \
             ('wx77081de86b8e6232', quote('http://120.27.30.239:80/login'), 'snsapi_userinfo')
    # re_url = quote(re_url1)
    return WeixinUtils.make_singletext(tousername, fromusername,
                                       "请访问%s" % re_url)
Exemple #7
0
def jiabei():
    if request.method == "GET":
        if len(request.args) > 3:
            temparr = []
            token = "xiaosenz"
            signature = request.args["signature"]
            timestamp = request.args["timestamp"]
            nonce = request.args["nonce"]
            echostr = request.args["echostr"]
            temparr.append(token)
            temparr.append(timestamp)
            temparr.append(nonce)
            temparr.sort()
            newstr = "".join(temparr)
            sha1str = hashlib.sha1(newstr)
            temp = sha1str.hexdigest()
            if signature == temp:
                return echostr
            else:
                return "认证失败,不是微信服务器的请求!"
        else:
            return "你请求的方法是:" + request.method
    else:  # POST
        xmldict = WeixinUtils.recv_msg(request.data)
        if xmldict["MsgType"] == "event":
            if xmldict["Event"] == "subscribe":
                reply = WeixinUtils.make_singletext(
                    xmldict["FromUserName"],
                    xmldict["ToUserName"],
                    "欢迎关注Senz情境技术,希望能与你交流更多有趣的想法!" "\n输入/帮助 查看相关操作指令。祝愉快!",
                )
            else:
                reply = ""
        else:
            reply = task_manager.check_task(xmldict)
        response = make_response(reply)
        response.content_type = "application/xml"
        return response