This commit is contained in:
2020-11-14 02:33:13 +08:00
parent 650b4d9f19
commit 7e3a959096
+29 -57
View File
@@ -32,55 +32,51 @@ class Message extends SmallProgram
/**
* @param string $content
* @return Result
* @throws \Exception
* @return Message
*/
public function sendTextNews(string $content)
{
$this->msgData['msgtype'] = 'text';
$this->msgData['text'] = ['content' => $content];
return $this->sendKefuMsg();
return $this;
}
/**
* @param $media_id
* @return Result
* @throws \Exception
* @param string $media_id
* @return Message
*/
public function sendImageNews(string $media_id)
{
$this->msgData['msgtype'] = 'image';
$this->msgData['image'] = ['media_id' => $media_id];
return $this->sendKefuMsg();
return $this;
}
/**
* @param $media_id
* @return Result
* @throws \Exception
* @param string $media_id
* @return Message
*/
public function sendVoiceNews(string $media_id)
{
$this->msgData['msgtype'] = 'voice';
$this->msgData['voice'] = ['media_id' => $media_id];
return $this->sendKefuMsg();
return $this;
}
/**
* @param $media_id
* @return Result
* @throws \Exception
* @param string $media_id
* @return Message
*/
public function sendMpNewsNews(string $media_id)
{
$this->msgData['msgtype'] = 'mpnews';
$this->msgData['mpnews'] = ['media_id' => $media_id];
return $this->sendKefuMsg();
return $this;
}
@@ -89,8 +85,7 @@ class Message extends SmallProgram
* @param string $description
* @param string $url
* @param string $picurl
* @return Result
* @throws \Exception
* @return Message
*/
public function sendNewsNews(string $title, string $description, string $url, string $picurl)
{
@@ -101,21 +96,20 @@ class Message extends SmallProgram
'url' => $url,
'picurl' => $picurl
]]];
return $this->sendKefuMsg();
return $this;
}
/**
* @param string $title
* @return Result
* @throws \Exception
* @return Message
*/
public function sendCardNews(string $title)
{
$this->msgData['msgtype'] = 'wxcard';
$this->msgData['wxcard'] = ['card_id' => $title];
return $this->sendKefuMsg();
return $this;
}
@@ -124,8 +118,7 @@ class Message extends SmallProgram
* @param string $thumb_media_id
* @param string $title
* @param string $description
* @return Result
* @throws \Exception
* @return Message
*/
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
{
@@ -136,7 +129,7 @@ class Message extends SmallProgram
'title' => $title,
'description' => $description
]];
return $this->sendKefuMsg();
return $this;
}
@@ -146,8 +139,7 @@ class Message extends SmallProgram
* @param string $thumb_media_id
* @param string $title
* @param string $description
* @return Result
* @throws \Exception
* @return Message
*/
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
{
@@ -159,7 +151,7 @@ class Message extends SmallProgram
'hqmusicurl' => $hqmusicurl,
'thumb_media_id' => $thumb_media_id
];
return $this->sendKefuMsg();
return $this;
}
@@ -167,7 +159,7 @@ class Message extends SmallProgram
* @param string $head_content
* @param string $tail_content
* @param array $menus
* @return Result
* @return Message
* @throws \Exception
*/
public function sendMenuNews(string $head_content, string $tail_content, array $menus = [])
@@ -183,7 +175,7 @@ class Message extends SmallProgram
foreach ($menus as $key => $val) {
$this->addNewsMenu($val['id'], $val['name']);
}
return $this->sendKefuMsg();
return $this;
}
private int $index = 0;
@@ -203,12 +195,11 @@ class Message extends SmallProgram
}
/**
* @param $title
* @param $appid
* @param $pagepath
* @param $thumb_media_id
* @return Result
* @throws \Exception
* @param string $title
* @param string $appid
* @param string $pagepath
* @param string $thumb_media_id
* @return Message
*/
public function sendMiniprogrampageNews(string $title, string $appid, string $pagepath, string $thumb_media_id)
{
@@ -219,7 +210,7 @@ class Message extends SmallProgram
'pagepath' => $pagepath,
'thumb_media_id' => $thumb_media_id,
];
return $this->sendKefuMsg();
return $this;
}
/**
@@ -268,28 +259,10 @@ class Message extends SmallProgram
return $data->getData();
}
/**
* @param $mime
* @throws \Exception
* @return array
*/
private function checkExtinfo($mime)
{
switch (strtolower($mime)) {
case 'image/bmp':
case 'image/png':
case 'image/jpeg':
case 'image/jpg':
case 'image/gif':
case 'mp3/wma/wav/amr':
case 'mp4';
case 'jpg';
break;
default:
throw new \Exception('不支持的文件格式');
}
}
public function getContents()
{
return $this->msgData;
@@ -297,7 +270,6 @@ class Message extends SmallProgram
/**
* @param $data
* @return Result
* @throws \Exception
*/