由于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框架写的,大家可以用在自己的写法写













