/** * @param Container $pimple * @return \Closure */ protected function getTestMessageHandler(Container $pimple) { return function ($message) use($pimple) { if (in_array($message->MsgType, ['text', 'image', 'voice'], false)) { if ($message->Content === 'TESTCOMPONENT_MSG_TYPE_TEXT') { return $message->Content . '_callback'; } else { $queryAuthCode = ltrim($message->Content, 'QUERY_AUTH_CODE:'); $accessToken = new TestAccessToken($pimple['open_platform'], $queryAuthCode); $staff = new Staff($accessToken); $text = new Text(['content' => $queryAuthCode . '_from_api']); $staff->message($text)->to($message->FromUserName)->send(); return null; } } elseif ($message->MsgType === 'event') { return $message['Event'] . 'from_callback'; } }; }
/** * Send the message. * * @return bool * * @throws RuntimeException */ public function send() { if (empty($this->message)) { throw new RuntimeException('No message to send.'); } $transformer = new Transformer(); $content = $transformer->transform($this->message); $message = array_merge(['touser' => $this->to, 'msgtype' => $this->message->type, 'customservice' => ['kf_account' => $this->account]], $content); return $this->staff->send($message); }
/** * Send the message. * * @return bool * * @throws RuntimeException */ public function send() { if (empty($this->message)) { throw new RuntimeException('No message to send.'); } $transformer = new Transformer(); if ($this->message instanceof RawMessage) { $message = $this->message->get('content'); } else { $content = $transformer->transform($this->message); $message = array_merge(['touser' => $this->to, 'customservice' => ['kf_account' => $this->account]], $content); } return $this->staff->send($message); }