keywords = $keywords; } /** * @param string $templateId */ public function setTemplateId(string $templateId) { $this->templateId = $templateId; } /** * @param string $openId */ public function setOpenId(string $openId) { $this->openId = $openId; } /** * @param string $defaultUrl */ public function setDefaultUrl(string $defaultUrl) { $this->defaultUrl = $defaultUrl; } /** * @param $name * @param $context * @param string $color */ public function replaceKeyword($name, $context, $color = '') { $this->keywords[$name] = ['value' => $context, 'color' => $color]; } /** * @param $name * @param $context * @param null $color */ public function addKeyword($name, $context, $color = null) { if (empty($color)) { $color = '#000'; } $this->keywords[$name] = [ 'value' => $context, 'color' => $color ]; } /** * @param $context * @param string $color */ public function setFirst($context, $color = '#f00') { $this->first = [ 'value' => $context, 'color' => $color ]; } /** * @param $context * @param string $color */ public function setRemark($context, $color = '#000') { $this->remark = [ 'value' => $context, 'color' => $color ]; } /** * @param $appid * @param $pagepath */ public function setMiniprogram($appid, $pagepath) { $this->miniprogram = [ 'appid' => $appid, 'pagepath' => $pagepath ]; } /** * @return Result * @throws \Exception * * 奴隶交易通知 */ public function sendTemplate() { $url = $this->sendUrl . '?access_token=' . $this->getAccessToken(); $keywords = $this->keywords; $keywords['first'] = $this->first; $keywords['remark'] = $this->remark; $default = [ "touser" => $this->openId, "template_id" => $this->templateId, "url" => $this->defaultUrl, "data" => $keywords, ]; if (!empty($this->miniprogram)) { $default['miniprogram'] = $this->miniprogram; } $params = json_encode($default, JSON_UNESCAPED_UNICODE); $this->request->setIsSSL(true); $this->request->addHeader('content-type', 'application/json'); $result = $this->request->post($url, $params); $result->append('postBody', $params); return $result; } }