订阅告诉是一个用户被动订阅、服务号按需下发的告诉能力。应用过程请恪守《微信公众平台服务协定》《微信公众平台经营标准》。 用户在前述场景被动订阅后,服务号可通过接口向用户发送订阅告诉,如信用卡动账揭示、物流到货告诉等。订阅告诉分为一次性订阅和长期订阅,一次性订阅是指用户订阅一次,服务号可不限工夫公开发一条对应的订阅告诉;长期订阅是指用户订阅一次,服务号可长期屡次下发告诉,长期订阅告诉仅向政务民生、医疗等公共服务畛域凋谢。
微信订阅音讯和微信模版音讯的区别在于模版音讯能够忽视用户的主观意识,间接发给用户;而订阅音讯则必须用户批准零碎能力发给用户。这样防止了给用户带来的骚扰。
因为微信有打算应用订阅音讯来取代模版音讯,所以常识付费新增了订阅音讯性能,常识付费零碎能够抉择应用模版音讯还是订阅音讯。上面咱们就来看看常识付费是如何加订阅音讯性能的。
通过微信文档,咱们能够看到微信公众号的订阅音讯是通过wx-open-subscribe标签来调起抉择的。如下事例:
<wx-open-subscrib template=”TenvU22BA1jCp4YHfYEpRuESXYReQyDuhs4vbdWA99I” id=”subscribe-btn”>
<script type=”text/wxtag-template” slot=”style”>
<style>
.subscribe-btn {
color: #fff;
background-color: #07c160;
}
</style>
</script>
<script type=”text/wxtag-template”>
<button class="subscribe-btn">
一次性模版音讯订阅
</button>
</script>
</wx-open-subscribe>
<script>
var btn = document.getElementById(‘subscribe-btn’);
btn.addEventListener(‘success’, function (e) {
console.log(‘success’, e.detail);});
btn.addEventListener(‘error’,function (e) {
console.log(‘fail’, e.detail);
});
</script>
依据事例咱们能够理解应用wx-open-subscribe标签给template属性传入你须要弹出的订阅音讯模板ID即可,多个以英文逗号分隔。
常识付费是如何实现的呢?
首先是前端显示,在常识付费调起领取,抉择微信领取而后调起微信订阅音讯的弹窗,我的项目根目录中public/wap/first/zsff/components/payment下的index.html中咱们退出订阅音讯的标签,传入须要的模板ID。
<wx-open-subscribe
v-if="isWechat && templateId"
:template="templateId"
@success="onSuccess"
@error="onError"
<script type="text/wxtag-template" slot="style">
<style>
button {
display: block;
width: 100%;
height: 40px;
border-radius: 20px;
border: none;
background-color: #2c8eff;
font-family: inherit;
font-weight: normal;
font-size: 14px;
color: #fff;
}
</style>
</script>
<script type="text/wxtag-template">
<button>立刻领取</button>
</script>
</wx-open-subscribe>
用户抉择实现后执行订单性能,后盾依照用户的抉择后果发送相应的订阅音讯。
常识付费根目录下extend/service中的RoutineTemplateService类中加有对于微信公众号订阅音讯的全副接口,sendTemplate办法就是给用户发送订阅音讯的办法,通过这个办法咱们能够发送各种订阅音讯。
常识付费根目录application\wap\model\routine中的RoutineTemplate类里是各个订阅音讯的发送办法。如下是专题购买胜利发送的订阅音讯,其中$data中的所有索引要和微信公众号平台中加的订阅音讯内容统一。
$data[‘character_string1’][‘value’] = $orderId;
$data[‘amount3’][‘value’] = $order[‘pay_price’];
$data’time2′ = date(‘Y-m-d H:i:s’,time());
$data’thing6′ = ‘您购买的专题已领取胜利!’;
RoutineTemplate::sendOrderSuccess($data,$order[‘uid’],$site_url . Url::build(‘wap/special/grade_list’));
这样咱们就实现了微信订阅音讯性能了。
如果你感觉这篇文章对你有点用的话,麻烦请给咱们的开源我的项目点点star: http://github.crmeb.net/u/defu 不胜感激 !
发表回复