创建临时二维码
@param access_token access_token
@param expire_seconds 最大不超过604800秒（即30天）
@param scene_id		  场景值ID，32位非0整型  最多10万个
@return QrcodeTicket
13250
public static QrcodeTicket qrcodeCreateTemp(String access_token,int expire_seconds,long scene_id){
		String json = String.format("{\"expire_seconds\": %d, \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": %d}}}",expire_seconds,scene_id);
		return qrcodeCreate(access_token,json);
	}
485770
private String getAccessId(WSCredential cred) {
        String accessId = null;
        try {
            accessId = cred.getAccessId();
        } catch (CredentialExpiredException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Caught exception getting the access id: " + e);
            }
        } catch (CredentialDestroyedException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Caught exception getting the access id: " + e);
            }
        }
        // TODO if ignoreCase is Collection, then lower case the accessid
        return accessId;
    }
1168347
public function getOauthAuth($access_token, $openid)
    {
        $result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_AUTH_URL . "access_token={$access_token}&openid={$openid}");
        if ($result) {
            $json = json_decode($result, true);
            if (empty($json) || !empty($json['errcode'])) {
                $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
                $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容！';
                Tools::log("WechatOauth::getOauthAuth Fail.{$this->errMsg} [{$this->errCode}]", "ERR - {$this->appid}");
                return false;
            } elseif (intval($json['errcode']) === 0) {
                return true;
            }
        }
        return false;
    }
673817
public function vaildAccessToken(string $access_token, string $open_id)
    {
        $data = [
            'access_token' => $access_token,
            'openid' => $open_id,
        ];
        $url = self::WECHAT.'auth?'.http_build_query($data);
        $data = $this->curl->get($url);

        return Response::json($data);
    }
260068
protected final Date getExpiration(RenderRequest renderRequest) {
        // Expiration of the JWT
        final PortletSession portletSession = renderRequest.getPortletSession();
        final Date rslt =
                new Date(
                        portletSession.getLastAccessedTime()
                                + ((long) portletSession.getMaxInactiveInterval() * 1000L));
        return rslt;
    }
959333
protected void updateOAuthCode(final AccessTokenRequestDataHolder holder) {
        if (holder.getToken() instanceof OAuthCode) {
            val codeState = TicketState.class.cast(holder.getToken());
            codeState.update();

            if (holder.getToken().isExpired()) {
                this.ticketRegistry.deleteTicket(holder.getToken().getId());
            } else {
                this.ticketRegistry.updateTicket(holder.getToken());
            }
            this.ticketRegistry.updateTicket(holder.getTicketGrantingTicket());
        }
    }
940082
public static String getPerpetualQR_senceId(String access_token, int senceId) {
		// 获取数据的地址（微信提供）
		String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + access_token;
		JsonObject content = new JsonObject();
		content.addProperty("action_name", "QR_LIMIT_SCENE");
		JsonObject scene = new JsonObject();
		scene.addProperty("scene_id", senceId);
		JsonObject action_info = new JsonObject();
		action_info.add("scene", scene);
		content.add("action_info", action_info);
		// 发送给微信服务器的数据
		String jsonStr = content.toString();
		String qrurl = null;
		try {
			HttpUtil http = new HttpUtil();
			byte[] data = http.httpsPost(url, jsonStr.getBytes());
			JsonObject json = new JsonParser().parse(new String(data)).getAsJsonObject();
			qrurl = json.get("url").getAsString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return qrurl;
	}
73136
public function componentAccessToken() {
        $key  = md5(__FILE__ . 'component_access_token');
        $data = to_array(cache::get($key));
        if (!cache::check($key) || $data['expire_time'] < time()) {
            #提交URL地址
            $url  = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
            $data = array(
                "component_appid"         => C("wechat", "componentAppid"),
                "component_appsecret"     => C("wechat", "componentSecret"),
                "component_verify_ticket" => $this->getComponentVerifyTicket(),
            );
            $res = to_array($this->httpPost($url, $data));
            #返回Token信息
            $access_token = $res['component_access_token'];
            if ($access_token) {
                $data['expire_time']            = time() + 7000;
                $data['component_access_token'] = $access_token;
                cache::set($key, to_json($data), 7000);
            }
        } else {
            $access_token = $data['component_access_token'];
        }
        return $access_token;
    }
639400
function (model) {
              var tokenCode = 'token-' + md5(new Date().toString()) + md5(model.id + Math.random().toString());
              var redisExpire = (global._gluon_auth_expire) >>> 0; //redis using seconds not milliseconds
              return redisClient.setAsync(tokenCode, JSON.stringify(model.toJSON())).then(function () {
                return redisClient.expireAsync(tokenCode, redisExpire);
              }).then(function () {
                return {code: tokenCode, expire: new Date(Date.now() + redisExpire * 1000)};
              });
            }
522544
def _parse_access_token(self, r):
        '''
        
        '''
        current = int(time.time())
        expires = r.expires_in + current
        remind_in = r.get('remind_in', None)
        if remind_in:
            rtime = int(remind_in) + current
            if rtime < expires:
                expires = rtime
        return JsonDict(access_token=r.access_token, expires=expires, expires_in=expires, uid=r.get('uid', None))
1199672
def access_token(self):
        
        if (self._access_token is None or
                self.expiration_time <= int(time.time())):
            resp = self.make_access_request()
            self._access_token = resp.json()['access_token']

        return self._access_token
1292837
def get_jsapi_ticket(self):
        
        ticket_key = '{0}_jsapi_ticket'.format(self.appid)
        expires_at_key = '{0}_jsapi_ticket_expires_at'.format(self.appid)
        ticket = self.session.get(ticket_key)
        expires_at = self.session.get(expires_at_key, 0)
        if not ticket or expires_at < int(time.time()):
            jsapi_ticket_response = self.get_ticket('jsapi')
            ticket = jsapi_ticket_response['ticket']
            expires_at = int(time.time()) + int(jsapi_ticket_response['expires_in'])
            self.session.set(ticket_key, ticket)
            self.session.set(expires_at_key, expires_at)
        return ticket
1170446
public function getQRCode($scene_id,$type=0,$expire=1800){
		if (!$this->access_token && !$this->checkAuth()) return false;
		$type = ($type && is_string($scene_id))?2:$type;
		$data = array(
			'action_name'=>$type?($type == 2?"QR_LIMIT_STR_SCENE":"QR_LIMIT_SCENE"):"QR_SCENE",
			'expire_seconds'=>$expire,
			'action_info'=>array('scene'=>($type == 2?array('scene_str'=>$scene_id):array('scene_id'=>$scene_id)))
		);
		if ($type == 1) {
			unset($data['expire_seconds']);
		}
		$result = $this->http_post(self::API_URL_PREFIX.self::QRCODE_CREATE_URL.'access_token='.$this->access_token,self::json_encode($data));
		if ($result)
		{
			$json = json_decode($result,true);
			if (!$json || !empty($json['errcode'])) {
				$this->errCode = $json['errcode'];
				$this->errMsg = $json['errmsg'];
				return false;
			}
			return $json;
		}
		return false;
	}
1026665
protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth) {
		if (clientDetailsService != null) {
			ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
			Integer validity = client.getAccessTokenValiditySeconds();
			if (validity != null) {
				return validity;
			}
		}
		return accessTokenValiditySeconds;
	}
230784
public function getAccessToken($access_token)
	{
		// create access token
		$token = \Components\Developer\Models\Accesstoken::oneByToken($access_token);

		// make sure we have a token
		if (!$token->get('id'))
		{
			return false;
		}

		// make sure its a published token
		if (!$token->isPublished())
		{
			return false;
		}

		// get the application's client id
		$application = \Components\Developer\Models\Application::oneOrFail($token->get('application_id'));
		$token->set('client_id', $application->get('client_id'));

		// format expires to unix timestamp
		$token->set('expires', with(new Date($token->get('expires')))->toUnix());

		// return token
		return $token->toArray(true);
	}
816090
def _fetch_access_token(self, url, data):
        
        logger.info('Fetching component access token')
        res = self._http.post(
            url=url,
            data=data
        )
        try:
            res.raise_for_status()
        except requests.RequestException as reqe:
            raise WeChatClientException(
                errcode=None,
                errmsg=None,
                client=self,
                request=reqe.request,
                response=reqe.response
            )
        result = res.json()
        if 'errcode' in result and result['errcode'] != 0:
            raise WeChatClientException(
                result['errcode'],
                result['errmsg'],
                client=self,
                request=res.request,
                response=res
            )

        expires_in = 7200
        if 'expires_in' in result:
            expires_in = result['expires_in']
        self.session.set(
            'component_access_token',
            result['component_access_token'],
            expires_in
        )
        self.expires_at = int(time.time()) + expires_in
        return result
1026320
public function getJsTicket($appid = '', $jsapi_ticket = '', $access_token = '')
    {
        if (empty($access_token)) {
            if (!$this->access_token && !$this->getAccessToken()) {
                return false;
            }
            $access_token = $this->access_token;
        }
        if (empty($appid)) {
            $appid = $this->appid;
        }
        # 手动指定token，优先使用
        if ($jsapi_ticket) {
            $this->jsapi_ticket = $jsapi_ticket;
            return $this->jsapi_ticket;
        }
        # 尝试从缓存中读取
        $cache = 'wechat_jsapi_ticket_' . $appid;
        $jt = Tools::getCache($cache);
        if ($jt) {
            return $this->jsapi_ticket = $jt;
        }
        # 检测事件注册
        if (isset(Loader::$callback[__FUNCTION__])) {
            return $this->jsapi_ticket = call_user_func_array(Loader::$callback[__FUNCTION__], array(&$this, &$cache));
        }
        # 调接口获取
        $result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$access_token}" . '&type=jsapi');
        if ($result) {
            $json = json_decode($result, true);
            if (empty($json) || !empty($json['errcode'])) {
                $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
                $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容！';
                return $this->checkRetry(__FUNCTION__, func_get_args());
            }
            $this->jsapi_ticket = $json['ticket'];
            Tools::setCache($cache, $this->jsapi_ticket, $json['expires_in'] ? intval($json['expires_in']) - 100 : 3600);
            return $this->jsapi_ticket;
        }
        return false;
    }