微信公开课
微信公开课小程序热门讨论关于「用云函数怎么实现模板消息」的小程序开发问题
补充:用云函数怎么实现模板消息
展开:现在用小程序云开发需要用到模板消息,研究了模板消息需要用客户端获取tocken,再获取模板消息利用云开发如何实现模板消息即速小程序:模板消息与统一服务消息教程:https:githubcomTencentCloudBasempbookblobmasterbasictutorialmessagemd如果需要缓存access_token,可考虑使用云开发的数据库:建议在小程序打开的时候就获取access_token,要不然你会频繁的获取access_token,官方不建议这样:我之前写了个测试发消息的云函数,希望能帮到你:npminstallrequestpromise安装requestpromise命令constrp=require(requestpromise);appid和秘钥constappid=wxxxxxxxx,secret=xxxxxxxxxxxx;constAccessToken_options={method:GET,url:https:apiweixinqqcomcgibintoken,qs:{appid,secret,grant_type:client_credential},json:true};获取AccessTokenconstresultValue=awaitrp(AccessToken_options);consttoken=resultValueaccess_token;constbody={touser:OPENID,template_id:TEMPLATE_ID,page:index,form_id:FORMID,data:{ keyword1:{ value:339208499 }, keyword2:{ value:2015年01月05日12:30 }, keyword3:{ value:腾讯微信总部 }, keyword4:{ value:广州市海珠区新港中路397号 }},emphasis_keyword:keyword1DATA}constsend={method:POST,url:https:apiweixinqqcomcgibinmessagewxopentemplatesend?access_token=+toke,body,json:true};constsend_res=awaitrp(send);
更多有关「用云函数怎么实现模板消息」的讨论可以前往微信公开课小程序参与互动哦!了解更多