uni-app开发支付宝小程序订阅消息
使用uni-app,完成支付宝小程序订阅消息开发1、配置订阅消息插件打开uni-app项目中manifest.json配置文件,选择源码视图,在支付宝小程序配置内完成订阅消息插件配置:"mp-alipay" : {"usingComponents" : true, // 是否启用自定义组件模式"appid" : "",// 支付宝小程序appid"plugins": { // 使用到的插件"sub
·
使用uni-app,完成支付宝小程序订阅消息开发
1、配置订阅消息插件
打开uni-app项目中manifest.json
配置文件,选择源码视图,在支付宝小程序配置内完成订阅消息插件配置:
"mp-alipay" : {
"usingComponents" : true, // 是否启用自定义组件模式
"appid" : "", // 支付宝小程序appid
"plugins": { // 使用到的插件
"subscribeMsg": { // 订阅消息插件
"version": "*", // 目前只支持设置 * 拉取当前上架最新版本
"provider": "2021001155639035" // 消息订阅插件 appid
}
}
},
2、引入订阅消息插件
打开page.json
,在需要添加订阅消息的页面的style内,引入订阅消息插件:
"style": {
// #ifdef MP-ALIPAY
"usingComponents": { // 引用小程序插件
"subscribe-msg": "plugin://subscribeMsg/subscribe-msg"
}
// #endif
}
3、使用
在页面添加<subscribe-msg />
订阅消息插件,在js中引入模板消息方法,最后在需要触发的函数内调用模板消息方法,触发订阅消息弹框:
<template>
<!-- #ifdef MP-ALIPAY -->
<subscribe-msg />
<!-- #endif -->
</template>
<script>
// #ifdef MP-ALIPAY
// 引入消息模板方法
// const { requestSubscribeMessage } = requirePlugin('subscribeMsg');
// #endif
export default {
data() {
return {}
},
mounted() {
// #ifdef MP-ALIPAY
// requestSubscribeMessage({ // 触发消息订阅弹框
// entityIds: ['模板消息id1', '模板消息id2'], // 模板消息id,
// callback(res) {
// console.log(res)
// }
// })
// #endif
},
}
</script>
注:具体参数及相关配置见支付宝提供的支付宝小程序消息订阅插件开发文档
更多推荐
已为社区贡献1条内容
所有评论(0)