微信小程序常用代码

来源:互联网 发布:java程序设计大学课本 编辑:程序博客网 时间:2024/06/03 13:33

微信的通知服务

var access_token = await wepy.request({  url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=小程序的appid&secret=小程序的secret`,  method: 'GET',  header: { 'content-type': 'application/json' }})var sendMsg = await wepy.request({  url: `https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=${access_token    .data.access_token}`,  method: 'POST',  header: { 'content-type': 'application/json' },   //必须是json , 如果是urlencode会报错  data: {    touser: openid,    template_id: '模板id在控制台获取',    page: 'pages/setting/manage-address-page',    form_id: prepay_id,   //支付的prepay_id    data: {      keyword1: '123',        keyword2: 'LION '    }  }})

微信的客服服务

<contact-button   type="default-light"   size="20"  session-from="weapp"></contact-button>微信管理平台设置后台客服的微信, 消息会自动推送到指定的微信

微信自带弹框

wx.showModal({  title: '确认收货?',  confirmText: '确认',  confirmColor: '#ffde00',  success: function(res) {    if (res.confirm) {      changeOrderStatus(e.currentTarget.id, 4).then(res => {        this.toDoWhatUShouldDo(e, 4)      })    } else if (res.cancel) {      console.log('用户点击取消收货')    }  },  fail: function() {}})
原创粉丝点击