eee
This commit is contained in:
+11
-14
@@ -27,7 +27,7 @@ abstract class Subject extends Multiprogramming
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
public function setKeywords(array $keywords): void
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ abstract class Subject extends Multiprogramming
|
||||
/**
|
||||
* @param $templateId
|
||||
*/
|
||||
public function setTemplateId($templateId)
|
||||
public function setTemplateId($templateId): void
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ abstract class Subject extends Multiprogramming
|
||||
/**
|
||||
* @param $openId
|
||||
*/
|
||||
public function setOpenId($openId)
|
||||
public function setOpenId($openId): void
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ abstract class Subject extends Multiprogramming
|
||||
/**
|
||||
* @param $page
|
||||
*/
|
||||
public function setPage($page)
|
||||
public function setPage($page): void
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ abstract class Subject extends Multiprogramming
|
||||
/**
|
||||
* @param $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword($emphasis_keyword)
|
||||
public function setEmphasisKeyword($emphasis_keyword): void
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ abstract class Subject extends Multiprogramming
|
||||
* @param $context
|
||||
* @param string $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, string $color = '')
|
||||
public function replaceKeyword($index, $context, string $color = ''): void
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
@@ -85,7 +85,7 @@ abstract class Subject extends Multiprogramming
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null)
|
||||
public function addKeyword($context, $color = null): void
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
@@ -135,7 +135,7 @@ abstract class Subject extends Multiprogramming
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws
|
||||
*/
|
||||
public function sendTemplate(): Result
|
||||
{
|
||||
@@ -158,7 +158,7 @@ abstract class Subject extends Multiprogramming
|
||||
if (!empty($this->use_robot)) {
|
||||
$params['use_robot'] = $this->use_robot;
|
||||
}
|
||||
$this->reset($result);
|
||||
$this->reset();
|
||||
|
||||
$client = new Client($this->getHost(), 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
|
||||
@@ -184,17 +184,14 @@ abstract class Subject extends Multiprogramming
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function reset($result)
|
||||
public function reset(): void
|
||||
{
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+120
-121
@@ -13,126 +13,126 @@ abstract class Template extends Multiprogramming
|
||||
{
|
||||
|
||||
|
||||
private array $keywords = [];
|
||||
private string $templateId = '';
|
||||
private string $formId = '';
|
||||
private string $openId = '';
|
||||
private string $page = 'pages/index/index';
|
||||
private string $emphasis_keyword = '';
|
||||
private array $keywords = [];
|
||||
private string $templateId = '';
|
||||
private string $formId = '';
|
||||
private string $openId = '';
|
||||
private string $page = 'pages/index/index';
|
||||
private string $emphasis_keyword = '';
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords): void
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $templateId
|
||||
*/
|
||||
public function setTemplateId($templateId)
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
/**
|
||||
* @param $templateId
|
||||
*/
|
||||
public function setTemplateId($templateId): void
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $formId
|
||||
*/
|
||||
public function setFormId($formId)
|
||||
{
|
||||
$this->formId = $formId;
|
||||
}
|
||||
/**
|
||||
* @param $formId
|
||||
*/
|
||||
public function setFormId($formId): void
|
||||
{
|
||||
$this->formId = $formId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openId
|
||||
*/
|
||||
public function setOpenId($openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
/**
|
||||
* @param $openId
|
||||
*/
|
||||
public function setOpenId($openId): void
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
*/
|
||||
public function setPage($page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
/**
|
||||
* @param $page
|
||||
*/
|
||||
public function setPage($page): void
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword($emphasis_keyword)
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
/**
|
||||
* @param $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword($emphasis_keyword): void
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $index
|
||||
* @param $context
|
||||
* @param string $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, string $color = '')
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . $index] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
public function replaceKeyword($index, $context, string $color = ''): void
|
||||
{
|
||||
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
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null): void
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . (count($this->keywords) + 1)] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
abstract public function getUrl();
|
||||
abstract public function getUrl();
|
||||
|
||||
abstract public function getHost();
|
||||
abstract public function getHost();
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate(): Result
|
||||
{
|
||||
$access_token = $this->payConfig->getAccessToken();
|
||||
if (empty($access_token)) {
|
||||
throw new \Exception('request access_token con\'t null.');
|
||||
}
|
||||
/**
|
||||
* @return Result
|
||||
* @throws
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate(): Result
|
||||
{
|
||||
$access_token = $this->payConfig->getAccessToken();
|
||||
if (empty($access_token)) {
|
||||
throw new \Exception('request access_token con\'t null.');
|
||||
}
|
||||
|
||||
$params = [
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"page" => $this->page,
|
||||
"form_id" => $this->formId,
|
||||
"data" => $this->keywords,
|
||||
];
|
||||
$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;
|
||||
}
|
||||
if (!empty($this->emphasis_keyword)) {
|
||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||
}
|
||||
|
||||
$this->reset($result);
|
||||
$this->reset();
|
||||
|
||||
$client = new Client($this->getHost(), 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
|
||||
$client = new Client($this->getHost(), 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
|
||||
|
||||
$proxyHost = $this->payConfig->getProxyHost();
|
||||
$proxyPort = $this->payConfig->getProxyPort();
|
||||
@@ -141,29 +141,28 @@ abstract class Template extends Multiprogramming
|
||||
}
|
||||
|
||||
$client->post($this->getUrl() . '?access_token=' . $access_token, $params);
|
||||
$client->close();
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
}
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
}
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return void
|
||||
*/
|
||||
private function reset($result): void
|
||||
{
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->formId = '';
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function reset(): void
|
||||
{
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->formId = '';
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user