getApi() protected static method

protected static getApi ( )
Esempio n. 1
0
 /**
  * 公众号用于调用微信JS接口的临时票据
  *
  * http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
  * jsapi_ticket 的type为jsapi (腾讯demo中的JSSDK.php代码中type为1 不知为何)
  * 卡券 api_ticket 的type为 wx_card
  *
  * @param string $type
  * @return string
  */
 public static function getJsApiTicket($type = 'jsapi')
 {
     $cacheKey = parent::getApi()->getAppId() . $type . 'jsapi_ticket';
     $ticket = Cache::get($cacheKey);
     if ($ticket !== false) {
         return $ticket;
     }
     $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=ACCESS_TOKEN";
     $data = parent::request($url);
     $ticket = $data['ticket'];
     //jsapi_ticket的有效期为7200秒
     Cache::set($cacheKey, $ticket, $data['expires_in'] - 200);
     return $ticket;
 }
Esempio n. 2
0
 /**
  * 网页授权获取用户基本信息 流程第2步 通过code换取网页授权access_token
  * @param $code
  * @return array
  * [
  *      "access_token"=>"ACCESS_TOKEN",
  *      "expires_in"=>7200,    //access_token接口调用凭证超时时间,单位(秒)
  *      "refresh_token"=>"REFRESH_TOKEN",
  *      "openid"=>"OPENID",
  *      "scope"=>"SCOPE"
  * ]
  */
 public static function getOauthAccessToken($code)
 {
     $appId = parent::getApi()->getAppId();
     $secret = parent::getApi()->getAppSecret();
     $grant_type = 'authorization_code';
     $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appId}&secret={$secret}&code={$code}&grant_type={$grant_type}";
     return parent::request($url);
 }