首页 > 微信 > 详细

django 微信企业号 返回text消息

时间:2015-10-26 20:48:48      阅读:553      评论:0      收藏:0      [点我收藏+]
from django.template import Context,Template
textTemplate="""
        <xml>
        <ToUserName><![CDATA[{{target}}]]></ToUserName>
        <FromUserName><![CDATA[{{source}}]]></FromUserName>
        <CreateTime>{{time}}</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[{% autoescape off %} {{content}} {% endautoescape %} ]]></Content>
        <MsgId>{{MsgId}}</MsgId>
        <AgentID>{{AgentID}}</AgentID>
        </xml>
    """


    def response_text(self,msg):
        """
        回复文字消息
        """
        oneDic=self.message.__dict__
        oneDic['content']=msg;
        oneDic['time']=str(int(time.time()))
        t=Template(self.textTemplate)
        c=Context(oneDic)
        rs=t.render(c)
        
        return rs

其中避免html字符串被转译

{% autoescape off %} {{content}} {% endautoescape %}

django 微信企业号 返回text消息

原文:http://www.cnblogs.com/springday/p/4912220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!