add clear
This commit is contained in:
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace wchat;
|
||||
|
||||
|
||||
class Subject extends Miniprogarampage
|
||||
{
|
||||
|
||||
|
||||
private $keywords = [];
|
||||
private $templateId = '';
|
||||
private $openId = '';
|
||||
private $defaultUrl = '';
|
||||
private $page = 'pages/index/index';
|
||||
private $emphasis_keyword = '';
|
||||
|
||||
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send';
|
||||
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->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 string $page
|
||||
*/
|
||||
public function setPage(string $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword(string $emphasis_keyword)
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $index
|
||||
* @param $context
|
||||
* @param $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, $color = '')
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . $index] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null)
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . (count($this->keywords) + 1)] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$url = $this->sendUrl . '?access_token=' . $this->config->getAccessToken();
|
||||
$params = json_encode([
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"page" => $this->page,
|
||||
"data" => $this->keywords,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
if (!empty($this->emphasis_keyword)) {
|
||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||
}
|
||||
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->addHeader('content-type', 'application/json');
|
||||
|
||||
$result = $this->request->post($url, $params);
|
||||
$result->append('postBody', $params);
|
||||
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user