微信小程序> 微信自动发消息,微信小程序完整开发小程序模板消息,定时发送,附前台后台源码数据库参考

微信自动发消息,微信小程序完整开发小程序模板消息,定时发送,附前台后台源码数据库参考

浏览量:1195 时间: 来源:weixin_44069250
首先第一步,获取access_token这个access_token需要去微信公众平台去获取
由于access_tokem是有过期时间的也就是2个小时,所以咱们需要新建一个数据库来存储这些access_token判断是否过期zhe
这是数据库结构
接下来我们需要写一下后端代码
publicfunctiongetaccess_token(){$appid='';$appsecret='';//这两个可以从微信公众平台获取}下一步贴一下代码,基本粘贴过去就能用的,换上自己的表跟字段
publicfunctiongetaccess_token(){$appid='';$appselect='';//这两个可以从微信公众平台获取$sql=Db::table('xdk_token')-where(['appid'=$appid,'appselect'=$appselect])-find();$now=time();//获取当前时间戳if($now-$sql['apptime']7000){$token=$sql['token'];return$token;}else{$token_access="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appselect";//执行请求file_get_contents$tokens=file_get_contents($token_access);//JSON转换$tokening=json_decode($tokens);$token=$tokening-access_token;//获取Token字段值$data=['token'=$token,'apptime'=$now,'appid'=$appid,'appselect'=$appselect];Db::table('xdk_token')-insert($data);return$token;}}我这里是用的TP5框架写的,大家可以用在自己的写法写

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎