按发送消息模板接口操作48001求助大神
发布于 6 年前 作者 fang05 7272 次浏览 来自 问答

获取access token后,缓存在本地,自己更新

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

表单提交时替换accesstoken

https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN


表单

<form name=‘pushMsgFm’ report-submit bindsubmit=‘orderSign’>  

   enter product:<input type=“text” name=“product” value=’’ placeholder=“enter your name” />  

   detail: <input type=“text” name=‘detail’ placeholder=“enter desc” />  

   select sex:<switch type=“switch” name=‘sex’ />  

   <button form-type=“submit”>submit</button>  

</form>  

js代码

orderSign: function (e) {

   var fId = e.detail.formId;

   console.log(fId);

   var fObj = e.detail.value;

   var l = https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token= + ‘’;

   var d = {

     touser: ‘’,

     template_id: ‘’,  

     form_id: fId,

     page: “index”,

     data: {

       “keyword1”: {

         “value”: fObj.product,

         “color”: “#4a4a4a”

       },

       “keyword2”: {

         “value”: fObj.detail,

         “color”: “#9b9b9b”

       },

       “keyword3”: {

         “value”: new Date().getDate(),

         “color”: “#9b9b9b”

       },

       “keyword4”: {

         “value”: “201612130909”,

         “color”: “#9b9b9b”

       },

       “keyword5”: {

         “value”: “$300”,

         “color”: “#9b9b9b”

       },

       “keyword6”: {

         “value”: “$300”,

         “color”: “#9b9b9b”

       },

       “keyword7”: {

         “value”: “$300”,

         “color”: “#9b9b9b”

       },

       “keyword8”: {

         “value”: “$300”,

         “color”: “#9b9b9b”

       }

     },

     color: ‘#ccc’,

     emphasis_keyword: ‘keyword1.DATA’

   }

   console.log(d)

   wx.request({

     url: l,

     data: d,

     method: ‘POST’,

     success: function (res) {

       console.log(“push msg”);

       console.log(res);

     },

     fail: function (err) {

       // fail  

       console.log(“push err”)

       console.log(err);

     }

   });

 }

后台发送模板消息是48001错误,网上找了个demo试验还是错误,求助

回到顶部