key = $str; return $this; } /** * 发送文本消息 * @param string $content 消息内容 * @return bool * @throws DtaException */ public function text(string $content = ''): bool { $this->msgType = 'text'; return $this->sendMsg([ 'text' => [ 'content' => $content, ], ]); } /** * 发送markdown消息 * @param string $content 消息内容 * @return bool * @throws DtaException */ public function markdown(string $content = '') { $this->msgType = 'markdown'; return $this->sendMsg([ 'markdown' => [ 'content' => $content, ], ]); } /** * 组装发送消息 * @param array $data 消息内容数组 * @return bool * @throws DtaException */ private function sendMsg(array $data): bool { if (empty($this->key)) { throw new DtaException("请检查KEY"); } if (empty($data['msgtype'])) { $data['msgtype'] = $this->msgType; } $result = HttpService::instance() ->url("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" . $this->key) ->data($data) ->toArray(); return $result['errcode'] === 0; } }