예제 #1
0
파일: Menu.php 프로젝트: ruizhengyu/wechat
 /**
  * Set menu.
  *
  * @param array $menus
  *
  * @return bool
  *
  * @throws InvalidArgumentException
  */
 public function set($menus)
 {
     if ($menus instanceof Closure) {
         $menus = $menus($this);
     }
     if (!is_array($menus)) {
         throw new InvalidArgumentException('buttons must be an array or Closure returns an array.');
     }
     $menus = $this->extractMenus($menus);
     return $this->http->json(self::API_CREATE, ['button' => $menus]);
 }
예제 #2
0
 /**
  * Send the message.
  *
  * @return bool
  *
  * @throws RuntimeException
  */
 public function send()
 {
     if (empty($this->message)) {
         throw new RuntimeException('No message to send.');
     }
     $content = $this->transformer->transform($this->message);
     $message = ['touser' => $this->to, 'msgtype' => $this->message->type, $this->message->type => $content, 'customservice' => ['kf_account' => $this->account]];
     return $this->http->json(self::API_MESSAGE_SEND, $message);
 }
예제 #3
0
 /**
  * Create a QRCode.
  *
  * @param string $actionName
  * @param array  $actionInfo
  * @param bool   $temporary
  * @param int    $expireSeconds
  *
  * @return Collection
  */
 protected function create($actionName, $actionInfo, $temporary = true, $expireSeconds = null)
 {
     $expireSeconds !== null || ($expireSeconds = 7 * self::DAY);
     $params = ['action_name' => $actionName, 'action_info' => ['scene' => $actionInfo]];
     if ($temporary) {
         $params['expire_seconds'] = min($expireSeconds, 7 * self::DAY);
     }
     return new Collection($this->http->json(self::API_CREATE, $params));
 }
예제 #4
0
 /**
  * Send the message.
  *
  * @return bool
  *
  * @throws RuntimeException
  */
 public function send()
 {
     if (empty($this->message)) {
         throw new RuntimeException('No message to send.');
     }
     $this->message->to = $this->to;
     $this->message->account = $this->account;
     $message = $this->transformer->transform($this->message);
     return $this->http->json(self::API_MESSAGE_SEND, $message);
 }
예제 #5
0
파일: Notice.php 프로젝트: raymonder/wechat
 /**
  * 发送模板消息.
  *
  * @param string $to
  * @param string $templateId
  * @param array  $data
  * @param string $url
  * @param string $color
  *
  * @return int
  *
  * @throws InvalidArgumentException
  */
 public function send($to = null, $templateId = null, array $data = [], $url = null, $color = '#FF0000')
 {
     $params = ['touser' => $to, 'template_id' => $templateId, 'url' => $url, 'topcolor' => $color, 'data' => $data];
     $required = ['touser', 'template_id'];
     foreach ($params as $key => $value) {
         if (in_array($key, $required) && empty($value) && empty($this->message[$key])) {
             throw new InvalidArgumentException("消息属性 '{$key}' 不能为空!");
         }
         $params[$key] = empty($value) ? $this->message[$key] : $value;
     }
     $params['data'] = $this->formatData($params['data']);
     $result = $this->http->json(self::API_SEND_NOTICE, $params);
     return $result['msgid'];
 }
예제 #6
0
파일: Stats.php 프로젝트: heivin/wechat
 /**
  * 查询数据.
  *
  * @param string $api
  * @param string $from
  * @param string $to
  *
  * @return array
  */
 protected function query($api, $from, $to)
 {
     $params = ['begin_date' => $from, 'end_date' => $to];
     $result = $this->http->json($api, $params);
     return $result['list'];
 }
예제 #7
0
파일: Material.php 프로젝트: heivin/wechat
 /**
  * Update article.
  *
  * @param string $mediaId
  * @param array  $article
  * @param int    $index
  *
  * @return bool
  */
 public function updateArticle($mediaId, $article, $index = 0)
 {
     $params = ['media_id' => $mediaId, 'index' => $index, 'articles' => isset($article['title']) ? $article : (isset($article[$index]) ? $article[$index] : [])];
     return $this->http->json(self::API_NEWS_UPDATE, $params);
 }
예제 #8
0
파일: Url.php 프로젝트: raymonder/wechat
 /**
  * Shorten the url.
  *
  * @param string $url
  *
  * @return string
  */
 public function shorten($url)
 {
     $params = ['action' => 'long2short', 'long_url' => $url];
     $response = $this->http->json(self::API_SHORTEN_URL, $params);
     return $response['short_url'];
 }
예제 #9
0
 /**
  * Get the access token for the given code.
  *
  * @param string $code
  *
  * @return array
  */
 public function getAccessToken($code)
 {
     return $this->http->json(self::ACCESS_TOKEN_URL, $this->getTokenFields($code));
 }
예제 #10
0
파일: Card.php 프로젝트: raymonder/wechat
 /**
  * Checkin.
  *
  * <pre>
  * $data:
  * {
  *     "code": "198374613512",
  *     "card_id":"p1Pj9jr90_SQRaVqYI239Ka1erkI",
  *     "passenger_name": "乘客姓名",
  *     "class": "舱等",
  *     "seat": "座位号",
  *     "etkt_bnr": "电子客票号", "qrcode_data": "二维码数据", "is_cancel ": false
  * }
  * </pre>
  *
  * @param string $cardId
  * @param array  $data
  *
  * @return bool
  */
 public function checkin($cardId, array $data)
 {
     $params = array_merge(['card_id' => $cardId], $data);
     return $this->http->json(self::API_BOARDING_PASS_CHECKIN, $params);
 }
예제 #11
0
파일: User.php 프로젝트: ruizhengyu/wechat
 /**
  * Get user's group id.
  *
  * @param string $openId
  *
  * @return int
  */
 public function getGroup($openId)
 {
     $params = ['openid' => $openId];
     $response = $this->http->json(self::API_GROUP, $params);
     return $response['groupid'];
 }
예제 #12
0
파일: Group.php 프로젝트: raymonder/wechat
 /**
  * Batch move users to a group.
  *
  * @param array $openIds
  * @param int   $groupId
  *
  * @return bool
  */
 public function moveUsers(array $openIds, $groupId)
 {
     $params = ['openid_list' => $openIds, 'to_groupid' => $groupId];
     return $this->http->json(self::API_MEMBER_BATCH_UPDATE, $params);
 }
예제 #13
0
파일: Manager.php 프로젝트: heivin/wechat
 /**
  * Delete a staff.
  *
  * @param string $email
  * @param string $nickname
  * @param string $password
  *
  * @return bool
  */
 public function delete($email, $nickname, $password)
 {
     $params = ['kf_account' => $email, 'nickname' => $nickname, 'password' => $password];
     return $this->http->json(self::API_DELETE . "?kf_account={$email}", $params);
 }
예제 #14
0
파일: Store.php 프로젝트: keepeye/wechat
 /**
  * Delete a store.
  *
  * @param int $storeId
  *
  * @return bool
  */
 public function delete($storeId)
 {
     $params = ['poi_id' => $storeId];
     return $this->http->json(self::API_DELETE, $params);
 }
예제 #15
0
 public function json($url, $options = [], $encodeOption = JSON_UNESCAPED_UNICODE)
 {
     $url .= (stripos($url, '?') ? '&' : '?') . 'component_access_token=' . $this->component_access_token;
     return parent::parseJSON(parent::json($url, $options, $encodeOption));
 }
예제 #16
0
 /**
  * Update a staff.
  *
  * @param string $email
  * @param string $nickname
  * @param string $password
  *
  * @return bool
  */
 public function update($email, $nickname, $password)
 {
     $params = ['kf_account' => $email, 'nickname' => $nickname, 'password' => $password];
     return $this->http->json(self::API_UPDATE, $params);
 }
예제 #17
0
 /**
  * List materials.
  *
  * example:
  *
  * {
  *   "total_count": TOTAL_COUNT,
  *   "item_count": ITEM_COUNT,
  *   "item": [{
  *             "media_id": MEDIA_ID,
  *             "name": NAME,
  *             "update_time": UPDATE_TIME
  *         },
  *         // more...
  *   ]
  * }
  *
  * @param string $type
  * @param int    $offset
  * @param int    $count
  *
  * @return array
  */
 public function lists($type, $offset = 0, $count = 20)
 {
     $params = ['type' => $type, 'offset' => intval($offset), 'count' => min(20, $count)];
     return $this->http->json(self::API_LISTS, $params);
 }
예제 #18
0
 /**
  * Get the semantic content of giving string.
  *
  * @param string       $keyword
  * @param array|string $categories
  * @param array        $other
  *
  * @return Collection
  */
 public function query($keyword, $categories, array $other = [])
 {
     $params = ['query' => $keyword, 'category' => implode(',', (array) $categories), 'appid' => $this->appId];
     return new Collection($this->http->json(self::API_SEARCH, array_merge($params, $other)));
 }