前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信公众号-关注与取关

微信公众号-关注与取关

作者头像
星哥玩云
发布2022-09-14 18:23:52
8760
发布2022-09-14 18:23:52
举报
文章被收录于专栏:开源部署

当用户关注和取消关注时MsgType的类型均为event,我们可以在此时进行一些业务处理

接收样例:

代码语言:javascript
复制
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>
代码语言:javascript
复制
<span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render, HttpResponse
<span class="hljs-keyword">from</span> django.views.decorators.csrf <span class="hljs-keyword">import</span> csrf_exempt

<span class="hljs-keyword">import</span> hashlib
<span class="hljs-keyword">import</span> xmltodict
<span class="hljs-keyword">import</span> time

<span class="hljs-keyword">from</span> myApp.accessToken <span class="hljs-keyword">import</span> AccessToken

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">(request)</span>:</span>
    <span class="hljs-keyword">pass</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">responseXML</span><span class="hljs-params">(ToUserName, FromUserName, MsgType, **kwargs)</span>:</span>
    <span class="hljs-keyword">pass</span>

<span class="hljs-meta">@csrf_exempt</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">weixin</span><span class="hljs-params">(request)</span>:</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">"GET"</span>:
        <span class="hljs-keyword">pass</span>
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">pass</span>

        <span class="hljs-keyword">if</span> MsgType == <span class="hljs-string">"text"</span>:
            <span class="hljs-keyword">pass</span>
        <span class="hljs-keyword">elif</span> MsgType == <span class="hljs-string">"event"</span>:
            Event = reqDict.get(<span class="hljs-string">"Event"</span>)
            <span class="hljs-keyword">if</span> Event == <span class="hljs-string">"subscribe"</span>:
                <span class="hljs-comment"># 业务逻辑</span>
                resXml = responseXML(FromUserName, ToUserName, <span class="hljs-string">"text"</span>, Content=<span class="hljs-string">"欢迎光临红浪漫,三楼男宾一位"</span>)
                <span class="hljs-keyword">return</span> HttpResponse(resXml)
            <span class="hljs-keyword">elif</span> Event == <span class="hljs-string">"unsubscribe"</span>:
                <span class="hljs-comment"># 业务逻辑</span>
                <span class="hljs-keyword">return</span> HttpResponse(<span class="hljs-string">""</span>)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">pass</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">access</span><span class="hljs-params">(request)</span>:</span>
    <span class="hljs-keyword">pass</span>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档