Commit c532cc2b by HanSon

增加upload media

1 parent 579cba4a
...@@ -306,6 +306,20 @@ $robot->server->setCustomHandler(function(){ ...@@ -306,6 +306,20 @@ $robot->server->setCustomHandler(function(){
- [ ] 消息抽象成每个类 - [ ] 消息抽象成每个类
- [ ] 群操作
- [ ] 创建群
- [ ] 把某人踢出群
- [ ] 邀请好友加入群
- [ ] 修改群名称
- [ ] 聊天窗口操作
- [ ] 置顶聊天会话
- [ ] 取消聊天会话指定
- [ ] 好友操作
- [ ] 给好友添加备注
- [ ] 通过好友验证
- [x] 增加消息集合存储 - [x] 增加消息集合存储
- [ ] 消息发送 - [ ] 消息发送
...@@ -328,4 +342,4 @@ $robot->server->setCustomHandler(function(){ ...@@ -328,4 +342,4 @@ $robot->server->setCustomHandler(function(){
# 已知bug # 已知bug
* 20% 的几率初始化失败(暂时无解,如清楚问题欢迎PR) * 30% 的几率初始化失败(暂时无解,如清楚问题欢迎PR)
...@@ -20,7 +20,8 @@ $robot = new Robot([ ...@@ -20,7 +20,8 @@ $robot = new Robot([
$robot->server->setMessageHandler(function($message){ $robot->server->setMessageHandler(function($message){
/** @var $message Message */ /** @var $message Message */
if($message->content === '测试图片'){ if($message->content === '测试图片'){
Image::send($message->username, realpath(__DIR__ . '/./../tmp/jpg/9031924810002714257.jpg')); // https://wx2.qq.com/cgi-bin/mmwebwx-bin
Image::send($message->username, realpath(__DIR__ . '/./../tmp/jpg/1547651860337387181.jpg'));
} }
}); });
......
...@@ -111,8 +111,8 @@ class Server ...@@ -111,8 +111,8 @@ class Server
$content = http()->get('https://login.weixin.qq.com/jslogin', [ $content = http()->get('https://login.weixin.qq.com/jslogin', [
'appid' => 'wx782c26e4c19acffb', 'appid' => 'wx782c26e4c19acffb',
'fun' => 'new', 'fun' => 'new',
'lang' => 'zh_CN', // 'lang' => 'zh_CN',
'_' => time() * 1000 . random_int(1, 999) // '_' => time() * 1000 . random_int(1, 999)
]); ]);
preg_match('/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/', $content, $matches); preg_match('/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/', $content, $matches);
...@@ -168,6 +168,7 @@ class Server ...@@ -168,6 +168,7 @@ class Server
case '200': case '200':
preg_match('/window.redirect_uri="(\S+?)";/', $content, $matches); preg_match('/window.redirect_uri="(\S+?)";/', $content, $matches);
$this->redirectUri = $matches[1] . '&fun=new'; $this->redirectUri = $matches[1] . '&fun=new';
Console::log('登录URL:'.$this->redirectUri);
return; return;
case '408': case '408':
Console::log('[ERROR] login timeout. please try 1 second later.'); Console::log('[ERROR] login timeout. please try 1 second later.');
...@@ -237,7 +238,7 @@ class Server ...@@ -237,7 +238,7 @@ class Server
if($result['BaseResponse']['Ret'] != 0){ if($result['BaseResponse']['Ret'] != 0){
// print_r($this->baseRequest); // print_r($this->baseRequest);
Console::log('[ERROR] init fail!'); Console::log('init URL:'. $url);
// throw new Exception('[ERROR] init fail!'); // throw new Exception('[ERROR] init fail!');
} }
} }
......
...@@ -27,7 +27,7 @@ trait UploadAble ...@@ -27,7 +27,7 @@ trait UploadAble
*/ */
public static function uploadMedia($username, $file) public static function uploadMedia($username, $file)
{ {
$url = 'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'; $url = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json';
static::$mediaCount = ++static::$mediaCount; static::$mediaCount = ++static::$mediaCount;
static::$file = $file; static::$file = $file;
...@@ -38,7 +38,7 @@ trait UploadAble ...@@ -38,7 +38,7 @@ trait UploadAble
'name' => basename($file), 'name' => basename($file),
'type' => $mime, 'type' => $mime,
// 'lastModifieDate' => gmdate('D M d Y H:i:s', filemtime($file) ).' GMT+0800 (CST)', // 'lastModifieDate' => gmdate('D M d Y H:i:s', filemtime($file) ).' GMT+0800 (CST)',
'lastModifieDate' => date('D M d Y H:i:s',filemtime($file)).' GMT+0800 (CST)', 'lastModifieDate' => gmdate('D M d Y H:i:s TO', filemtime($file)).' (CST)',
'size' => filesize($file), 'size' => filesize($file),
'mediatype' => $mediaType, 'mediatype' => $mediaType,
'uploadmediarequest' => json_encode([ 'uploadmediarequest' => json_encode([
...@@ -62,7 +62,7 @@ trait UploadAble ...@@ -62,7 +62,7 @@ trait UploadAble
// 'filename' => curl_file_create($file, $mime, basename($file)) // 'filename' => curl_file_create($file, $mime, basename($file))
]; ];
// $data = static::dataToMultipart($data); $data = static::dataToMultipart($data);
// $result = http()->post($url, $data, true); // $result = http()->post($url, $data, true);
$result = http()->request($url, 'post', [ $result = http()->request($url, 'post', [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!