微信小程序通知服务实现及错误47001和41028

来源:互联网 发布:linux还原备份命令 编辑:程序博客网 时间:2024/06/06 05:13

微信小程序报错47001

  • 47001 data format error
  • 请求的head必须是application/json不能是urlencode
var sendMsg = await wepy.request({  url: `https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=你的access_token`,  method: 'POST',  header: { 'content-type': 'application/json' },   //必须是json , 如果是urlencode会报47001错误  data: {    touser: openid,    template_id: '模板id在控制台获取',    page: 'pages/setting/manage-address-page',  // 用户点击消息跳转到的小程序页面    form_id: prepay_id,   //支付的prepay_id       data: {      keyword1: '123',        keyword2: 'LION '    }  }})

小程序报错41028

  • 原因是必须要在真机上测试, 不能用微信开发工具测试

微信小程序通知

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' },  data: {    touser: openid,    template_id: '微信控制台配置的模板id, 模板通常有支付成功等',    page: 'pages/index',  // 用户点击通知会跳转到的页面    form_id: prepay_id,  // 发送通知是有条件的, 这里是用支付做测试所以form_id用的是支付的prepay_id, from表单可以用    data: {      keyword1: '123',      keyword2: 'LION 狮王 CLINICA ADVANTAGE防蛀立式牙膏 柑橘薄荷型'    }  }})
原创粉丝点击