Commit e0cd8283 by hanccc

增加文档和增加消息分类

1 parent 01f92cf9
...@@ -303,8 +303,12 @@ $robot->server->setCustomHandler(function(){ ...@@ -303,8 +303,12 @@ $robot->server->setCustomHandler(function(){
# to do list # to do list
- [ ] 命令行操作信息发送 - [ ] 命令行操作信息发送
- [ ] 增加消息集合存储 - [ x ] 增加消息集合存储
- [ ] 消息发送
- [ ] 发送图片
- [ ] 发送表情
- [ ] 消息处理 - [ ] 消息处理
- [ x ] 防撤回
# 已知bug # 已知bug
......
...@@ -218,7 +218,7 @@ class Server ...@@ -218,7 +218,7 @@ class Server
return true; return true;
} }
protected function init() protected function init($first = true)
{ {
$url = sprintf(self::BASE_URI . '/webwxinit?r=%i&lang=en_US&pass_ticket=%s', time(), $this->passTicket); $url = sprintf(self::BASE_URI . '/webwxinit?r=%i&lang=en_US&pass_ticket=%s', time(), $this->passTicket);
...@@ -227,7 +227,7 @@ class Server ...@@ -227,7 +227,7 @@ class Server
]); ]);
$result = json_decode($content, true); $result = json_decode($content, true);
$this->generateSyncKey($result); $this->generateSyncKey($result, $first);
myself()->init($result['User']); myself()->init($result['User']);
...@@ -271,15 +271,19 @@ class Server ...@@ -271,15 +271,19 @@ class Server
]); ]);
} }
protected function generateSyncKey($result) protected function generateSyncKey($result, $first)
{ {
$this->syncKey = $result['SyncKey']; $this->syncKey = $result['SyncKey'];
$syncKey = []; $syncKey = [];
if(is_array($this->syncKey['List'])){
foreach ($this->syncKey['List'] as $item) { foreach ($this->syncKey['List'] as $item) {
$syncKey[] = $item['Key'] . '_' . $item['Val']; $syncKey[] = $item['Key'] . '_' . $item['Val'];
} }
}elseif($first){
$this->init(false);
}
$this->syncKeyStr = implode('|', $syncKey); $this->syncKeyStr = implode('|', $syncKey);
} }
......
...@@ -157,7 +157,7 @@ class Message ...@@ -157,7 +157,7 @@ class Message
{ {
print_r($this->rawMsg); print_r($this->rawMsg);
switch($this->rawMsg['MsgType']){ switch($this->rawMsg['MsgType']){
case 1: case 1: //文本消息
if(Location::isLocation($this->rawMsg)){ if(Location::isLocation($this->rawMsg)){
$this->type = 'Location'; $this->type = 'Location';
$this->content = Location::getLocationText($this->rawMsg['Content']); $this->content = Location::getLocationText($this->rawMsg['Content']);
...@@ -166,26 +166,29 @@ class Message ...@@ -166,26 +166,29 @@ class Message
$this->content = $this->rawMsg['Content']; $this->content = $this->rawMsg['Content'];
} }
break; break;
case 3: case 3: // 图片消息
$this->type = 'Image'; $this->type = 'Image';
$this->content = Server::BASE_URI . sprintf('/webwxgetmsgimg?MsgID=%s&skey=%s', $this->rawMsg['MsgId'], server()->skey); $this->content = Server::BASE_URI . sprintf('/webwxgetmsgimg?MsgID=%s&skey=%s', $this->rawMsg['MsgId'], server()->skey);
$content = http()->get($this->content); $content = http()->get($this->content);
FileManager::download($this->rawMsg['MsgId'].'.jpg', $content, 'jpg'); FileManager::download($this->rawMsg['MsgId'].'.jpg', $content, 'jpg');
break; break;
case 34: case 34: // 语音消息
$this->type = 'Voice'; $this->type = 'Voice';
$this->content = Server::BASE_URI . sprintf('/webwxgetvoice?msgid=%s&skey=%s', $this->rawMsg['MsgId'], server()->skey); $this->content = Server::BASE_URI . sprintf('/webwxgetvoice?msgid=%s&skey=%s', $this->rawMsg['MsgId'], server()->skey);
$content = http()->get($this->content); $content = http()->get($this->content);
FileManager::download($this->rawMsg['MsgId'].'.mp3', $content, 'mp3'); FileManager::download($this->rawMsg['MsgId'].'.mp3', $content, 'mp3');
break; break;
case 37: case 37: // 好友验证
$this->type = 'AddUser'; $this->type = 'AddUser';
break; break;
case 42: case 42: //共享名片
$this->type = 'Recommend'; $this->type = 'Recommend';
$this->content = (object)$this->rawMsg['RecommendInfo']; $this->content = (object)$this->rawMsg['RecommendInfo'];
break; break;
case 47: case 43:
$this->type = 'VideoCall';
break;
case 47: // 动画表情
$this->type = 'Animation'; $this->type = 'Animation';
break; break;
case 49: case 49:
...@@ -194,9 +197,19 @@ class Message ...@@ -194,9 +197,19 @@ class Message
case 62: case 62:
$this->type = 'Video'; $this->type = 'Video';
break; break;
case 51:
$this->type = 'Init';
break;
case 53: case 53:
$this->type = 'VideoCall'; $this->type = 'VideoCall';
break; break;
case 10000:
if($this->rawMsg['Status'] == 4){
$this->type = 'RedPacket'; // 红包
}else{
$this->type = 'Unknown';
}
break;
case 10002: case 10002:
$this->type = 'Recall'; // 撤回 $this->type = 'Recall'; // 撤回
$msgId = $this->parseMsgId($this->rawMsg['Content']); $msgId = $this->parseMsgId($this->rawMsg['Content']);
...@@ -206,13 +219,6 @@ class Message ...@@ -206,13 +219,6 @@ class Message
Console::log('nickname:'.$nickname); Console::log('nickname:'.$nickname);
$this->content = "{$nickname} 刚撤回了消息 \"{$message['content']}\""; $this->content = "{$nickname} 刚撤回了消息 \"{$message['content']}\"";
break; break;
case 10000:
if($this->rawMsg['Status'] == 4){
$this->type = 'RedPacket'; // 红包
}else{
$this->type = 'Unknown';
}
break;
default: default:
$this->type = 'Unknown'; $this->type = 'Unknown';
break; break;
...@@ -308,4 +314,33 @@ class Message ...@@ -308,4 +314,33 @@ class Message
return true; return true;
} }
public static function sendImg($username, $mediaId)
{
$url = sprintf(Server::BASE_URI . '/webwxsendmsgimg?fun=async&f=json&pass_ticket=%s' , server()->passTicket);
$clientMsgId = (time() * 1000) .substr(uniqid(), 0,5);
$data = [
'BaseRequest'=> server()->baseRequest,
'Msg'=> [
'Type'=> 3,
'MediaId'=> $mediaId,
'FromUserName'=> myself()->username,
'ToUserName'=> $username,
'LocalID'=> $clientMsgId,
'ClientMsgId'=> $clientMsgId
]
];
$result = http()->post($url,
json_encode($data, JSON_UNESCAPED_UNICODE), true
);
if($result['BaseResponse']['Ret'] != 0){
Console::log('发送消息失败');
return false;
}
return true;
}
// pri
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!