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)
Beispiel #6
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