当前位置:主页 > 接口开发 > 微信公众平台接口Python使用样例

微信公众平台接口Python使用样例

时间:2013-04-14 13:18来源:微信站 作者:网络 点击:
# coding=utf-8from django.http import HttpResponseimport hashlib, time, refrom xml.etree import ElementTree as ET def weixin(request): token = your token here params = request.GET args = [token, params[timestamp], params[nonce]] args.sort(
# coding=utf-8 from django.http import HttpResponse import hashlib, time, re from xml.etree import ElementTree as ET def weixin(request): token = "your token here" params = request.GET args = [token, params['timestamp'], params['nonce']] args.sort() if hashlib.sha1("".join(args)).hexdigest() == params['signature']: if params.has_key('echostr'): return HttpResponse(params['echostr']) else: reply = """<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>0</FuncFlag> </xml>""" if request.raw_post_data: xml = ET.fromstring(request.raw_post_data) content = xml.find("Content").text fromUserName = xml.find("ToUserName").text toUserName = xml.find("FromUserName").text postTime = str(int(time.time())) if not content: return HttpResponse(reply % (toUserName, fromUserName, postTime, "输入点命令吧...")) if content == "Hello2BizUser": return HttpResponse(reply % (toUserName, fromUserName, postTime, "产看微信营销经验,请登录 www.weixinz.com本微信更多功能开发中...")) else: return HttpResponse(reply % (toUserName, fromUserName, postTime, "暂不支持任何命令交互哦,功能开发中...")) else: return HttpResponse("Invalid Request") else: return HttpResponse("Invalid Request")
(责任编辑:admin)
Tags:微信公众平台接口 Python
------分隔线----------------------------

相关文章

文章评论

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)