Esempio n. 1
0
 /**
  * 返回json
  *
  * @return string
  */
 public function toJson()
 {
     return JSON::encode($this->all());
 }
Esempio n. 2
0
 /**
  * 生成 js添加到卡包 需要的 card_list 项
  *
  * @param string $cardId
  * @param array  $extension
  *
  * @return string
  */
 public function attachExtension($cardId, array $extension = array())
 {
     $timestamp = time();
     $ext = array('code' => Arr::get($extension, 'code'), 'openid' => Arr::get($extension, 'openid', Arr::get($extension, 'open_id')), 'timestamp' => $timestamp, 'outer_id' => Arr::get($extension, 'outer_id'), 'balance' => Arr::get($extension, 'balance'));
     $ext['signature'] = $this->getSignature($this->getTicket(), $timestamp, $cardId, $ext['code'], $ext['openid'], $ext['balance']);
     return array('card_id' => $cardId, 'card_ext' => JSON::encode($ext));
 }
Esempio n. 3
0
 /**
  * Make a HTTP request
  *
  * @param string $url
  * @param string $method
  * @param array  $params
  * @param array  $options
  *
  * @return array
  */
 protected function request($url, $method = self::GET, $params = array(), $options = array())
 {
     if ($method === self::GET || $method === self::DELETE) {
         $url .= (stripos($url, '?') ? '&' : '?') . http_build_query($params);
         $params = array();
     }
     curl_setopt($this->curl, CURLOPT_HEADER, 1);
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($this->curl, CURLOPT_URL, $url);
     curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
     // Check for files
     if (isset($options['files']) && count($options['files'])) {
         foreach ($options['files'] as $index => $file) {
             $params[$index] = $this->createCurlFile($file);
         }
         version_compare(PHP_VERSION, '5.5', '<') || curl_setopt($this->curl, CURLOPT_SAFE_UPLOAD, false);
         curl_setopt($this->curl, CURLOPT_POST, 1);
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
     } else {
         if (isset($options['json'])) {
             $params = JSON::encode($params);
             $options['headers'][] = 'content-type:application/json';
         }
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
     }
     // Check for custom headers
     if (isset($options['headers']) && count($options['headers'])) {
         curl_setopt($this->curl, CURLOPT_HTTPHEADER, $options['headers']);
     }
     // Check for basic auth
     if (isset($options['auth']['type']) && 'basic' === $options['auth']['type']) {
         curl_setopt($this->curl, CURLOPT_USERPWD, $options['auth']['username'] . ':' . $options['auth']['password']);
     }
     $response = $this->doCurl();
     // Separate headers and body
     $headerSize = $response['curl_info']['header_size'];
     $header = substr($response['response'], 0, $headerSize);
     $body = substr($response['response'], $headerSize);
     $results = array('curl_info' => $response['curl_info'], 'content_type' => $response['curl_info']['content_type'], 'status' => $response['curl_info']['http_code'], 'headers' => $this->splitHeaders($header), 'data' => $body);
     return $results;
 }
Esempio n. 4
0
 /**
  * 上传视频
  *
  * 有点不一样。。。
  *
  * @param string $path
  * @param string $title
  * @param string $description
  *
  * @return string
  */
 public function video($path, $title, $description)
 {
     $params = array('description' => JSON::encode(array('title' => $title, 'introduction' => $description)));
     return $this->upload('video', $path, $params);
 }
Esempio n. 5
0
File: SDK.php Progetto: Gwill/wechat
 /**
  * Get config json for jsapi.
  *
  * @param array $APIs
  * @param bool  $debug
  * @param bool  $beta
  * @param bool  $json
  *
  * @return array|string
  */
 public function config(array $APIs, $debug = false, $beta = false, $json = true)
 {
     $signPackage = $this->getSignaturePackage();
     $base = array('debug' => $debug, 'beta' => $beta);
     $config = array_merge($base, $signPackage, array('jsApiList' => $APIs));
     return $json ? JSON::encode($config) : $config;
 }