微信access_token

微信access_token
    function get_access_token() {
        $key = ‘access_token‘;
        $access_token = Session::get($key);
        if (!empty($access_token) && $access_token !== false)
            return $access_token;
        
        $corp_info=C(‘wxinfo‘);
        // var_dump ($corp_info);
        
        $corp_id = $corp_info[‘CorpID‘];
        $Secret  = $corp_info[‘Secret‘];
        
        if (empty ( $corp_id ) || empty ( $Secret )) {
            Session::set($key, 0, 7200); 
            return 0;
        }
        $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corp_id}&corpsecret={$Secret}";
        $tempArr = json_decode ( file_get_contents ( $url ), true );
        if (@array_key_exists ( $key, $tempArr )) {
            
            Session::set($key, $tempArr [‘access_token‘], 7200); 
            return $tempArr [‘access_token‘];
            
        } else {
            return 0;
        }
    }
View Code

 

微信access_token

上一篇:微信模板消息接口、微信客服接口


下一篇:关于微信 公众号相关问题记录