Skip to content

Commit

Permalink
支持发送base64图片
Browse files Browse the repository at this point in the history
  • Loading branch information
nkxingxh committed Feb 26, 2023
1 parent 5eafad6 commit d93862b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions core/easyMirai.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ function replyMessage($messageChain, $quote = 0, $at = 0, $sessionKey = '')
/**
* 获取消息链
* @param string @PlainText 消息文本
* @param string|array $ImageUrl 图片链接(可以是数组)
* @param string|array $Images 图片链接或 base64 (可以是数组)
* @param int|array $AtTarget 要 At 的 QQ 号(可以是数组)
*/
function getMessageChain($PlainText = '', $ImageUrl = '', $AtTarget = 0)
function getMessageChain($PlainText = '', $Images = '', $AtTarget = 0)
{
$MessageChain = array();
if (!empty($AtTarget)) {
Expand All @@ -315,14 +315,21 @@ function getMessageChain($PlainText = '', $ImageUrl = '', $AtTarget = 0)
} else $MessageChain[] = getMessageChain_PlainText($PlainText);
}

if (!empty($ImageUrl)) {
if (is_array($ImageUrl)) {
$n = count($ImageUrl);
for ($i = 0; $i < $n; $i++) {
$MessageChain[] = getMessageChain_Image($ImageUrl[$i]);

if (!empty($Images)) {
if (!is_array($Images)) {
$Images = array($Images);
}
$n = count($Images);
for ($i = 0; $i < $n; $i++) {
if (
strtolower(substr($Images[$i], 0, 7)) == 'http://' ||
strtolower(substr($Images[$i], 0, 8)) == 'https://'
) {
$MessageChain[] = getMessageChain_Image($Images[$i]);
} else {
$MessageChain[] = getMessageChain_Image(null, $Images[$i]);
}
} else {
$MessageChain[] = getMessageChain_Image($ImageUrl);
}
}

Expand All @@ -339,9 +346,14 @@ function getMessageChain_At($target)
return array('type' => 'At', 'target' => $target);
}

function getMessageChain_Image($ImageUrl)
/**
* 生产消息链中的图片类型成员 (参数二选一)
* @param string ImageUrl 图片链接
* @param string ImageBase64 图片 BASE64 编码后的内容
*/
function getMessageChain_Image($ImageUrl = null, $ImageBase64 = null)
{
return array('type' => 'Image', 'url' => $ImageUrl);
return array('type' => 'Image', 'url' => $ImageUrl, 'base64' => $ImageBase64);
}

function getMessageChain_Json($json)
Expand Down

0 comments on commit d93862b

Please sign in to comment.