微信接口access_token

//调用聚合网笑话接口
$url 'http://japi.juhe.cn/joke/img/text.from?page=&pagesize=2&key=f0d06a1fe45b2d35825810b6b83bdd2d';  
$con=https_request($url);
p( $con );
 
//获取微信access_token    
$AppID 'wxb67**************';
$AppSecret 'b18566ca77661948*************';
$con=getAccessToken($AppID,$AppSecret);
p( $con );
 
//封装接口凭证access_token
    function  getAccessToken($AppID,$AppSecret){
    $url 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppID.'&secret='.$AppSecret;
              $ch = curl_init();
              /*
              //本地获取为空打开注释
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            */
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $outopt = curl_exec($ch);
            curl_close($ch);
            $con = json_decode($outopt,true);
     
              if(!isset($con['errcode'])){
                  return $con['access_token'];
              }
    }
 
//微信access_token  memcached保存
 
    $mem new Memcache;
    $mem->connect('127.0.0.1','11211');
 
    if(!$mem->get('token')){
        $AppID 'wxb67********';
        $AppSecret 'b18566ca7****************';
        $con=getAccessToken($AppID,$AppSecret);
        $mem->set('token',$con,0,7200);
    
      
 echo $con $mem->get('token') ;
 
 
//微信access_token  文件保存
 
$url 'bb.txt';
 
     if(filemtime($url)+5> time()){
       $confile_get_contents($url);
     }else{
       $AppID 'wxb67********';
        $AppSecret 'b18566ca7****************';
        $con=getAccessToken($AppID,$AppSecret);
       file_put_contents($url,$con );
         
     }
echo $con;
     
     
     
     
     
     
     
     
    

 

posted on 2016-12-27 14:42  炊厨  阅读(189)  评论(0)    收藏  举报

导航