/**
  * Unsubscribe the event or message type
  * @param string $module the module name
  * @param string $channel the wechat account id
  * @param string $dataType the data type of event type from WeConnect
  * @param integer $startAt the start time timestamp
  * @param string $type event or message type
  * @return boolean Whether the event or message is unsubscribed successfully
  */
 private function unsubscribe($module, $channel = '', $dataType = '', $startAt = 0, $type)
 {
     $this->validateParameters($module, $channel, $dataType, $type);
     $condition = ['module' => $module, 'channel' => $channel];
     if (!empty($type) && !empty($dataType)) {
         $condition['type'] = $type . '-' . $dataType;
     }
     if (!empty($startAt)) {
         $condition['startAt'] = new \MongoDate($startAt);
     }
     $funciton = [Yii::$app->weConnect, 'update' . ucfirst($type) . 'WebhookRule'];
     //transform inconsistent event name for weconnect API
     if (WebhookEvent::DATA_TYPE_MSG_SHORT_VIDEO === $dataType) {
         $dataType = 'SHORT_VIDEO';
     }
     call_user_func($funciton, $channel, strtoupper($dataType), self::DISABLE_ACTION);
     $deletedCount = WebhookEvent::deleteAll($condition);
     return $deletedCount > 0;
 }
示例#2
0
 /**
  * This function is provided to update evet type webhook rule.
  * @param $accountId, string
  * @return boolean
  */
 public function enableEventWebhookRules($accountId)
 {
     $url = $this->weconnectDomain . "/accounts/{$accountId}/webhookRules";
     $data = WebhookEvent::getWebhookRuleData(WebhookEvent::ENABLE_RULE);
     return $this->_curl(self::METHOD_POST, $url, 'channel', $data);
 }