Beispiel #1
0
 /**
  * 获取token
  */
 public function get_accesstoken($key = 'access_token', $default = null)
 {
     \Core\Cache::init_config_params();
     $this->accesstoken = \Core\Cache::get('access_token');
     if (empty($this->accesstoken)) {
         $host = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
         $url = sprintf($host, $this->appid, $this->appsecret);
         $info = \Core\Curl::get($url);
         $respone = json_decode($info->response, true);
         if (isset($respone['access_token'])) {
             $this->accesstoken = $respone;
         }
         \Core\Cache::set('access_token', $respone);
     }
     if (!isset($this->accesstoken[$key])) {
         $this->accesstoken[$key] = $default;
     }
     return $this->accesstoken[$key];
 }
Beispiel #2
0
 private function get_jsapi_ticket($key = 'ticket', $default = null)
 {
     \Core\Cache::init_config_params();
     $this->ticket = \Core\Cache::get('jsapi_ticket');
     if (empty($this->ticket)) {
         $host = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=%s";
         $url = sprintf($host, $this->get_accesstoken());
         $info = \Core\Curl::get($url);
         $respone = json_decode($info->response, true);
         if (isset($respone['ticket'])) {
             $this->ticket = $respone;
         }
         \Core\Cache::set('jsapi_ticket', $respone);
     }
     if (!isset($this->ticket[$key])) {
         $this->ticket[$key] = $default;
     }
     return $this->ticket[$key];
 }
Beispiel #3
0
 /**
  * 请求token
  */
 public function get_accesstoken($key = 'access_token', $default = null)
 {
     \Core\Cache::init_config_params();
     $this->enterprise_accesstoken = \Core\Cache::get('enterprise_accesstoken');
     if (empty($this->enterprise_accesstoken)) {
         $host = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s';
         $url = sprintf($host, $this->corpid, $this->corpsecret);
         $info = \Core\Curl::get($url);
         $respone = json_decode($info->response, true);
         if (isset($respone['access_token'])) {
             $this->enterprise_accesstoken = $respone;
         }
         \Core\Cache::set('enterprise_accesstoken', $respone);
     }
     if (!isset($this->accesstoken[$key])) {
         $this->accesstoken[$key] = $default;
     }
     return $this->accesstoken[$key];
 }