E企盈营销工具技术服务商 热线:4006-838-530

微信小程序(订阅消息)

E企盈直播平台营销卖货系统

小程序模板消息即将被废弃掉,于是有了新接口wx.requestSubscribeMessage订阅消息文档步骤:1、获取用户openid 、access_token(前面文章提到过)2、获取模板 ID3、获取下发权限(api)4、发送订阅消息 (api)模板id小程序代码:获取下发权限:// login.jsrequestMsg(){    return new Promise((resolve, reject) => {      wx.requestSubscribeMessage({        tmplIds: [“MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c”],        success: (res) => {          if (res[‘MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c’] === ‘accept’){            wx.showToast({              title: ‘订阅OK!’,              duration: 1000,              success(data) {                //成功                resolve()              }            })          }        },        fail(err) {          //失败          console.error(err);          reject()        }      })    })  }// index.wxml<button  class=”v-btn mt40″ bindtap=”sendMsg”>发生订阅消息</button>// index.js // 点击发生订阅sendMsg:function(e){    wx.request({      url: ‘https://cff.mynatapp.cc/wxXcx/sendMessage’,      method: ‘POST’,      data: { },      header: {        ‘content-type’: ‘application/json’ // 默认值      },      success(res) {        console.log(res)      }    })  }nodejs(koa2)代码:发送订阅消息://  index.jsconst router = require(‘koa-router’)()const request  = require(‘superagent’)let AppID = ‘xxxxx’let AppSecret = ‘xxxxx’let access_token = ‘xxxxx’let openid = ‘xxxxx’// 点击发生订阅消息router.post(‘/wxXcx/sendMessage’, async (ctx, next) => {    let requestData ={        “touser”: openid,        “template_id”: “MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c”,        “page”: “index”,        “data”: {            “phrase1”: {                “value”: “王小二”            },            “date5”: {                “value”: “2019年10月1日 15:01”            },            “phrase4”: {                “value”: “王老师”            },            “thing2”: {                “value”: “ps入门到精通”            },            “character_string6”: {                “value”: “1/10”            }        }      }        // 2、发送模板消息    let res = await request            .post(`https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${access_token}`)            .send(requestData)            .set(‘Accept’, ‘application/json’)      console.log(res)      ctx.body = {         code: ‘200’,         data: null,         msg: ‘操作成功’    }})

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序(订阅消息)
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏