设置jsapi_ticket
@param string @param array $data  ['ticket' => 'ticket 字符串', 'expire' => 'ticket 超时时间']
557991
public function setJsApiTicket(array $data)
    {
        if (!isset($data['ticket'])) {
            throw new InvalidParamException('The wechat js api ticket must be set.');
        } elseif(!isset($data['expire'])) {
            throw new InvalidParamException('Wechat jsapi_ticket expire time must be set.');
        }
        $this->_jsApiTicket = [
            'ticket' => $data['ticket'],
            'expire' => $data['expire']
        ];
    }
920185
public function getTicket()
    {
        $key    = 'JSAPI_TICKET' . $this->getAppId();
        $ticket = $this->cache($key);
        if (!$ticket) {
            $this->module = 'ticket';
            $queryStr     = [
                'type' => 'jsapi',
            ];
            $res          = $this->_get('getticket', $queryStr, false);

            if (!$res) {
                return false;
            }

            $ticket  = $res['ticket'];
            $expires = $res['expires_in'];

            $this->cache($key, $ticket, $expires - 1000);
        }

        return $ticket;
    }
834865
public function notify(array $data = null)
    {
        if(is_null($data)) {
            $data = $_POST;
        }

        if(!$this->verifyResponse($data)) {
            throw new \Exception('回调参数签名不正确');
        }

        try {
            switch($data['status']) {
                case static::NOTIFY_STATUS_CANCELED:
                    $result = $this->notifyHandler->handleCanceled($data);
                    break;
                default:
                    $result = $this->notifyHandler->handlePaid($data);
            }

            if($result === false) {
                throw new \RuntimeException('notify failed');
            }

            return $this->success();
        } catch (\Exception $e) {
            return $this->failed();
        }
    }
855379
public function update(array $data = [])
    {
        $options = $this->parseExpress();
        $data    = array_merge($options['data'], $data);
        $pk      = $this->getPk($options);
        $where   = [];
        if (isset($options['cache']) && is_string($options['cache']['key'])) {
            $key = $options['cache']['key'];
        }

        if (empty($options['where'])) {
            // 如果存在主键数据 则自动作为更新条件
            if (is_string($pk) && isset($data[$pk])) {
                $where[$pk] = $data[$pk];
                if (!isset($key)) {
                    $key = 'think:' . $options['table'] . '|' . $data[$pk];
                }
                unset($data[$pk]);
            } elseif (is_array($pk)) {
                // 增加复合主键支持
                foreach ($pk as $field) {
                    if (isset($data[$field])) {
                        $where[$field] = $data[$field];
                    } else {
                        // 如果缺少复合主键数据则不执行
                        throw new Exception('miss complex primary data');
                    }
                    unset($data[$field]);
                }
            }
            if (!isset($where)) {
                // 如果没有任何更新条件则不执行
                throw new Exception('miss update condition');
            } else {
                $options['where']['AND'] = $where;
            }
        } elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
            $key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
        }

        //过滤无效字段
        $this->filter($data);

        // 生成UPDATE SQL语句
        $sql = $this->builder->update($data, $options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        } else {
            // 执行操作
            $result = '' == $sql ? 0 : $this->execute($sql, $bind);
            if ($result) {
                if (is_string($pk) && isset($where[$pk])) {
                    $data[$pk] = $where[$pk];
                } elseif (is_string($pk) && isset($key) && strpos($key, '|')) {
                    list($a, $val) = explode('|', $key);
                    unset($a);
                    $data[$pk]     = $val;
                }
                $options['data'] = $data;
                $this->trigger('after_update', $options);
            }
            return $result;
        }
    }
1079938
public function updateCard(array $data)
    {
        $result = $this->wechat->httpPost(self::WECHAT_CARD_LIST_GET_PREFIX, $data, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] === 'ok';
    }
882328
private static Date getExpireAt(final Ticket ticket) {
        val expirationPolicy = ticket.getExpirationPolicy();
        val ttl = ticket instanceof TicketState
            ? expirationPolicy.getTimeToLive((TicketState) ticket)
            : expirationPolicy.getTimeToLive();

        if (ttl < 1) {
            return null;
        }

        return new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(ttl));
    }
621394
protected function _before_write(&$data) {
        $pk   =  $this->getPk();
        // 根据主键类型处理主键数据
        if(isset($data[$pk]) && $this->_idType == self::TYPE_OBJECT) {
            $data[$pk] =  new \MongoId($data[$pk]);
        }    
    }
971851
public function updateIndexOne(array $data)
    {
        if (!is_array($data)) {
            throw new \Exception('你的索引参数不是一个数组');
        }

        if (count($data) == count($data, 1)) {
            // 一维数组
            $this->getIndex()->update(new \XSDocument($data));
        }

        //索引是否立即生效
        if ($this->flush_index) {
            $this->getIndex()->flushIndex();
        }

        return $this->getIndex();
    }
1187112
public function getJsCardTicket($appid = '', $jsapi_ticket = '')
    {
        if (!$this->access_token && !$this->getAccessToken()) {
            return false;
        }
        $appid = empty($appid) ? $this->appid : $appid;
        if ($jsapi_ticket) {
            return $jsapi_ticket;
        }
        $authname = 'wechat_jsapi_ticket_wxcard_' . $appid;
        if (($jsapi_ticket = Tools::getCache($authname))) {
            return $jsapi_ticket;
        }
        $result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$this->access_token}&type=wx_card");
        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());
            }
            $expire = $json['expires_in'] ? intval($json['expires_in']) - 100 : 3600;
            Tools::setCache($authname, $json['ticket'], $expire);
            return $json['ticket'];
        }
        return false;
    }
674311
public function setData(array $data)
    {
        $reservedDataKeys = array(
            'from',
            'notification',
            'to',
            'registration_ids',
            'collapse_key',
            'priority',
            'restricted_package_name',
            'content_available',
            'delay_while_idle',
            'dry_run',
            'time_to_live',
            'data',
        );

        foreach ($data as $key => $value) {

            if (!is_string($key)) {
                throw new \InvalidArgumentException('Data keys must be of type string in order to convert data in a valid JSON Object.');
            }

            if (in_array($key, $reservedDataKeys)
                || strpos($key, 'google') === 0
                || strpos($key, 'gcm') === 0
            ) {
                throw new \InvalidArgumentException(sprintf(
                    'The key "%s" is reserved or not recommended. Do not use it as data key.',
                    $key
                ));
            }

        }

        $this->data = $data;

        return $this;
    }
1356535
private function getJsApiTicket() {
        $key  = md5(__FILE__ . 'jsapi_ticket');
        $data = to_array(cache::get($key));
        if (!cache::check($key) || $data['expire_time'] < time()) {
            $accessToken = $this->getAccessToken();
            #提交URL地址
            $url  = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
            $res  = to_array($this->httpGet($url));
            $data = array();
            #返回Ticket信息
            $ticket = $res['ticket'];
            if ($ticket) {
                $data['expire_time']  = time() + 7000;
                $data['jsapi_ticket'] = $ticket;
                cache::set($key, to_json($data), 7000);
            }
        } else {
            $ticket = $data['jsapi_ticket'];
        }
        return $ticket;
    }
1167519
function push($data)
    {
        if(is_array($data) or is_object($data)) $data = serialize($data);
        //入队
        $this->data[] = $data;
        if($this->put_save) $this->save();
    }
935610
public function getJsapiTicket() {
		$time = time();
		if(empty($this->app->jsapi_ticket) || $this->app->jsapi_ticket_expired_at < $time) {
			$data = $this->getData('/cgi-bin/ticket/getticket', [
				'access_token' => $this->getAccessToken(),
				'type' => 'jsapi',
			]);
			if(isset($data['ticket']) && isset($data['expires_in'])) {
				$this->app->jsapi_ticket = $data['ticket'];
				$this->app->jsapi_ticket_expired_at = $time + $data['expires_in'];
				$this->app->save();
			}
		}

		return $this->app->jsapi_ticket;
	}
619671
public function sendDataAsJson($data) {
    $this->disableView();
    $this->setContentType('application/json', 'UTF-8');
    if (is_object($data)) {
      if (method_exists($data,'toArray'))
        $data = $data->toArray();
    }
    if (empty($data))
      $data = new \stdClass();
    
    $this->setJsonContent($data);
    $this->send();
  }
995635
public function getJsApiTicket($force = false)
    {
        $time = time(); // 为了更精确控制.取当前时间计算
        $cache_name = 'wechat_jsapi_ticket_' . $this->corpId . '_' . $this->app;
        if ($this->_jsApiTicket === null || $this->_jsApiTicket['expire'] < $time || $force) {
            $result = $this->_jsApiTicket === null && !$force ? $this->getCache($cache_name, false) : false;
            if ($result === false) {
                if (!($result = $this->requestJsApiTicket())) {
                    throw new HttpException(500, 'Fail to get jsapi_ticket from wechat server.');
                }
                $result['expire'] = $time + $result['expires_in'];
                $this->trigger(self::EVENT_AFTER_JS_API_TICKET_UPDATE, new Event(['data' => $result]));
                $this->setCache($cache_name, $result, $result['expires_in']);
            }
            $this->setJsApiTicket($result);
        }
        return $this->_jsApiTicket['ticket'];
    }
703136
private function setCookie($ticket)
	{
		$name = $this->_config['ticketName'];
		$expire_time = (int)$ticket['expire_time'];
		setcookie($name."['id']",$ticket['id'],time()+$expire_time);
		setcookie($name."['create_at']",$ticket['create_at'],time()+$expire_time);
		setcookie($name."['expire_time']",$ticket['expire_time'],time()+$expire_time);
	}
211854
public function cache_js_api_ticket($result)
    {
        if (isset($result['errcode']) && $result['errcode'] == 0 && isset($result['ticket']) && $result['ticket'] && isset($result['expires_in']) && $result['expires_in']){
            $expires_in = $result['expires_in'] - 200;
            $expires_in = $expires_in > 0 ? $expires_in : 3600;
            $this->file_cache(self::CACHE_KEY_JS_API_TICKET,$result['ticket'],$expires_in,self::CACHE_PREFIX_ACCESS_TOKEN);
        }
        return true;
    }