美文网首页
微信小程序&PHP 生成access_token存入缓存

微信小程序&PHP 生成access_token存入缓存

作者: 阿_莫西林 | 来源:发表于2018-03-08 17:21 被阅读0次

    注意:每个小程序都会对应后台的一系列接口。access_token一天2000次,每个有效期为2小时。所以可以保存到缓存中,每隔一段时间去获取一次。
    把appid和secret放在全局配置文件中,方便调用。

    config.php

    <?php   
    header('Content-Type:text/html;charset=utf-8');  
    *****  
    $appid='wxc59f99d22e250d53';  
    $secret='fd8688709ab4e1bxawdd46a821c2e34bd';  
    *****  
    ?>  
    

    获取access_token,后台接口

    $access_token=M::Get('q******n_'.$appid);  
    if(!$access_token){  
            $url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;  
            $json_access_token = sendCmd($url_access_token,array());  
            //access_token加缓存  
            $arr_access_token = json_decode($json_access_token,true);  
            $access_token = $arr_access_token['access_token'];  
            M::Set('q*********en_'.$appid,$access_token,3600);  
    } 
    

    相关文章

      网友评论

          本文标题:微信小程序&PHP 生成access_token存入缓存

          本文链接:https://www.haomeiwen.com/subject/dybyfftx.html