当前位置: 首页>>代码示例>>Python>>正文


Python WechatBasic.response_news方法代码示例

本文整理汇总了Python中wechat_sdk.WechatBasic.response_news方法的典型用法代码示例。如果您正苦于以下问题:Python WechatBasic.response_news方法的具体用法?Python WechatBasic.response_news怎么用?Python WechatBasic.response_news使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wechat_sdk.WechatBasic的用法示例。


在下文中一共展示了WechatBasic.response_news方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: weixin

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def weixin(request):
    wechat = WechatBasic(token=token)
    if wechat.check_signature(signature=request.GET['signature'],
                              timestamp=request.GET['timestamp'],
                              nonce=request.GET['nonce']):
        if request.method == 'GET':
            rsp = request.GET.get('echostr', 'error')
        else:
            wechat.parse_data(request.body)
            message = wechat.get_message()
            # write_log(message.type)
            if message.type == u'text':
                response_content = 'this is text'
                # response_content = handle_text(message.content)
                if message.content == u'wechat':
                    # response_content = 'hello wechat'
                    rsp = wechat.response_text(u'^_^')
                elif re.findall(u'锐捷', message.content):
                    rsp = wechat.response_news(ruijie_response)
                else:
                    rsp = wechat.response_news(default_response)
            else:
                # rsp = wechat.response_text(u'消息类型: {}'.format(message.type))
                rsp = wechat.response_news(default_response)

    else:
        rsp = wechat.response_text('check error')
    return HttpResponse(rsp)
开发者ID:pierre94,项目名称:python-django-cd-sample,代码行数:30,代码来源:views.py

示例2: wechat_auth

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def wechat_auth():
    wechat = WechatBasic(token=TOKEN)
    if request.method == 'GET':
        token = TOKEN  # your token
        query = request.args  # GET 方法附上的参数
        signature = query.get('signature', '')
        timestamp = query.get('timestamp', '')
        nonce = query.get('nonce', '')
        echostr = query.get('echostr', '')

        if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return make_response(echostr)
        else:
            return 'Signature Mismatch'
    else:
        body_text=request.data
        wechat.parse_data(body_text)
        # 获得解析结果, message 为 WechatMessage 对象 (wechat_sdk.messages中定义)
        message = wechat.get_message()
        response = None
        # 在这里解析 message.content 也就是用户发来的文字
        if message.type == 'text':
            if message.content.lower() in ('h', 'help'):
                response = wechat.response_text(u'z 看知乎日报\nv 看 V2EX 十大\nh 为帮助\n输入其他文字与机器人对话 : )')
            elif message.content == 'wechat':
                response = wechat.response_text(u'^_^')
            elif message.content[0:3] == 'test':
                response = wechat.response_text(u'I\'m testing ' + message.content[4:])
            elif (u'陆' or u'杰') in message.content:
                response = wechat.response_text(u'爸爸是个天才')
            elif (u'***' or u'内内') in message.content:
                response = wechat.response_text(u'内内,为什么你名字那么难写')
            elif message.content.upper() in ('V', 'V2EX'):
                response = wechat.response_news(get_v2ex_news())
            elif message.content.upper() in ('Z', 'ZHIHU'):
                response = wechat.response_news(get_zhihudaily())
            else:
                response = wechat.response_text(get_turing(message.content))
        elif message.type == 'image':
            response = wechat.response_text(u'您发来了一个图片')
        elif message.type == 'location':
            response = wechat.response_text(u'您的位置我已收到')
        elif message.type == 'subscribe':
            response = wechat.response_text(u'oh...你居然关注了,其实我自己也不知道关注这个号有啥用.\nz 看知乎日报\nv 看 V2EX 十大\nh 为帮助\n输入其他文字与机器人对话 : )')
        elif message.type == 'unsubscribe':
            response = wechat.response_text(u'呜呜呜,爱我别走.....')
        else:
            response = wechat.response_text(u'未知类型。您发的是什么?')
        return response
开发者ID:newlcj93,项目名称:weixin,代码行数:51,代码来源:myapp.py

示例3: validate

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def validate():
    signature = request.args.get('signature')
    echostr = request.args.get('echostr')
    timestamp = request.args.get('timestamp')
    nonce = request.args.get('nonce')

    token = "test"

    body_text = request.get_data()

    # 实例化 wechat
    wechat = WechatBasic(token=token)
    # 对签名进行校验
    if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
        # 对 XML 数据进行解析 (必要, 否则不可执行 response_text, response_image 等操作)
        wechat.parse_data(body_text)
        # 获得解析结果, message 为 WechatMessage 对象 (wechat_sdk.messages中定义)
        message = wechat.get_message()

        response = None

        if message.type == 'subscribe':
            response = wechat.response_text("谢谢关注V2EX热帖分享,输入任意内容以获取最新热帖咨询")

        if message.type == 'text':
            newsList = generate()
            response = wechat.response_news(newsList)

        # 现在直接将 response 变量内容直接作为 HTTP Response 响应微信服务器即可,此处为了演示返回内容,直接将响应进行输出
        return response
开发者ID:ieiayaobb,项目名称:v2ex_push,代码行数:32,代码来源:Application.py

示例4: index

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def index(request):

    # 实例化 We_chat_Basic
    we_chat = WechatBasic(token=WECHAT_TOKEN, appid=AppID, appsecret=AppSecret)
    if request.method == "GET":
        signature = request.GET.get("signature")
        timestamp = request.GET.get("timestamp")
        nonce = request.GET.get("nonce")
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        else:
            return HttpResponse(request.GET.get("echostr"), content_type="text/plain")
    else:
        signature = request.GET.get("signature")
        timestamp = request.GET.get("timestamp")
        nonce = request.GET.get("nonce")
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        try:
            we_chat.parse_data(data=request.body)
        except ParseError:
            return HttpResponseBadRequest("Invalid XML Data")
        message = we_chat.get_message()
        if isinstance(message, EventMessage):
            if message.type == "click":
                if message.key == "STEP_COUNT":
                    step_array = Record.objects.filter(user=message.source)
                    if step_array:
                        step = step_array[len(step_array) - 1].step
                        response = we_chat.response_text("跑了" + str(step) + "步咯")
                        # 里面的数字应由其他函数获取
                        return HttpResponse(response)
                    else:
                        response = we_chat.response_text("Sorry, there' no data about you in our database.")
                        return HttpResponse(response)
                if message.key == "CHART":
                    print 1
                    response = we_chat.response_news(
                        [
                            {
                                "title": "Today's amount of exercise",
                                "description": "data analysis",
                                "picurl": "http://7xn2s5.com1.z0.glb.clouddn.com/ez.png",
                                "url": SERVER_IP + "TodayChart/" + message.source,
                            }
                        ]
                    )
                    return HttpResponse(response)
        response = we_chat.response_text("Cheer up!")
        return HttpResponse(response)
开发者ID:xujingao13,项目名称:Arrange,代码行数:52,代码来源:views.py

示例5: index

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def index(request):
 
    # 实例化 We_chat_Basic
    we_chat = WechatBasic(
        token=WECHAT_TOKEN,
        appid=AppID,
        appsecret=AppSecret
    )
    if request.method == "GET":
        signature = request.GET.get('signature')
        timestamp = request.GET.get('timestamp')
        nonce = request.GET.get('nonce')
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        else:
            return HttpResponse(request.GET.get("echostr"), content_type="text/plain")
    else:
        signature = request.GET.get('signature')
        timestamp = request.GET.get('timestamp')
        nonce = request.GET.get('nonce')
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        try:
            we_chat.parse_data(data=request.body)
        except ParseError:
            return HttpResponseBadRequest('Invalid XML Data')
        message = we_chat.get_message()
        if isinstance(message, EventMessage):
            if message.type == 'click':
                if message.key == 'STEP_COUNT':
                    step_array = Record.objects.filter(user=message.source)
                    if step_array:
                        step = step_array[len(step_array) - 1].step
                        response = we_chat.response_text(u'跑了' + str(step) + u'步咯')
                        # 里面的数字应由其他函数获取
                        return HttpResponse(response)
                    else:
                        response = we_chat.response_text(u'Sorry, there\' no data about you in our database.')
                        return HttpResponse(response)
                if message.key == 'CHART':
                    print 1
                    response = we_chat.response_news([{
                        'title': u'Today\'s amount of exercise',
                        'description': 'data analysis',
                        'picurl': 'http://7xn2s5.com1.z0.glb.clouddn.com/ez.png',
                        'url': SERVER_IP + 'TodayChart/' + message.source}])
                    return HttpResponse(response)
        response = we_chat.response_text(u'Cheer up!')
        return HttpResponse(response)
开发者ID:Software-Eng-THU-2015,项目名称:TreasureRing,代码行数:51,代码来源:views.py

示例6: test_response_news

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
    def test_response_news(self):
        wechat = WechatBasic()
        wechat.parse_data(data=self.test_message)

        resp_xml = wechat.response_news(articles=[
            {
                'title': '第一条新闻标题',
                'description': '第一条新闻描述,这条新闻没有预览图',
                'url': 'http://www.google.com.hk/',
            }, {
                'title': '第二条新闻标题, 这条新闻无描述',
                'picurl': 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg',
                'url': 'http://www.github.com/',
            }, {
                'title': '第三条新闻标题',
                'description': '第三条新闻描述',
                'picurl': 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg',
                'url': 'http://www.v2ex.com/',
            }
        ])
        resp = xmltodict.parse(resp_xml)

        self.assertEqual(resp['xml']['ToUserName'], 'fromUser')
        self.assertEqual(resp['xml']['FromUserName'], 'toUser')
        self.assertEqual(resp['xml']['MsgType'], 'news')
        self.assertEqual(resp['xml']['ArticleCount'], '3')

        self.assertEqual(resp['xml']['Articles']['item'][0]['Title'], '第一条新闻标题')
        self.assertEqual(resp['xml']['Articles']['item'][0]['Description'], '第一条新闻描述,这条新闻没有预览图')
        self.assertEqual(resp['xml']['Articles']['item'][0]['Url'], 'http://www.google.com.hk/')
        self.assertIsNone(resp['xml']['Articles']['item'][0]['PicUrl'])

        self.assertEqual(resp['xml']['Articles']['item'][1]['Title'], '第二条新闻标题, 这条新闻无描述')
        self.assertIsNone(resp['xml']['Articles']['item'][1]['Description'])
        self.assertEqual(resp['xml']['Articles']['item'][1]['Url'], 'http://www.github.com/')
        self.assertEqual(resp['xml']['Articles']['item'][1]['PicUrl'], 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg')

        self.assertEqual(resp['xml']['Articles']['item'][2]['Title'], '第三条新闻标题')
        self.assertEqual(resp['xml']['Articles']['item'][2]['Description'], '第三条新闻描述')
        self.assertEqual(resp['xml']['Articles']['item'][2]['Url'], 'http://www.v2ex.com/')
        self.assertEqual(resp['xml']['Articles']['item'][2]['PicUrl'], 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg')
开发者ID:14F,项目名称:wechat-python-sdk,代码行数:43,代码来源:test_basic.py

示例7: smart_entry

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def smart_entry(request):
    signature = request.REQUEST.get('signature', None)
    timestamp = request.REQUEST.get('timestamp', None)
    nonce = request.REQUEST.get('nonce', None)

    # if it's account authenticate request
    echostr = request.REQUEST.get('echostr', None)
    if echostr:
        return HttpResponse(echostr)

    wechat = WechatBasic(token=settings.WECHAT_TOKEN, appid=settings.WECHAT_ACCOUNT)

    # 对签名进行校验
    if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
        # 对 XML 数据进行解析 (必要, 否则不可执行 response_text, response_image 等操作)
        body_text = request.body
        log.info("Wechat message come: {0}".format(body_text))

        wechat.parse_data(body_text)
        # 获得解析结果, message 为 WechatMessage 对象 (wechat_sdk.messages中定义)
        message = wechat.get_message()

        #response = None
        if isinstance(message, EventMessage):
            if message.type == 'click' and message.key == 'V1001_PLANT_LIVE':
                # post latest image
                records = IoTRecord.objects.filter().order_by("-timestamp")[:1]
                if not records or not records[0].image:
                    return HttpResponse(wechat.response_text(u"找不到你的菜呀!"))

                api = WechatCgiApi(app_id=settings.WECHAT_APP_ID, app_secret=settings.WECHAT_APP_SECRET)
                result_token = WechatConfig.objects.filter(key=WechatConfig.KEY_ACCESS_TOKEN)
                if not result_token or result_token[0].is_expired():
                    result_update, resp_json = WechatConfig.refresh_access_token()
                    if result_update:
                        token = resp_json[u"access_token"]
                    else:
                        log.error("Cannot update wechat access token: {0}".format(resp_json))
                        return HttpResponse(wechat.response_text(u"服务器有点小问题。。。"))
                        
                else:
                    token = result_token[0].value

                with open(records[0].image.path, 'rb') as live_image:
                    api_result = api.create_temp_media(token, "image", media={"media": live_image})
                    log.info("Wechat upload image response: {0}".format(api_result))
                    if api_result and api_result["media_id"]:
                        return HttpResponse(wechat.response_image(api_result["media_id"]))
                    else:
                        log.warning("Wechat upload temporary image failed: {0}".format(api_result))
                        return HttpResponse(wechat.response_text(u"发送图片失败: {0}".format(str(api_result))))


            elif message.type == 'click' and message.key == 'V1001_HEALTH_STATS':
                return HttpResponse(wechat.response_text(u"功能未实现"))

            elif message.type == 'click' and message.key == 'V1001_GROW_VID':
                return HttpResponse(wechat.response_text(u"功能未实现。"))

            elif message.type == 'click' and message.key == 'V1001_PLAY_CUTE':
                return HttpResponse(wechat.response_text(u"我已经长得很好吃了,主人请摘我吧!"))

        #    response = wechat.response_text(content=u'文字信息')

        response = wechat.response_news([{
                "title": "我是别人的菜",
                "description": "你要的功能失败了,这是测试页面",
                "picurl": "http://wechat.lucki.cn/static/iotimages/test.jpg",
                "url": "http://wechat.lucki.cn/",
            },])

        return HttpResponse(response)

    return HttpResponse("Not implemented yet")
开发者ID:SZmaker,项目名称:LazyPlant,代码行数:76,代码来源:views.py

示例8: HttpResponse

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
        wechat.parse_data(post_data,msg_signature=msg_signature, timestamp=timestamp, nonce=nonce)
    except Exception, e:
        print "error.msg:%s" % (str(e))
        return HttpResponse(u'parse_data error')
    print "return a message"

    if isinstance(wechat.message, TextMessage):
        content = wechat.message.content
        #回复一个图文信息
        articles = []
        onearticle = {}
        onearticle["title"] = u'查看"%s"相关电影' % content
        onearticle["description"] = u'查看"%s"相关电影' % content
        onearticle["url"] = u"http://15dyy.com/wx_search?keyword=%s" % content
        articles.append(onearticle)
        xml = wechat.response_news(articles)
        return HttpResponse(xml)
    if  isinstance(wechat.message, EventMessage):
        if wechat.message.type == "subscribe":
            articles = []
            onearticle = {}
            onearticle["title"] = u'欢迎关注,获取电影资源'
            onearticle["description"] = u'欢迎关注,获取电影资源'
            onearticle["url"] = u"http://15dyy.com/wx_index"
            articles.append(onearticle)
            xml = wechat.response_news(articles)
            return HttpResponse(xml)
    articles = []
    onearticle = {}
    onearticle["title"] = u'不能识别,点击获取更多电影资源'
    onearticle["description"] = u'不能识别,点击获取更多电影资源'
开发者ID:luckyzwei,项目名称:movie,代码行数:33,代码来源:wx.py

示例9: weixin

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def weixin(request):
    # 实例化 We_chat_Basic
    we_chat = WechatBasic(
        token=WECHAT_TOKEN,
        appid=AppID,
        appsecret=AppSecret
    )
    if request.method == "GET":
        signature = request.GET.get('signature')
        timestamp = request.GET.get('timestamp')
        nonce = request.GET.get('nonce')
        if "bet" in request.GET:
            return get_user_bet(request)
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        else:
            #create_menu()
            return HttpResponse(request.GET.get("echostr"), content_type="text/plain")
    else:
        signature = request.GET.get('signature')
        timestamp = request.GET.get('timestamp')
        nonce = request.GET.get('nonce')
        if not we_chat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
            return HttpResponse("Verify failed")
        try:       
            we_chat.parse_data(data=request.body)
        except ParseError:
            return HttpResponseBadRequest('Invalid XML Data')
        message = we_chat.get_message()
        if isinstance(message, TextMessage):
            result = process_text_message(message)
            response = we_chat.response_text(result)
            return HttpResponse(response)
        if isinstance(message, EventMessage):
            if message.type == 'click':
                if message.key == 'STEP_COUNT':
                    step_user = RingUser.objects.filter(user_id=message.source)[0]
                    if step_user:
                        try:
                            target = step_user.target
                            step = get_today_step(step_user)
                            goal_completion = int(float(step) / target * 100)
                            response = we_chat.response_text(u'跑了' + str(step) + u'步咯,完成今日目标:' + str(goal_completion) + u'%')
                        except Exception as e:
                            print e
                        # 里面的数字应由其他函数获取
                        return HttpResponse(response)
                    else:
                        response = we_chat.response_text(u'Sorry, there\' no data about you in our database.')
                        return HttpResponse(response)

                elif message.key == 'RANK_LIST':
                    response = RESPONSE_RANKLIST % (message.source, message.target)
                    return HttpResponse(response)  

                elif message.key == '2048':
                    response = we_chat.response_news([{
                            'title': u'Let us play 2048 together',
                            'description': 'a simple but interesting game',
                            'picurl': 'http://7xn2s5.com1.z0.glb.clouddn.com/2048.jpg',
                            'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+AppID+'&redirect_uri=http%3a%2f%2f'+LOCAL_IP+'%2fdodojump.html'+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'}])
                    return HttpResponse(response)

                elif message.key == 'FLAPPY':
                    response = we_chat.response_news([{
                            'title': u'Let us play Flappy Bird together',
                            'description': 'a simple but interesting game',
                            'picurl': 'http://7xn2s5.com1.z0.glb.clouddn.com/flappy_bird.jpg',
                            'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+AppID+'&redirect_uri=http%3a%2f%2f'+LOCAL_IP+'%2fflyingdog.html'+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'}])
                    return HttpResponse(response)

                elif message.key == 'CHART':
                    print "here"
                    response = we_chat.response_news([{
                        'title': u'Today\'s amount of exercise',
                        'description': 'data analysis',
                        'picurl': 'http://7xn2s5.com1.z0.glb.clouddn.com/info.jpg',
                        'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+AppID+'&redirect_uri=http%3a%2f%2f'+LOCAL_IP+'%2fsleepAnalysis.html'+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'}])
                    return HttpResponse(response)

                elif message.key == 'CHEER':
                    response = we_chat.response_text(u'We are family!')
                    return HttpResponse(response)
            return HttpResponse('OK')
开发者ID:caozhangjie,项目名称:weixin,代码行数:86,代码来源:views.py

示例10:

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
                    # 注销用户
                    user_off = {'state':'off'}
                    result = db_obj.dbput('api/user/'+str(rec_source),user_off)
                except Exception, e:
                    raise e

            elif rec_type == 'click':  # 自定义菜单点击事件
                key = wechat.message.key           # 对应于 XML 中的 EventKey
                if key == 'TODAY_MISSIONS':
                    feedback = wechat.response_news([
                        {
                            'title': u'IT类项目',
                            'picurl': u'http://o7m541j22.bkt.clouddn.com/justdoit.jpg',
                            'description': u'Cisco、Oracle、Linux相关',
                            'url': u'https://open.weixin.qq.com/connect/oauth2/authorize'+u'?appid=wxa9312a82e8138370&redirect_uri=http%3A%2F%2Fbountyunions.applinzi.com%2Fwechat%2Fmissionhall&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect',
                        },{
                            'title': u'非IT类项目',
                            'picurl': u'http://o7m541j22.bkt.clouddn.com/biznetwork.png',
                            'description': u'其他和IT相关的非技术性任务',
                            'url': u'http://www.baidu.com/',
                        }

                    ])
                    return feedback
                elif key == 'APP_HELP':
                    feedback = wechat.response_news([
                        {
                            'title': u'帮助',
                            'picurl': u'http://o7m541j22.bkt.clouddn.com/biznetwork.png',
                            'description': u'正确姿势',
                            'url': u'http://www.baidu.com/',
                        }
开发者ID:liangchaob,项目名称:bountyhunter,代码行数:34,代码来源:weichatweb.py

示例11: WechatBasic

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
# 实例化 wechat
wechat = WechatBasic(WechatConf(token=token, encrypt_mode='normal'))
# 对签名进行校验
if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
    # 对 XML 数据进行解析 (必要, 否则不可执行 response_text, response_image 等操作)
    wechat.parse_data(body_text)
    # 获得解析结果, message 为 WechatMessage 对象 (wechat_sdk.messages中定义)
    message = wechat.get_message()

    response = None
    if message.type == 'text' and message.content == '新闻':
        response = wechat.response_news([
            {
                'title': '第一条新闻标题',
                'description': '第一条新闻描述,这条新闻没有预览图',
                'url': 'http://www.google.com.hk/',
            }, {
                'title': '第二条新闻标题, 这条新闻无描述',
                'picurl': 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg',
                'url': 'http://www.github.com/',
            }, {
                'title': '第三条新闻标题',
                'description': '第三条新闻描述',
                'picurl': 'http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg',
                'url': 'http://www.v2ex.com/',
            }
        ])

    # 现在直接将 response 变量内容直接作为 HTTP Response 响应微信服务器即可,此处为了演示返回内容,直接将响应进行输出
    print(response)
开发者ID:daimon99,项目名称:wechat-python-sdk,代码行数:32,代码来源:tutorial_official_2.py

示例12: index

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def index():
    token = settings.TOKEN
    signature = request.args.get('signature', '')
    timestamp = request.args.get('timestamp', '')
    nonce = request.args.get('nonce', '')

    # 实例化 wechat
    wechat = WechatBasic(token=token)

    if not wechat.check_signature(signature=signature,
                                  timestamp=timestamp, nonce=nonce):
        return 'fail'

    # 对签名进行校验
    echostr = request.args.get('echostr')
    if echostr:
        return echostr

    wechat.parse_data(request.data)
    message = wechat.get_message()
    if message.type == 'text':
        if message.content == '1':
            response = wechat.response_news(settings.TIPS)
        elif message.content == u'活动详细说明':
            response = wechat.response_text(settings.ACTIVITY_DESC)
        else:
            response = wechat.group_transfer_message()
    elif message.type == 'image':
        response = ''
    elif isinstance(message, EventMessage):
        if message.type == 'subscribe':
            if message.key and message.ticket:
                scene = message.key.startswith(
                    'qrscene_') and message.key[8:] or 'default'
            else:
                scene = 'default'

            SubscribeEvent.create_event(message.source, scene, message.time)
            response = wechat.response_text(content=settings.GREETINGS)

        elif message.type == 'unsubscribe':
            UnsubscribeEvent.create_event(message.source, message.time)
            # TODO
            response = ''
        elif message.type == 'scan':
            # TODO
            response = ''
        elif message.type == 'location':
            response = ''
            #response = wechat.response_text(content=u'上报地理位置事件')
        elif message.type == 'click':
            content = settings.CLICK_MENU_TEXT_MAPPER.get(message.key, u'未知')
            response = wechat.response_text(content=content)
        elif message.type == 'view':
            response = ''
            #response = wechat.response_text(content=u'自定义菜单跳转链接事件')
        elif message.type == 'templatesendjobfinish':
            response = ''
            #response = wechat.response_text(content=u'模板消息事件')
        else:
            response = ''
    else:
        response = wechat.response_text(u'未知')
    return response
开发者ID:daixm,项目名称:wechat-admin,代码行数:66,代码来源:views.py

示例13: MsgProcess

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
				mp = MsgProcess()
				response = mp.msg_process(message, wechat)
			# 消息内容为图片
			elif isinstance(message, ImageMessage):
<<<<<<< HEAD
                            ip = ImgProcess()
                            content = ip.check_picture(message)
                            response = wechat.response_text(content)
			# 消息内容为事件
			elif isinstance(message, EventMessage):
				ep = EventProcess()
				state, response = ep.click_event(message)
				if response == '获取地理信息':
					return 
                                if state == 'news':
                                    response = wechat.response_news(response)
                                elif state == 'text':
                                    response = wechat.response_text(response)
=======
				picurl = message.picurl
				#media_id = message.media_id
				download_picture.get(picurl)		
				response = wechat.response_text('上传成功!')
			# 消息内容为事件
			elif isinstance(message, EventMessage):
				ep = EventProcess()
				content = ep.click_event(message)
				if content == '获取地理信息':
					return 
				response = wechat.response_text(content)
>>>>>>> 48f33b10e0460d1b1213af2c3d17ecd3f84e0ac5
开发者ID:mynameischaos,项目名称:ypyk-wechat,代码行数:33,代码来源:index.py

示例14: index

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
def index():
    echostr = request.args.get('echostr', '')
    if (echostr != ''):
        return echostr

    signature = request.args.get('signature')
    timestamp = request.args.get('timestamp')
    nonce = request.args.get('nonce')
    body_text = request.data
    print 'body======='
    print body_text
    print '========'
    wechat = WechatBasic(token = wechat_config['token'], appid = wechat_config['appid'], appsecret = wechat_config['appsecret'])
    wechat.grant_token()
    # 对签名进行校验
    if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
        # 对 XML 数据进行解析 (必要, 否则不可执行 response_text, response_image 等操作)
        wechat.parse_data(body_text)
        message = wechat.get_message()
        openid = message.source
        
        if message.type == 'text':
            if message.content == 'wechat':
                response = wechat.response_text(u'^_^')
            else:
                response = wechat.response_text(u'文字')
        elif message.type == 'image':
            response = wechat.response_text(u'图片')
        elif message.type == 'click':
            if message.key == 'GET_STEP':
                response = wechat.response_news([{
                        'title': u'步数信息',
                        'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.step', openid = openid))
                    }])
            elif message.key == 'GET_RATE_CURVE':
                response = wechat.response_news([{
                        'title': u'心率曲线',
                        'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.rate', openid = openid))
                    }])
            elif message.key == 'GET_RATE_NOW':
                response = wechat.response_news([{
                        'title': u'当前心率',
                        'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.rate_now', openid = openid))
                    }])
            elif message.key == 'GET_RANK':
                response = response_rank(message.target, message.source)
                print ranklist
            elif message.key == 'SET_INFO':
                response = wechat.response_news([{
                        'title': u'信息维护',
                        'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.register', openid = openid))
                    }])
            elif message.key == 'ADD_SPORT':
                response = wechat.response_news([{
                        'title': u'添加运动',
                        'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.add_sport', openid = openid))
                    }])
            elif message.key == 'PET_SYS':
                if exist_user(message.source):
                    response = wechat.response_news([{
                            'title': u'宠物系统',
                            'url': u'http://%s:5000%s' % (wechat_config['localAddr'], url_for('main.pet_welcome', openid = openid))
                        }])
                else:
                    response = wechat.response_text(u'请先维护个人信息(点击“个人”-“信息维护”)')
            else:
                response = wechat.response_text(u'抱歉,这个功能还在开发中0 0')
        elif message.type == 'subscribe':
            response = wechat.response_text(u'雷吼!')
        else:
            response = wechat.response_text(u'未知')

        # 现在直接将 response 变量内容直接作为 HTTP Response 响应微信服务器即可
        print 'response: ========'
        #print response
        print '========'
    return response
开发者ID:ThreePigsTeam,项目名称:wechat-band,代码行数:79,代码来源:views.py

示例15: in

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import response_news [as 别名]
 
# 对来自微信服务器的信息处理部分
if wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce):
    # 对 XML 数据进行解析
    wechat.parse_data(body_text)
 
    # 获得解析结果, message 为 WechatMessage 对象 (wechat_sdk.messages中定义)
    message = wechat.get_message()
 
    response = None


    if message.type == 'text':
        if message.content.lower() in ('hello', 'hi'):
	    response = wechat.response_text(u'Who are you!')
	elif message.content.encode(encoding='UTF-8', errors='strict').lower() in (u'一拍遥控', 'app', 'ypyk', 'APP'):
	    response = wechat.response_news(
		[
			{
				'title': u'一拍遥控',
				'description': u'点击进入属于您自己的遥控器',
				#'url':u'http://demo.open.weixin.qq.com/jssdk',
				'url': u'http://weixin.yipaiyaokong.com/ypyk-web/wechat/index.html',
				'picurl': u'http://weixin.yipaiyaokong.com/ypyk-web/wechat/image/page.png',
			},

		])
        else:
            response = wechat.response_text(content = get_turing(message.content))
    print response.encode('utf-8')
开发者ID:mynameischaos,项目名称:ypyk-wechat,代码行数:32,代码来源:test.py


注:本文中的wechat_sdk.WechatBasic.response_news方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。