tmplIdMessage.js
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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,
}