add clear
This commit is contained in:
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace wchat\base;
|
||||||
|
|
||||||
|
|
||||||
|
use wchat\common\Miniprogarampage;
|
||||||
|
use wchat\common\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Subject
|
||||||
|
* @package wchat\base
|
||||||
|
*/
|
||||||
|
abstract class Subject extends Miniprogarampage
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private $keywords = [];
|
||||||
|
private $templateId = '';
|
||||||
|
private $openId = '';
|
||||||
|
private $page = 'pages/index/index';
|
||||||
|
private $emphasis_keyword = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 $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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function getUrl(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Result
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function sendTemplate()
|
||||||
|
{
|
||||||
|
$url = $this->getUrl() . '?access_token=' . $this->config->getAccessToken();
|
||||||
|
$params = [
|
||||||
|
"touser" => $this->openId,
|
||||||
|
"template_id" => $this->templateId,
|
||||||
|
"page" => $this->page,
|
||||||
|
"data" => $this->keywords,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($this->emphasis_keyword)) {
|
||||||
|
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->addHeader('content-type', 'application/json');
|
||||||
|
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$result = $this->request->post($url, $params);
|
||||||
|
$result->append('postBody', $params);
|
||||||
|
|
||||||
|
return $this->reset($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $result
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function reset($result)
|
||||||
|
{
|
||||||
|
$this->openId = '';
|
||||||
|
$this->keywords = [];
|
||||||
|
$this->templateId = '';
|
||||||
|
$this->page = '';
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\base;
|
||||||
|
|
||||||
|
use wchat\common\Miniprogarampage;
|
||||||
|
use wchat\common\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Template
|
||||||
|
*/
|
||||||
|
abstract class Template extends Miniprogarampage
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private $keywords = [];
|
||||||
|
private $templateId = '';
|
||||||
|
private $formId = '';
|
||||||
|
private $openId = '';
|
||||||
|
private $page = 'pages/index/index';
|
||||||
|
private $emphasis_keyword = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $keywords
|
||||||
|
*/
|
||||||
|
public function setKeywords(array $keywords)
|
||||||
|
{
|
||||||
|
$this->keywords = $keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $templateId
|
||||||
|
*/
|
||||||
|
public function setTemplateId(string $templateId)
|
||||||
|
{
|
||||||
|
$this->templateId = $templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $formId
|
||||||
|
*/
|
||||||
|
public function setFormId(string $formId)
|
||||||
|
{
|
||||||
|
$this->formId = $formId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $openId
|
||||||
|
*/
|
||||||
|
public function setOpenId(string $openId)
|
||||||
|
{
|
||||||
|
$this->openId = $openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function getUrl(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Result
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* 奴隶交易通知
|
||||||
|
*/
|
||||||
|
public function sendTemplate()
|
||||||
|
{
|
||||||
|
$access_token = $this->config->getAccessToken();
|
||||||
|
if (empty($access_token)) {
|
||||||
|
throw new \Exception('request access_token con\'t null.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $this->getUrl() . '?access_token=' . $access_token;
|
||||||
|
$params = [
|
||||||
|
"touser" => $this->openId,
|
||||||
|
"template_id" => $this->templateId,
|
||||||
|
"page" => $this->page,
|
||||||
|
"form_id" => $this->formId,
|
||||||
|
"data" => $this->keywords,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($this->emphasis_keyword)) {
|
||||||
|
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||||
|
}
|
||||||
|
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||||
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->addHeader('content-type', 'application/json');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$result = $this->request->post($url, $params);
|
||||||
|
$result->append('postBody', $params);
|
||||||
|
|
||||||
|
return $this->reset($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $result
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function reset($result)
|
||||||
|
{
|
||||||
|
$this->openId = '';
|
||||||
|
$this->keywords = [];
|
||||||
|
$this->formId = '';
|
||||||
|
$this->templateId = '';
|
||||||
|
$this->page = '';
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -152,7 +152,7 @@ class Result
|
|||||||
public function append($key, $data)
|
public function append($key, $data)
|
||||||
{
|
{
|
||||||
if (!is_array($this->data)) {
|
if (!is_array($this->data)) {
|
||||||
$this->data = [];
|
$this->data = ['origin' => $this->data];
|
||||||
}
|
}
|
||||||
$this->data[$key] = $data;
|
$this->data[$key] = $data;
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
+8
-120
@@ -6,133 +6,21 @@ namespace wchat\qq;
|
|||||||
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
class Subject extends SmallProgram
|
/**
|
||||||
|
* Class Subject
|
||||||
|
* @package wchat\qq
|
||||||
|
*/
|
||||||
|
class Subject extends \wchat\base\Subject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private $keywords = [];
|
|
||||||
private $templateId = '';
|
|
||||||
private $openId = '';
|
|
||||||
private $defaultUrl = '';
|
|
||||||
private $page = 'pages/index/index';
|
|
||||||
private $emphasis_keyword = '';
|
|
||||||
|
|
||||||
private $sendUrl = 'https://api.q.qq.com/api/json/subscribe/SendSubscriptionMessage';
|
private $sendUrl = 'https://api.q.qq.com/api/json/subscribe/SendSubscriptionMessage';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $keywords
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function setKeywords(array $keywords)
|
public function getUrl(): string
|
||||||
{
|
{
|
||||||
$this->keywords = $keywords;
|
return $this->getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = [
|
|
||||||
"touser" => $this->openId,
|
|
||||||
"template_id" => $this->templateId,
|
|
||||||
"page" => $this->page,
|
|
||||||
"data" => $this->keywords,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!empty($this->emphasis_keyword)) {
|
|
||||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-132
@@ -11,143 +11,18 @@ namespace wchat\qq;
|
|||||||
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
class Template extends SmallProgram
|
/**
|
||||||
|
* Class Template
|
||||||
|
* @package wchat\qq
|
||||||
|
*/
|
||||||
|
class Template extends \wchat\base\Template
|
||||||
{
|
{
|
||||||
|
|
||||||
private $keywords = [];
|
|
||||||
private $templateId = '';
|
|
||||||
private $formId = '';
|
|
||||||
private $openId = '';
|
|
||||||
private $defaultUrl = '';
|
|
||||||
private $page = 'pages/index/index';
|
|
||||||
private $emphasis_keyword = '';
|
|
||||||
|
|
||||||
private $sendUrl = 'https://api.q.qq.com/api/json/template/send';
|
private $sendUrl = 'https://api.q.qq.com/api/json/template/send';
|
||||||
|
|
||||||
|
public function getUrl(): string
|
||||||
/**
|
|
||||||
* @param array $keywords
|
|
||||||
*/
|
|
||||||
public function setKeywords(array $keywords)
|
|
||||||
{
|
{
|
||||||
$this->keywords = $keywords;
|
return $this->sendUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $templateId
|
|
||||||
*/
|
|
||||||
public function setTemplateId(string $templateId)
|
|
||||||
{
|
|
||||||
$this->templateId = $templateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $formId
|
|
||||||
*/
|
|
||||||
public function setFormId(string $formId)
|
|
||||||
{
|
|
||||||
$this->formId = $formId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = [
|
|
||||||
"touser" => $this->openId,
|
|
||||||
"template_id" => $this->templateId,
|
|
||||||
"page" => $this->page,
|
|
||||||
"form_id" => $this->formId,
|
|
||||||
"data" => $this->keywords,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!empty($this->emphasis_keyword)) {
|
|
||||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
|
||||||
}
|
|
||||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
||||||
$this->request->setIsSSL(true);
|
|
||||||
$this->request->addHeader('content-type', 'application/json');
|
|
||||||
$this->request->setErrorField('errcode');
|
|
||||||
$this->request->setErrorMsgField('errmsg');
|
|
||||||
$result = $this->request->post($url, $params);
|
|
||||||
$result->append('postBody', $params);
|
|
||||||
|
|
||||||
$this->openId = '';
|
|
||||||
$this->keywords = [];
|
|
||||||
$this->formId = '';
|
|
||||||
$this->templateId = '';
|
|
||||||
$this->page = '';
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-123
@@ -6,135 +6,16 @@ namespace wchat\wx;
|
|||||||
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
class Subject extends SmallProgram
|
class Subject extends \wchat\base\Subject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
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';
|
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $keywords
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function setKeywords(array $keywords)
|
public function getUrl(): string
|
||||||
{
|
{
|
||||||
$this->keywords = $keywords;
|
return $this->sendUrl;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = [
|
|
||||||
"touser" => $this->openId,
|
|
||||||
"template_id" => $this->templateId,
|
|
||||||
"page" => $this->page,
|
|
||||||
"data" => $this->keywords,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!empty($this->emphasis_keyword)) {
|
|
||||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
|
||||||
$this->request->setIsSSL(true);
|
|
||||||
$this->request->addHeader('content-type', 'application/json');
|
|
||||||
|
|
||||||
$this->request->setErrorField('errcode');
|
|
||||||
$this->request->setErrorMsgField('errmsg');
|
|
||||||
$result = $this->request->post($url, $params);
|
|
||||||
$result->append('postBody', $params);
|
|
||||||
|
|
||||||
$this->openId = '';
|
|
||||||
$this->keywords = [];
|
|
||||||
$this->templateId = '';
|
|
||||||
$this->page = '';
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-135
@@ -8,145 +8,17 @@
|
|||||||
|
|
||||||
namespace wchat\wx;
|
namespace wchat\wx;
|
||||||
|
|
||||||
use wchat\common\Result;
|
/**
|
||||||
|
* Class Template
|
||||||
class Template extends SmallProgram
|
* @package wchat\wx
|
||||||
|
*/
|
||||||
|
class Template extends \wchat\base\Template
|
||||||
{
|
{
|
||||||
|
|
||||||
private $keywords = [];
|
|
||||||
private $templateId = '';
|
|
||||||
private $formId = '';
|
|
||||||
private $openId = '';
|
|
||||||
private $defaultUrl = '';
|
|
||||||
private $page = 'pages/index/index';
|
|
||||||
private $emphasis_keyword = '';
|
|
||||||
|
|
||||||
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send';
|
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send';
|
||||||
|
|
||||||
|
public function getUrl(): string
|
||||||
/**
|
|
||||||
* @param array $keywords
|
|
||||||
*/
|
|
||||||
public function setKeywords(array $keywords)
|
|
||||||
{
|
{
|
||||||
$this->keywords = $keywords;
|
return $this->sendUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $templateId
|
|
||||||
*/
|
|
||||||
public function setTemplateId(string $templateId)
|
|
||||||
{
|
|
||||||
$this->templateId = $templateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $formId
|
|
||||||
*/
|
|
||||||
public function setFormId(string $formId)
|
|
||||||
{
|
|
||||||
$this->formId = $formId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = [
|
|
||||||
"touser" => $this->openId,
|
|
||||||
"template_id" => $this->templateId,
|
|
||||||
"page" => $this->page,
|
|
||||||
"form_id" => $this->formId,
|
|
||||||
"data" => $this->keywords,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!empty($this->emphasis_keyword)) {
|
|
||||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
|
||||||
}
|
|
||||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
|
||||||
$this->request->setIsSSL(true);
|
|
||||||
$this->request->addHeader('content-type', 'application/json');
|
|
||||||
$this->request->setErrorField('errcode');
|
|
||||||
$this->request->setErrorMsgField('errmsg');
|
|
||||||
$result = $this->request->post($url, $params);
|
|
||||||
$result->append('postBody', $params);
|
|
||||||
|
|
||||||
$this->openId = '';
|
|
||||||
$this->keywords = [];
|
|
||||||
$this->formId = '';
|
|
||||||
$this->templateId = '';
|
|
||||||
$this->page = '';
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user