美文网首页
微信小程序

微信小程序

作者: define光年 | 来源:发表于2019-08-26 10:28 被阅读0次

    获取access-token

     /**
         * [getinfo 获取access-token]
         * @return [type] [description]
         */
        public function getinfo(){
             $output=self::get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".self::$appid."&secret=".self::$appsecret);
             echo $output;
             exit();
    
        }
        /**
         * [get curl 请求]
         * @param  [string] $url [路径]
         * @return [json]      [{"access_token":"xxxxxxxxxx","expires_in":7200}]
         */
         public static function get($url) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            # curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    
            if (!curl_exec($ch)) {
                error_log(curl_error($ch));
                $data = '';
            } else {
                $data = curl_multi_getcontent($ch);
            }
            curl_close($ch);
            return $data;
        }

    相关文章

      网友评论

          本文标题:微信小程序

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