如下图,如何用python开发出圆圈上的功能界面
微信公众号这块,我已经把后台的接收发信息开发好了,后台放在阿里云的服务器上,现在想有些功能上的界面,操作会更方便
你是打算用 python做web开发吗
你可以使用 django, 也可以使用flask,建议flask操作简单一些flask
给你一段flask的实例代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask,request, redirect, url_for
import logging
from wechatpy.utils import check_signature
from wechatpy.exceptions import InvalidSignatureException
from wechatpy import parse_message
from wechatpy.replies import TextReply
token = "mytoken"
records = []
MAXLEN = 10
app = Flask(__name__)
# 微信消息接口
@app.route('/',methods=["POST","GET"])
def main():
logging.debug('进入主页面')
if(len(request.args)<2):
return redirect(url_for('index'))
try:
signature = request.args.get("signature", "")
timestamp = request.args.get("timestamp", "")
nonce = request.args.get("nonce", "")
echostr = request.args.get("echostr", "")
# echostr是微信用来验证服务器的参数,需原样返回
if echostr:
try:
print('正在验证服务器签名')
check_signature(token, signature, timestamp, nonce)
print('验证签名成功')
return echostr
except InvalidSignatureException as e:
print('检查签名出错: '.format(e))
return 'Check Error'
# 也可以通过POST与GET来区别
# 不是在进行服务器验证,而是正常提交用户数据
print('开始处理用户消息')
result = handlemsg(request.data)
xml = result[0]
return xml
# 处理异常情况或忽略
except Exception as e:
print("exception")
def txtreply(msg,txt):
reply = TextReply(content=txt, message=msg)
xml = reply.render()
return xml
def handlemsg(data):
msg = parse_message(data)
print(msg)
content = msg.content
print(content)
xml = txtreply(msg, content)
return [xml]
@app.route('/index',methods=["GET"])
def index():
print('GET访问')
return 'The index page'
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True,port=80)