Commit 579cba4a by hanccc

无语了。。。

1 parent 04712535
...@@ -20,7 +20,7 @@ $robot = new Robot([ ...@@ -20,7 +20,7 @@ $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/5102437722783331610.jpg')); Image::send($message->username, realpath(__DIR__ . '/./../tmp/jpg/9031924810002714257.jpg'));
} }
}); });
......
...@@ -196,17 +196,18 @@ class Server ...@@ -196,17 +196,18 @@ class Server
{ {
$content = http()->get($this->redirectUri); $content = http()->get($this->redirectUri);
$crawler = new Crawler($content); $data = (array)simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->skey = $crawler->filter('error skey')->text();
$this->sid = $crawler->filter('error wxsid')->text(); $this->skey = $data['skey'];
$this->uin = $crawler->filter('error wxuin')->text(); $this->sid = $data['wxsid'];
$this->passTicket = $crawler->filter('error pass_ticket')->text(); $this->uin = $data['wxuin'];
$this->passTicket = $data['pass_ticket'];
if(in_array('', [$this->skey, $this->sid, $this->uin, $this->passTicket])){ if(in_array('', [$this->skey, $this->sid, $this->uin, $this->passTicket])){
throw new \Exception('[ERROR] login fail!'); throw new \Exception('[ERROR] login fail!');
} }
$this->deviceId = 'e' . strval(random_int(100000000000000, 999999999999999)); $this->deviceId = 'e' .substr(mt_rand().mt_rand(), 1, 15);
$this->baseRequest = [ $this->baseRequest = [
'Uin' => intval($this->uin), 'Uin' => intval($this->uin),
...@@ -220,7 +221,7 @@ class Server ...@@ -220,7 +221,7 @@ class Server
protected function init($first = true) protected function init($first = true)
{ {
$url = sprintf(self::BASE_URI . '/webwxinit?r=%i&lang=en_US&pass_ticket=%s&skey=%s', time(), $this->passTicket, $this->skey); $url = sprintf(self::BASE_URI . '/webwxinit?r=%d', time());
$content = http()->json($url, [ $content = http()->json($url, [
'BaseRequest' => $this->baseRequest 'BaseRequest' => $this->baseRequest
...@@ -234,8 +235,10 @@ class Server ...@@ -234,8 +235,10 @@ class Server
$this->initContactList($result['ContactList']); $this->initContactList($result['ContactList']);
if($result['BaseResponse']['Ret'] != 0){ if($result['BaseResponse']['Ret'] != 0){
// Log::echo('init fail!'); // print_r($this->baseRequest);
throw new Exception('[ERROR] init fail!');
Console::log('[ERROR] init fail!');
// throw new Exception('[ERROR] init fail!');
} }
} }
......
...@@ -54,7 +54,7 @@ trait UploadAble ...@@ -54,7 +54,7 @@ trait UploadAble
'FileMd5' => md5_file($file) 'FileMd5' => md5_file($file)
], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), ], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
'webwx_data_ticket' => static::getTicket(), 'webwx_data_ticket' => static::getTicket(),
'pass_ticket' => urldecode(server()->passTicket), 'pass_ticket' => (server()->passTicket),
// 'filename' => "@{$file};filename=".basename($file), // 'filename' => "@{$file};filename=".basename($file),
// 'filename' => file_get_contents($file), // 'filename' => file_get_contents($file),
'filename' => fopen($file, 'r'), 'filename' => fopen($file, 'r'),
...@@ -63,13 +63,12 @@ trait UploadAble ...@@ -63,13 +63,12 @@ trait UploadAble
]; ];
// $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', [
// 'multipart' => $data 'multipart' => $data
// ]); ]);
$result = json_decode($result, true);
// $result = json_decode($result, true);
print_r($data); print_r($data);
print_r($result); print_r($result);
...@@ -110,7 +109,7 @@ trait UploadAble ...@@ -110,7 +109,7 @@ trait UploadAble
]; ];
if($key === 'filename'){ if($key === 'filename'){
$field['filename'] = basename(static::$file); $field['filename'] = basename(static::$file);
$field['Content-type'] = 'image/jpeg'; // $field['Content-type'] = 'application/octet-stream';
} }
$result[] = $field; $result[] = $field;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!