如何将XML数据发布到plone视图并将XML数据返回给发送方?

如何将XML数据发布到plone视图并将XML数据返回给发送方?,xml,view,plone,wechat,Xml,View,Plone,Wechat,我想使用plone接收微信服务器发布的xml消息。 我定义以下浏览器视图以接收消息: class Receive(BrowserView): def__init__(self,context,request) self.context = context self.request = request def render(self): from zope import event import pdb pdb.set_trace() from m

我想使用plone接收微信服务器发布的xml消息。 我定义以下浏览器视图以接收消息:

class Receive(BrowserView):
def__init__(self,context,request)
    self.context = context
    self.request = request

def render(self):
    from zope import event
    import pdb
    pdb.set_trace()
    from my315ok.wechat.events import ReceiveWechatEvent

    data = self.request.form
    ev = self.request.environ
    robot = BaseRoBot(token="haha018")        

    try:
        rn = robot.check_signature(
        data["timestamp"],
        data["nonce"],
        data["signature"]
        )
    except:
        return self.abort(403)

    if ev['REQUEST_METHOD'] =="GET":
        # valid request from weixin
        if rn:
            return data["echostr"]
        else:
            return self.abort(403)           

    else:
        # normal request form weixin
        if not rn:
            return self.abort(403)

        body =  self.request.get['BODY']

        message = parse_user_msg(body)
        logging.info("Receive message %s" % message)                    
        event.notify(ReceiveWechatEvent(message))
        return ""
这是我的zcml文件:

 <configure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:browser="http://namespaces.zope.org/browser"
   i18n_domain="my315ok.wechat">

  <browser:page
      for="*"
      name="send_as_wechat"
      class=".send.SendForm"
      template="templates/send_page.pt"
      permission="zope2.View"
  />
  <browser:page
      for="*"
      name="robot"
      class=".receive.Receive"
      permission="zope2.View"
  />
</configure>

但是,当我向view()发送文本xml消息时,遇到以下错误:

  • plone在调试模型上运行,但调试无法进入渲染功能

  • 当我使用tcpdump catch plone tcp流量时,我得到了以下tcpdump:

  • 问题看起来像是plone视图无法接收post xml请求

    tcpdump out:

    微信服务器至plone:

    0x0000:4500 0101 e7c2 4000 4006 5432 7f00 0001 E....T2。。。。
    0x0010:7f00 0001 9216 1f90 e80c 8ae5 33f2 5a60………3.Z`
    0x0020:80180156 fef5 0000 0101 080a 000a 6e15…V……….n。
    0x0030:000a 6e15 3c78 6d6c 3e3c 546f 5573 6572..n。
    0x0070:3c46 726f 6d55 7365 724e 616d 653e 3c21
    
    plone至微信服务器:

    0x00d0:656e 742d 5479 7065 3a20 7465 7874 2f68 ent类型:.text/h
    0x00e0:746d 6c3b 2063 6861 7273 6574 3d75 7466 tml;。字符集=utf
    0x00f0:2d38 0d0a 0d0a 3c68 746d 6c3e 0a3c 6865-8…站点E
    0x0110:7272 6f72 3c2f 7469 746c 653e 3c2f 6865错误。。。。。
    0x0140:203c 6832 3e53 6974 6520 4572 726f 723c.Site.Error<
    0x0150:2f68 323e 0a0a 2020 3c70 3e41 6e20 6572/h2>
    0x0160:726f 7220 7761 7320 656e 636f 756e 7465 ror.was.遭遇
    0x0170:7265 6420 7768 696c 6520 7075 626c 6973红色耻骨
    0x0180:6869 6e67 2074 6869 7320 7265 736f 7572 hing.this.resourcer
    0x0190:6365 2e0a 2020 3c2f 703e 0a20 200a 2020 ce….

    。。。。。。 0x01a0:3c70 3e0a 2020 3c73 7472 6f6e…错误。类型:。Re 0x01c0:7370 6f6e 7365 4572 726f 723c 2f73 7472海绵错误
    。。。。。。。 0x01e0:3c73 7472 6f6e 673e 4572 726f 7220 5661Error.Va 0x01f0:6c75 653a 2052 6573 706f 6e73 6545 7272 lue:.响应者 0x0200:6f72 2829 3c2f 7374 726f 6e67 3e3c 6272或() 0x0210:2f3e 200a 2020 3c2f 703e 0a20 0a20 203c/>..

    < 0x0220:6872 206e 6f73 6861 6465 3d22 6e6f 7368 hr.noshade=“nosh 0x0230:6164 6522 202f 3e0a 200a 2020 3c70 3e54 ade“/>….T 0x0240:726f 7562 6c65 7368 6f6f 7469 6e67 2053卢布射击 0x0250:7567 6765 7374 696f 6e73 3c2f 703e 0a0a建议

    。。
    多谢

    我还尝试使用
    \uuu调用顺便说一句,我使用真实的浏览器代理访问(例如,IE firefox等)可能会进入
    render(self)
    函数进行调试

    您的示例代码不一致。您定义了一个名为“robot”的视图,并且正在使用一个类值“.receive.robot”.这不符合您的类定义,该类称为“接收”

    无论如何-适用于configure.zcml。receive.py文件的内容应如下所示:

    from Products.Five import BrowserView
    
    class Receive(BrowserView):
        """ some docstring """
    
        def __call__(self):
            """ gets called and returns incoming form data """
            return "this was the incoming form data: %s" % (self.request.form)
    
    使用浏览器访问视图时,应返回输入数据

    我不确定我是否正确理解了您的最后一个注意事项:如果您的代码已经在浏览器上运行,但不是通过微信服务器,那么如果请求接收到plone实例,请检查您的访问日志(通常位于$buildout home/var/log/instance-Z2.log)


    另一个问题可能是,您需要身份验证,但这取决于您的设置。您是否在呼叫的微信环境中看到任何结果?

    您是否尝试覆盖uuuu call(self)方法而不是render(self)默认情况下,
    render
    方法以
    \uuuu call\uuuu
    方法的形式被调用。您是如何注册浏览器视图的?通过zcml?您使用了
    模板
    属性,还是仅使用了
    attr?我想可能有问题,为什么您的render方法没有被执行。这就是您的代码吗?什么是
    browserv查看
    。应该是
    BrowserView
    (从五开始)事实上,当IE浏览器访问视图时,一切都正常。但是微信服务器post xml请求查看,它不工作!这是plone日志:127.0.0.1-匿名[29/Nov/2014:09:12:50+0800]“POST/xsgs998/@@robot?timestamp=1417223570&nonce=evbownvd7tqstfpxwdeguragk3zkmjni&signature=7aecdf55efe05bf6b80968848afccfa7c75f5c1http/1.1“500 1001”“Ruby”127.0.1-匿名[29/11/2014:09:30:52+0800]“GET/xsgs998/@@robot HTTP/1.1”200 816”“Mozilla/5.0“第一项是微信服务器访问日志;第二项是firefox访问日志。微信服务器post请求未到达查看功能。
    0x00d0:  656e 742d 5479 7065 3a20 7465 7874 2f68  ent-Type:.text/h
    0x00e0:  746d 6c3b 2063 6861 7273 6574 3d75 7466  tml;.charset=utf
    0x00f0:  2d38 0d0a 0d0a 3c68 746d 6c3e 0a3c 6865  -8....<html>.<he
    0x0100:  6164 3e3c 7469 746c 653e 5369 7465 2045  ad><title>Site.E
    0x0110:  7272 6f72 3c2f 7469 746c 653e 3c2f 6865  rror</title></he
    0x0120:  6164 3e0a 3c62 6f64 7920 6267 636f 6c6f  ad>.<body.bgcolo
    0x0130:  723d 2223 4646 4646 4646 223e 0a0a 0a20  r="#FFFFFF">....
    0x0140:  203c 6832 3e53 6974 6520 4572 726f 723c  .<h2>Site.Error<
    0x0150:  2f68 323e 0a0a 2020 3c70 3e41 6e20 6572  /h2>....<p>An.er
    0x0160:  726f 7220 7761 7320 656e 636f 756e 7465  ror.was.encounte
    0x0170:  7265 6420 7768 696c 6520 7075 626c 6973  red.while.publis
    0x0180:  6869 6e67 2074 6869 7320 7265 736f 7572  hing.this.resour
    0x0190:  6365 2e0a 2020 3c2f 703e 0a20 200a 2020  ce....</p>......
    0x01a0:  3c70 3e0a 2020 2020 2020 3c73 7472 6f6e  <p>.......<stron
    0x01b0:  673e 4572 726f 7220 5479 7065 3a20 5265  g>Error.Type:.Re
    0x01c0:  7370 6f6e 7365 4572 726f 723c 2f73 7472  sponseError</str
    0x01d0:  6f6e 673e 3c62 722f 3e0a 2020 2020 2020  ong><br/>.......
    0x01e0:  3c73 7472 6f6e 673e 4572 726f 7220 5661  <strong>Error.Va
    0x01f0:  6c75 653a 2052 6573 706f 6e73 6545 7272  lue:.ResponseErr
    0x0200:  6f72 2829 3c2f 7374 726f 6e67 3e3c 6272  or()</strong><br
    0x0210:  2f3e 200a 2020 3c2f 703e 0a20 0a20 203c  />....</p>.....<
    0x0220:  6872 206e 6f73 6861 6465 3d22 6e6f 7368  hr.noshade="nosh
    0x0230:  6164 6522 202f 3e0a 200a 2020 3c70 3e54  ade"./>.....<p>T
    0x0240:  726f 7562 6c65 7368 6f6f 7469 6e67 2053  roubleshooting.S
    0x0250:  7567 6765 7374 696f 6e73 3c2f 703e 0a0a  uggestions</p>..
    
    from Products.Five import BrowserView
    
    class Receive(BrowserView):
        """ some docstring """
    
        def __call__(self):
            """ gets called and returns incoming form data """
            return "this was the incoming form data: %s" % (self.request.form)