Пример #1
0
 /**
  * 设置菜单.
  *
  * @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('子菜单必须是数组或者匿名函数返回数组', 1);
     }
     $menus = $this->extractMenus($menus);
     return $this->http->jsonPost(self::API_CREATE, ['button' => $menus]);
 }
Пример #2
0
 /**
  * 创建二维码
  *
  * @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 = array('action_name' => $actionName, 'action_info' => array('scene' => $actionInfo));
     if ($temporary) {
         $params['expire_seconds'] = min($expireSeconds, 7 * self::DAY);
     }
     return new Collection($this->http->jsonPost(self::API_CREATE, $params));
 }
Пример #3
0
 /**
  * Send the message.
  *
  * @return bool
  */
 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->jsonPost(self::API_MESSAGE_SEND, $message);
 }
Пример #4
0
 /**
  * 发送模板消息.
  *
  * @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->jsonPost(self::API_SEND_NOTICE, $params);
     return $result['msgid'];
 }
Пример #5
0
 /**
  * 获取永久素材列表.
  *
  * example:
  *
  * {
  *   "total_count": TOTAL_COUNT,
  *   "item_count": ITEM_COUNT,
  *   "item": [{
  *             "media_id": MEDIA_ID,
  *             "name": NAME,
  *             "update_time": UPDATE_TIME
  *         },
  *         //可能会有多个素材
  *   ]
  * }
  *
  * @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->jsonPost(self::API_FOREVER_LIST, $params);
 }
Пример #6
0
 /**
  * Delete a store.
  *
  * @param int $storeId
  *
  * @return bool
  */
 public function delete($storeId)
 {
     $params = ['poi_id' => $storeId];
     return $this->http->jsonPost(self::API_DELETE, $params);
 }
Пример #7
0
 /**
  * Get user's group id.
  *
  * @param string $openId
  *
  * @return int
  */
 public function getGroup($openId)
 {
     $params = ['openid' => $openId];
     $response = $this->http->jsonPost(self::API_GROUP, $params);
     return $response['groupid'];
 }
Пример #8
0
 /**
  * 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];
     $this->http->jsonPost(self::API_MEMBER_BATCH_UPDATE, $params);
     return true;
 }
Пример #9
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->jsonPost(self::API_CREATE, array_merge($params, $other)));
 }
Пример #10
0
 /**
  * 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->jsonPost(self::API_BOARDING_PASS_CHECKIN, $params);
 }
Пример #11
0
 /**
  * Shorten the url.
  *
  * @param string $url
  *
  * @return string
  */
 public function shorten($url)
 {
     $params = ['action' => 'long2short', 'long_url' => $url];
     $response = $this->http->jsonPost(self::API_SHORTEN_URL, $params);
     return $response['short_url'];
 }
Пример #12
0
 /**
  * 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->jsonPost(self::API_DELETE . "?kf_account={$email}", $params);
 }
Пример #13
0
 /**
  * 查询数据.
  *
  * @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->jsonPost($api, $params);
     return $result['list'];
 }