From 00f046fba12b79c1f17034324bc335d068299d88 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Wed, 21 Aug 2019 13:34:03 +0800 Subject: [PATCH] add clear --- wx/PublicTemplate.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wx/PublicTemplate.php b/wx/PublicTemplate.php index 4f985c2..6d54e70 100644 --- a/wx/PublicTemplate.php +++ b/wx/PublicTemplate.php @@ -13,6 +13,8 @@ class PublicTemplate extends Miniprogarampage private $keywords = []; private $templateId = ''; + private $first = ''; + private $remark = ''; private $openId = ''; private $defaultUrl = 'http://weixin.qq.com/download'; private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send'; @@ -58,21 +60,20 @@ class PublicTemplate extends Miniprogarampage */ public function replaceKeyword($name, $context, $color = '') { - $this->addKeyword($name, $context, $color); + $this->keywords['keyword' . $name] = ['value' => $context, 'color' => $color]; } /** - * @param $name * @param $context * @param null $color */ - public function addKeyword($name, $context, $color = null) + public function addKeyword($context, $color = null) { if (empty($color)) { $color = '#000'; } - $this->keywords[$name . '.DATA'] = [ + $this->keywords['keyword' . count($this->keywords)] = [ 'value' => $context, 'color' => $color ]; @@ -84,7 +85,7 @@ class PublicTemplate extends Miniprogarampage */ public function setFirst($context, $color = '#f00') { - $this->keywords['first.DATA'] = [ + $this->first = [ 'value' => $context, 'color' => $color ]; @@ -96,7 +97,7 @@ class PublicTemplate extends Miniprogarampage */ public function setRemark($context, $color = '#000') { - $this->keywords['remark.DATA'] = [ + $this->remark = [ 'value' => $context, 'color' => $color ]; @@ -124,11 +125,15 @@ class PublicTemplate extends Miniprogarampage { $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" => $this->keywords, + "data" => $keywords, ]; if (!empty($this->miniprogram)) {