当前位置: 首页 > news >正文

牛商网做网站的思路深圳百度推广联系方式

牛商网做网站的思路,深圳百度推广联系方式,上传软件的网站,展示型网站建设流程上一篇做了服务器校验,但没有处理用户发来的消息,为了完成自动回复的功能,需要增加一些功能: 1、调整服务器校验函数: def verify_wechat(request):tokentokendatarequest.argssignaturedata.get(signature)timestamp…

上一篇做了服务器校验,但没有处理用户发来的消息,为了完成自动回复的功能,需要增加一些功能:

1、调整服务器校验函数:

def verify_wechat(request):token='token'data=request.argssignature=data.get('signature')timestamp=data.get('timestamp')nonce=data.get('nonce')echostr=data.get('echostr')temp=[timestamp,nonce,token]temp.sort()temp=''.join(temp)if (hashlib.sha1(temp.encode('utf8')).hexdigest()==signature):return echostrelse:return 'error',403
2、解析用户发来的信息

微信公众号中,用户发给公众号的消息是以xml形式发给服务器的,所以要先对xml进行解析:

def getUserMessageContentFromXML(xml_content):root=ET.fromstring(xml_content)content=root.find('Content').textfrom_user_name=root.find('FromUserName').textto_user_name=root.find('ToUserName').textreturn content,from_user_name,to_user_name

这个函数获取了用户和公众号的id(名称)

3、回复信息(“你好”)

回复信息,和收到信息一样,都是xml形式,所以要先把回复的信息调整成xml形式:


def generate_response_xml(from_user_name,to_user_name,output_content):output_xml= '''<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[%s]]></Content></xml>'''response = make_response(output_xml % (from_user_name, to_user_name, str(int(time.time())), str(output_content)))response.content_type = 'application/xml'return response

然后,调整服务器函数:


@app.route('/wechatai', methods=['GET', 'POST'])
def wechatai():if request.method == 'GET':return verify_wechat(request)else:print("user request data: ",request.data)user_message_content,from_user_name,to_user_name=getUserMessageContentFromXML(request.data)print(from_user_name)print(to_user_name)return generate_response_xml(from_user_name, to_user_name, "你好")

最终效果:(为了避免一直你好,通过if条件判断,只设置了自己的信息才会回复“你好”)

http://www.hrbkazy.com/news/22964.html

相关文章:

  • 微信微网站是什么格式搜索引擎优化seo培训
  • 做齐鲁油官方网站商品推广与营销的方式
  • 做idc销售怎样建网站今日新闻内容
  • 设计型网站案例百度seo公司电话
  • 微站官网seo标题优化分析范文
  • 10个网站做站群seo网站推广的主要目的包括
  • 徐州seo推广seo排名优化课程
  • 石家庄哪家网站做的好培训心得体会范文500字
  • 普陀营销型网站建设广州市新闻最新消息
  • 网站建设业务介绍neotv
  • 机械东莞网站建设0769软文写手
  • 做的网站没法本地上传图片天眼查询个人
  • 西安网站建设 招聘成都抖音seo
  • 口碑营销为什么越来越重要免费网站seo
  • 提供网站制作广州seo技术外包公司
  • 百度网盘网站开发文档模板河南今日头条新闻最新
  • 如何做电商网站视频seo分析与优化实训心得
  • 云南建设厅网站工程师北京做网站的公司排行
  • 天河商城型网站建设百度网盘网页版登录首页
  • 西安建设工程交易网站外链工厂 外链
  • 网站需求流程图广告公司名称
  • 个人网站备案网站名称手机优化专家下载
  • 京山网站设计海淀区seo搜索引擎
  • 东莞市建设中心国外seo网站
  • 产品宣传片seo站长工具查询系统
  • 鹿邑网站设计公司网络营销推广工具有哪些?
  • 外贸推广网站有哪些如何创建个人网站免费
  • 深圳南山做网站的公司seo怎么去优化
  • 百度推广 个人网站全网推广网站
  • 有限公司和股份有限公司的区别佛山网站设计实力乐云seo