• 微信获取token


      /**
         * 获取微信access_token
         *
         * @param [type] $data
         * @return void
         */
        public function getAccessTokenWX($data)
        {
            $appid=trim($data['appid']);
            $appsec=trim($data['appsec']);
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsec";
            $result_info = $this->httpGet($url);
            $result = json_decode($result_info, true);
            return $result;
        }
        protected function httpGet($url,$timeout=30,$header=array())
        {
            $ch=curl_init();
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            $result=curl_exec($ch);
            return $result;
        }
        protected function httpPost($url,$data_string)
        {
            $header = [
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string)
            ];
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT,5);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $data = curl_exec($ch);
            if (curl_errno($ch)) {
                return curl_error($ch);
            }
            curl_close($ch);
            return $data;
        }
       
    
      
     /**
       * 接口次数清零
      */
        public function clearInterface()
        {
             $access_token='31_L8dZNFn6cppya0tzB4CX20j75Mjfn7kT0RCfG1Z9RtTxml-sKYrxFeTq3357gUszFQa-eSpzXa3rcEu_CE4ttKTaGTim2KB-vTT8US2g8P-dZ8iL1ScdR1MPLY1Z_ebebtmoB7MH-haWg3T8NRZjAFAXBJ';
             $url="https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=".$access_token;
             $data='
                    {
                        "appid":"wx2859f31715f7bb28"
                    }        
             ';
             $res=$this->httpPost($url,$data);
             var_dump($res);
        }
      /**
         * 获取微信access_token
         *
         * @param [type] $data
         * @return void
         */
        public function getAccessTokenWX($data)
        {
            $appid=trim($data['appid']);
            $appsec=trim($data['appsec']);
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsec";
            $result_info = $this->httpGet($url);
            $result = json_decode($result_info, true);
            return $result;
        }
        protected function httpGet($url,$timeout=30,$header=array())
        {
            $ch=curl_init();
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            $result=curl_exec($ch);
            return $result;
        }
        protected function httpPost($url,$data_string)
        {
            $header = [
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string)
            ];
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT,5);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $data = curl_exec($ch);
            if (curl_errno($ch)) {
                return curl_error($ch);
            }
            curl_close($ch);
            return $data;
        }
       
    
      
     /**
       * 接口次数清零
      */
        public function clearInterface()
        {
             $access_token='31_L8dZNFn6cppya0tzB4CX20j75Mjfn7kT0RCfG1Z9RtTxml-sKYrxFeTq3357gUszFQa-eSpzXa3rcEu_CE4ttKTaGTim2KB-vTT8US2g8P-dZ8iL1ScdR1MPLY1Z_ebebtmoB7MH-haWg3T8NRZjAFAXBJ';
             $url="https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=".$access_token;
             $data='
                    {
                        "appid":"wx2859f31715f7bb28"
                    }        
             ';
             $res=$this->httpPost($url,$data);
             var_dump($res);
        }
  • 相关阅读:
    Redis分布式锁实现
    mysql索引命中规则
    spring注解原理
    img 标签访问图片返回403forbidden
    根据注解修改属性的值
    通过反射改变对象的属性
    利用反射获取类或者方法或者字段上的注解的值
    什么时候出现死锁,如何解决?mysql 引擎? 多个like or 查询sql如何优化?什么是常量池?for条件执行顺序
    jvm 基础
    为什么要用jvm .
  • 原文地址:https://www.cnblogs.com/stj123/p/12500335.html
Copyright © 2020-2023  润新知