tmplIdMessage.js 1.28 KB

import { API_HOST, SERVICE_HOST } from './config';
import { GET, POST } from './request';

function postTmplId(params) {
  let app = getApp();
  let that = this;
  //如果没有uid,不上报,否则接口报500
  if (!app.getUid() || params.tmplIds.length === 0) return
  return new Promise(resolve => {
    wx.requestSubscribeMessage({
      tmplIds: params.tmplIds,
      success(res) {
        console.log(res)
        let tmplIds = res
        delete tmplIds.errMsg
        tmplIds = JSON.stringify(tmplIds)
        //上报tmplIds
        let tmplIdParams = {
          uid: app.getUid(),
          openId: app.getOpenID(),
          miniAppType: app.globalData.miniapp_type,
          templateIds: tmplIds,
          method: 'mini.subscribe.add',
        }
        console.log('params', tmplIdParams)
        GET(API_HOST, tmplIdParams).then(res => {
          resolve(res)
       })
      },
      fail(res) {
        console.log(res)
        wx.showToast({
          title: res.errCode===20004 ? '消息未开启 请点击右上角,打开设置,开启消息': res.errMsg,
          icon: 'none',
          duration: 3000,
        })
        setTimeout(function() {
          resolve()
        }, 3000)
      }
    })
  })

}

export {
  postTmplId,
}