微信开发——python获取开放平台的component_verify_ticket

第三方平台创建的时候填写了如下参数:


第三方平台创建成功后,微信会定时每隔10分钟发送一次ComponentVerifyTicket,只需要在“授权事件接收URL”对应的方法里接收就行(发送的是post请求)。具体接收python代码参考如下

#微信每隔10分钟推送一次
class WxOpenCallbackHandler(tornado.web.RequestHandler):
    def post(self):
        request = self.request.arguments
        if request.has_key("msg_signature"):
            msg_signature = self.get_argument('msg_signature')
            timestamp = self.get_argument('timestamp')
            nonce = self.get_argument('nonce')
            decrypt_test = WXBizMsgCrypt(WXTHIRD_APP_TOKEN, WXTHIRD_ENCODINGAESKEY, WXTHIRD_APP_ID)
            ret, decryp_xml = decrypt_test.DecryptMsg(self.request.body, msg_signature, timestamp, nonce)
            ticket_xml = ET.fromstring(decryp_xml)
            infoType = ticket_xml.find('InfoType').text
            if infoType == 'component_verify_ticket':
                COMPONENTVERIFYTICKET = ticket_xml.find('ComponentVerifyTicket').text
            print "COMPONENTVERIFYTICKET = ", COMPONENTVERIFYTICKET

这里WXBizMsgCrypt,直接在微信提供的demo里下载,WXTHIRD_APP_TOKEN, WXTHIRD_ENCODINGAESKEY, WXTHIRD_APP_ID,都在第三方平台详情里能查到

没有更多推荐了,返回首页