python可以调取第三方系统数据吗,微信公共平台第三方接口python实现,无法返回数据给客户端...

先给你一个我自己实现的示例,你先看看,微信公众平台只能在生产环境调试,这点很不好。如果还不行,可以联系我,微博:唐僧之妈#! /usr/bin/env python

# coding=utf-8

__author__ = 'jszhou'

from bottle import *

import hashlib

import xml.etree.ElementTree as ET

import urllib2

# import requests

import json

@get("/")

def checkSignature():

token = "****"

signature = request.GET.get('signature', None) # 拼写不对害死人那,把signature写成singnature,直接导致怎么也认证不成功

timestamp = request.GET.get('timestamp', None)

nonce = request.GET.get('nonce', None)

echostr = request.GET.get('echostr', None)

tmpList = [token, timestamp, nonce]

tmpList.sort()

tmpstr = "%s%s%s" % tuple(tmpList)

hashstr = hashlib.sha1(tmpstr).hexdigest()

# return "echostr: %s" % echostr

if hashstr == signature:

return echostr

else:

return None

def parse_msg():

recvmsg = request.body.read()

root = ET.fromstring(recvmsg)

msg = {}

for child in root:

msg[child.tag] = child.text

return msg

def query_movie_info():

movieurlbase = "http://api.douban.com/v2/movie/subject/"

DOUBAN_APIKEY = "******"

id = parse_msg()

url = '%s%s?apikey=%s' % (movieurlbase, id["Content"], DOUBAN_APIKEY)

# header = {'Referer': url, 'Content-Type': 'application/json'}

# resp = requests.get(url=url, headers=header)

resp = urllib2.urlopen(url)

movie = json.loads(resp.read())

info = movie['title'] + ': ' + ''.join(movie['summary'])

return info

@post("/")

def response_msg():

# 拿到Post过来的数据

# 分析数据(拿到FromUserName、ToUserName、CreateTime、MsgType和content)

# 构造回复信息(将其中content变为返回给用户的信息)

msg = parse_msg()

textTpl = """

%s

0

"""

Content = query_movie_info()

# if Content is not False:

echostr = textTpl % (msg['FromUserName'], msg['ToUserName'], str(int(time.time())), msg['MsgType'], Content)

return echostr

# else:

# echostr = textTpl % (msg['FromUserName'], msg['ToUserName'], str(int(time.time())), msg['MsgType'], "Content")

# return echostr

if __name__ == "__main__":

# Interactive mode

debug(True)

run(host='127.0.0.1', port=8888, reloader=True)

else:

# Mod WSGI launch

import sae

debug(True)

os.chdir(os.path.dirname(__file__))

app = default_app()

application = sae.create_wsgi_app(app)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值