requestSubscribeMessage 是微信提供的方法
封装的调用requestSubscribeMessage的方法
示例图如下
import {
getWechatTemplates,
postSubscribeNotice
} from '@/magic-sdk/apis/wechat-service';
import {
WechatTemplateType,
SubscribeNoticeObjTypeOptions,
WechatTemplateEvent
} from '@/magic-sdk/types/wechat-service';
import {
getSetting,
requestSubscribeMessage /**, showToast */,
nextTick,
SubscriptionsSetting
} from '@tarojs/taro';
import Modal from '@/components/Modal/Modal';
import {
isEmpty } from 'lodash-es';
import {
captureException } from '../sentry';
import {
showSubscribeGuidePopup } from './popup';
import {
} from './platform';
export interface OtherParams {
objValue: string | number | undefined;
}
/**
* 通过类型从后端获取订阅模板id并尝试订阅
* @param type
* @returns
*/
export async function tryWechatSubscribeByType(
type: WechatTemplateType,
otherParams: OtherParams = {
objValue: undefined
},
successCb?: () => void
): Promise<boolean> {
try {
const {
data: templateList } = await getWechatTemplates(type);
const isWeapp = process.env.TARO_ENV === 'weapp';
if (!templateList || !templateList.length) {
// showToast({
title: '抱歉,暂时还未开通该订阅消息服务', icon: 'none' });
return false;
}
const templateIds = templateList.map(({ templateId }) => templateId);
const subscriptionsSetting =
(await getSubscriptionsSetting()) as SubscriptionsSetting;
const noSettings =
isWeapp