Video.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/13
* Time: 22:08
*/
namespace Hanson\Robot\Message;
use Hanson\Robot\Core\Server;
use Hanson\Robot\Support\Console;
class Video extends Message
{
use UploadAble;
public static function send($username, $file)
{
$response = static::uploadMedia($username, $file);
if(!$response){
Console::log("视频 {$file} 上传失败");
return false;
}
$mediaId = $response['MediaId'];
$url = sprintf(Server::BASE_URI . '/webwxsendvideomsg?fun=async&f=json&pass_ticket=%s' , server()->passTicket);
$data = [
'BaseRequest'=> server()->baseRequest,
'Msg'=> [
'Type'=> 43,
'MediaId'=> $mediaId,
'FromUserName'=> myself()->username,
'ToUserName'=> $username,
'LocalID'=> time() * 1e4,
'ClientMsgId'=> time() * 1e4
]
];
$result = http()->json($url, $data, true);
if($result['BaseResponse']['Ret'] != 0){
Console::log('发送视频失败');
return false;
}
return true;
}
}