add clear
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace officialaccount;
|
||||
|
||||
|
||||
use common\HttpClient;
|
||||
|
||||
class Subscribe extends AfficialAccount
|
||||
{
|
||||
|
||||
private $openid = '';
|
||||
private $template_id = '';
|
||||
private $url = '';
|
||||
private $miniprogram = [];
|
||||
private $scene = '';
|
||||
private $title = '';
|
||||
private $keywords = [];
|
||||
|
||||
private $pushUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=';
|
||||
|
||||
/**
|
||||
* @param string $openid
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setOpenid(string $openid): Subscribe
|
||||
{
|
||||
$this->openid = $openid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template_id
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setTemplateId(string $template_id): Subscribe
|
||||
{
|
||||
$this->template_id = $template_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setUrl(string $url): Subscribe
|
||||
{
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $appid
|
||||
* @param string $path
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setMiniprogram(string $appid, string $path): Subscribe
|
||||
{
|
||||
$this->miniprogram['appid'] = $appid;
|
||||
$this->miniprogram['pagepath'] = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $scene
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setScene(string $scene): Subscribe
|
||||
{
|
||||
$this->scene = $scene;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return Subscribe
|
||||
*/
|
||||
public function setTitle(string $title): Subscribe
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $keyword
|
||||
* @param $content
|
||||
* @param null $color
|
||||
*/
|
||||
public function addContent($keyword, $content, $color = null)
|
||||
{
|
||||
$param['value'] = $content;
|
||||
if (!empty($color)) {
|
||||
$param['color'] = $color;
|
||||
}
|
||||
$this->keywords[$keyword] = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed|\common\Result
|
||||
*/
|
||||
public function sendSubscribeMessage()
|
||||
{
|
||||
$requestParam['touser'] = $this->openid;
|
||||
$requestParam['template_id'] = $this->template_id;
|
||||
$requestParam['url'] = $this->url;
|
||||
$requestParam['miniprogram'] = $this->miniprogram;
|
||||
$requestParam['scene'] = $this->scene;
|
||||
$requestParam['title'] = $this->title;
|
||||
$requestParam['data'] = $this->keywords;
|
||||
|
||||
$requestUrl = $this->pushUrl . $this->config->getAccessToken();
|
||||
|
||||
$client = HttpClient::NewRequest();
|
||||
return $client->post($requestUrl, $requestParam);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user