3
This commit is contained in:
+23
-28
@@ -3,21 +3,18 @@
|
||||
|
||||
namespace wchat\wx;
|
||||
|
||||
use Exception;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class Message
|
||||
* @package wchat\wx
|
||||
*/
|
||||
class Message extends SmallProgram
|
||||
{
|
||||
const TEXT = 0;
|
||||
const IMAGE = 1;
|
||||
const VOICE = 2;
|
||||
const NEWS = 3;
|
||||
const VIDEO = 4;
|
||||
const MUSIC = 5;
|
||||
const MINIPROGRAMPAGE = 6;
|
||||
const WXCARD = 7;
|
||||
|
||||
private string $openid = '';
|
||||
private array $msgData = [];
|
||||
|
||||
|
||||
@@ -26,14 +23,13 @@ class Message extends SmallProgram
|
||||
*/
|
||||
public function setOpenid(string $openid)
|
||||
{
|
||||
$this->openid = $openid;
|
||||
$this->msgData['touser'] = $openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendTextNews(string $content)
|
||||
{
|
||||
@@ -46,7 +42,7 @@ class Message extends SmallProgram
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendImageNews(string $media_id)
|
||||
{
|
||||
@@ -60,7 +56,7 @@ class Message extends SmallProgram
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendVoiceNews(string $media_id)
|
||||
{
|
||||
@@ -73,7 +69,7 @@ class Message extends SmallProgram
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendMpNewsNews(string $media_id)
|
||||
{
|
||||
@@ -90,7 +86,7 @@ class Message extends SmallProgram
|
||||
* @param string $url
|
||||
* @param string $picurl
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendNewsNews(string $title, string $description, string $url, string $picurl)
|
||||
{
|
||||
@@ -108,7 +104,7 @@ class Message extends SmallProgram
|
||||
/**
|
||||
* @param string $title
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendCardNews(string $title)
|
||||
{
|
||||
@@ -125,7 +121,7 @@ class Message extends SmallProgram
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
|
||||
{
|
||||
@@ -147,7 +143,7 @@ class Message extends SmallProgram
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
|
||||
{
|
||||
@@ -168,7 +164,7 @@ class Message extends SmallProgram
|
||||
* @param string $tail_content
|
||||
* @param array $menus
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendMenuNews(string $head_content, string $tail_content, array $menus = [])
|
||||
{
|
||||
@@ -178,7 +174,7 @@ class Message extends SmallProgram
|
||||
'tail_content' => $tail_content,
|
||||
];
|
||||
if (empty($menus) || !is_array($menus) || count($menus) < 2) {
|
||||
throw new \Exception('菜单选项必须有2个');
|
||||
throw new Exception('菜单选项必须有2个');
|
||||
}
|
||||
foreach ($menus as $key => $val) {
|
||||
$this->addNewsMenu($val['id'], $val['name']);
|
||||
@@ -208,7 +204,7 @@ class Message extends SmallProgram
|
||||
* @param $pagepath
|
||||
* @param $thumb_media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendMiniprogrampageNews(string $title, string $appid, string $pagepath, string $thumb_media_id)
|
||||
{
|
||||
@@ -229,16 +225,16 @@ class Message extends SmallProgram
|
||||
* @param string $title
|
||||
* @param string $introduction
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upload(string $filePath, string $type, $isPermanent = false, string $title = '', string $introduction = '')
|
||||
{
|
||||
if (!file_exists($filePath)) {
|
||||
throw new \Exception('文件不存在');
|
||||
throw new Exception('文件不存在');
|
||||
}
|
||||
|
||||
if (!in_array($type, ['image', 'voice', 'video', 'thumb'])) {
|
||||
throw new \Exception('暂不支持的文件类型');
|
||||
throw new Exception('暂不支持的文件类型');
|
||||
}
|
||||
|
||||
$token = $this->getAccessToken();
|
||||
@@ -262,7 +258,7 @@ class Message extends SmallProgram
|
||||
/** @var Result $body */
|
||||
$data = $this->request->post($url, $data);
|
||||
if (!$data->isResultsOK()) {
|
||||
throw new \Exception($data->getMessage());
|
||||
throw new Exception($data->getMessage());
|
||||
}
|
||||
|
||||
return $data->getData();
|
||||
@@ -279,9 +275,8 @@ class Message extends SmallProgram
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function sendKefuMsg()
|
||||
{
|
||||
@@ -299,7 +294,7 @@ class Message extends SmallProgram
|
||||
$body = $this->request->post($url, $data);
|
||||
|
||||
if (!$body->isResultsOK()) {
|
||||
throw new \Exception($body->getMessage());
|
||||
throw new Exception($body->getMessage());
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user