uni-app开发支付宝小程序订阅消息

使用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>

注:具体参数及相关配置见支付宝提供的支付宝小程序消息订阅插件开发文档

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值