Skip to content

Commit

Permalink
Merge pull request #106 from HanSon/dev
Browse files Browse the repository at this point in the history
修复文件发送
  • Loading branch information
Hanson authored May 3, 2017
2 parents fe457fb + 3a55ecd commit 50fd4e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
17 changes: 10 additions & 7 deletions demo/vbot.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function isAdmin($message)

$groupMap = [
[
'nickname' => 'vbot 测试群',
'nickname' => 'Vbot 体验群',
'id' => 1,
],
];
Expand Down Expand Up @@ -111,7 +111,6 @@ function isAdmin($message)
if ($message->fromType === Message::FROM_TYPE_CONTACT) {
if ($message->content === '拉我') {
$username = group()->getUsernameById(1);

group()->addMember($username, $message->from['UserName']);

return false;
Expand Down Expand Up @@ -174,7 +173,7 @@ function isAdmin($message)
}

// 表情信息 返回接收到的表情
if ($message instanceof Emoticon && random_int(0, 1) && random_int(0, 1)) {
if ($message instanceof Emoticon && random_int(0, 1)) {
Emoticon::sendRandom($message->from['UserName']);
}

Expand All @@ -192,6 +191,7 @@ function isAdmin($message)
Video::sendByMsgId($message->raw['FromUserName'], $message->origin->raw['MsgId']);
} elseif ($message->origin instanceof Voice) {
Text::send($message->raw['FromUserName'], "{$message->nickname} 撤回了一条语音");
\Hanson\Vbot\Message\Entity\File::send($message->raw['FromUserName'], Voice::getPath(Voice::$folder).$message->origin->raw['MsgId'].'.mp3');
} else {
Text::send($message->raw['FromUserName'], "{$message->nickname} 撤回了一条信息 \"{$message->origin->content}\"");
}
Expand Down Expand Up @@ -223,9 +223,8 @@ function isAdmin($message)
// 请求添加信息
if ($message instanceof RequestFriend) {
/** @var $message RequestFriend */
if ($message->info['Content'] === '上山打老虎') {
if (in_array($message->info['Content'], ['echo', 'var_dump', 'print', 'print_r', 'sprintf'])) {
$message->verifyUser($message::VIA);
} else {
}
}

Expand All @@ -237,6 +236,10 @@ function isAdmin($message)
$reply .= "\n来源APP:{$message->app}";
}

if (str_contains($message->url, 'meituan.com') && !($message->from['NickName'] !== '三年二班')) {
Text::send(group()->getUsernameByNickname('三年二班'), '收到美团红包:'.$message->url);
}

return $reply;
}

Expand Down Expand Up @@ -273,8 +276,8 @@ function isAdmin($message)
return $message->content;
} elseif ($message->action === 'RENAME') {
// \Hanson\Vbot\Support\Console::log($message->from['NickName'] . ' 改名为 ' . $message->rename);
if (group()->getUsernameById(1) == $message->from['UserName'] && $message->rename !== 'vbot 测试群') {
group()->setGroupName($message->from['UserName'], 'vbot 测试群');
if (group()->getUsernameById(1) == $message->from['UserName'] && $message->rename !== 'Vbot 体验群') {
group()->setGroupName($message->from['UserName'], 'Vbot 体验群');

return '行不改名,坐不改姓!';
}
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,10 @@ protected function init($first = true)
{
$url = sprintf($this->baseUri.'/webwxinit?r=%d', time());

$content = http()->json($url, [
$result = http()->post($url, json_encode([
'BaseRequest' => $this->baseRequest,
]);
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), true);

$result = json_decode($content, true);
$this->generateSyncKey($result, $first);

myself()->init($result['User']);
Expand Down
8 changes: 5 additions & 3 deletions src/Message/UploadAble.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,21 @@ public static function send($username, $file)

$mediaId = $response['MediaId'];

$url = sprintf(server()->baseUri.'/webwxsendappmsg?fun=async&f=json', server()->passTicket);
$url = server()->baseUri.'/webwxsendappmsg?fun=async&f=json&pass_ticket='.server()->passTicket;
$explode = explode('.', $file);
$fileName = end($explode);
$data = [
'BaseRequest'=> server()->baseRequest,
'Msg' => [
'Type' => 6,
'Content' => sprintf("<appmsg appid='wxeb7ec651dd0aefa9' sdkver=''><title>%s</title><des></des><action></action><type>6</type><content></content><url></url><lowurl></lowurl><appattach><totallen>%s</totallen><attachid>%s</attachid><fileext>%s</fileext></appattach><extinfo></extinfo></appmsg>", basename($file), filesize($file), $mediaId, end(explode('.', $file))),
'Content' => sprintf("<appmsg appid='wxeb7ec651dd0aefa9' sdkver=''><title>%s</title><des></des><action></action><type>6</type><content></content><url></url><lowurl></lowurl><appattach><totallen>%s</totallen><attachid>%s</attachid><fileext>%s</fileext></appattach><extinfo></extinfo></appmsg>", basename($file), filesize($file), $mediaId, $fileName),
'FromUserName'=> myself()->username,
'ToUserName' => $username,
'LocalID' => time() * 1e4,
'ClientMsgId' => time() * 1e4,
],
];
$result = http()->json($url, $data, true);
$result = http()->post($url, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), true);

if ($result['BaseResponse']['Ret'] != 0) {
Console::log('发送文件失败', Console::WARNING);
Expand Down

0 comments on commit 50fd4e0

Please sign in to comment.