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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| data: { code: '', templateid: '', appid:'', openid:'' }, onLoad(){ let that = this that.onCode() setTimeout(() => { wx.showModal({ title: '提示', content: '是否订阅XXXX消息', success(res) { if (res.confirm) { console.log('用户点击确定') that.onTake() } else if (res.cancel) { console.log('用户点击取消') that.onTake() } } }) }, 3000) }
onCode() { console.log('开始获取Code'); let that = this wx.login({ timeout: 10000, success: (res) => { console.log(res); that.setData({ code: res.code }) }, }) }, onTake() { console.log('开始订阅'); let that = this let accountInfo = wx.getAccountInfoSync(); let appid = accountInfo.miniProgram.appId; wx.request({ url: 'https://newsaas.guangzhouzhuangxiu01.cn/api/xcx/index/xcxsubtemplate', data: { wxappid: appid }, success(res) { console.log(res.data[0]); that.setData({ templateid: res.data[0].templateid, appid, }) wx.requestSubscribeMessage({ tmplIds: [that.data.templateid], success(res) { if (res[that.data.templateid] === 'accept') { console.log('用户同意了') wx.request({ url: 'https://newsaas.guangzhouzhuangxiu01.cn/api/xcx/index/getwxopenid', data:{ name: '', appId: appid, secret: '132', tmplIds: that.data.templateid, code: that.data.code }, success(res1){ console.log('订阅完成:', res1); wx.showToast({ title: '订阅OK!', duration: 1000, }) that.setData({ openid: res1.data.openid }) } }) } }, }) } }) },
|