Commit 61406210 by hanccc

增加实例用户信息

1 parent 429afca3
......@@ -12,6 +12,7 @@ namespace Hanson\Robot\Core;
use Endroid\QrCode\QrCode;
use GuzzleHttp\Client;
use Hanson\Robot\Models\ContactFactory;
use Hanson\Robot\Models\GroupAccount;
use Hanson\Robot\Support\Log;
use QueryPath\Exception;
use Symfony\Component\DomCrawler\Crawler;
......@@ -41,7 +42,7 @@ class Server
protected $syncKeyStr;
protected $http;
public $http;
protected $config;
......@@ -67,6 +68,10 @@ class Server
Log::echo('[INFO] init success!');
$this->statusNotify();
$this->initContact();
Log::echo('[INFO] init contacts success!');
print_r(GroupAccount::getInstance()->first());
}
public function prepare()
......@@ -124,10 +129,9 @@ class Server
/**
* waiting user to login
*
* @return int
* @throws \Exception
*/
protected function waitForLogin(): int
protected function waitForLogin()
{
$retryTime = 10;
$tip = 1;
......@@ -137,6 +141,8 @@ class Server
$content = $this->http->get($url);
Log::echo($content);
preg_match('/window.code=(\d+);/', $content, $matches);
$code = $matches[1];
......@@ -206,6 +212,7 @@ class Server
'BaseRequest' => $this->baseRequest
]);
$result = json_decode($content, true);
$this->generateSyncKey($result);
......@@ -214,8 +221,6 @@ class Server
if($result['BaseResponse']['Ret'] != 0){
throw new Exception('[ERROR] init fail!');
}
$this->initContact();
}
protected function initContact()
......
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/13
* Time: 20:56
*/
namespace Hanson\Robot\Models;
use Illuminate\Support\Collection;
class Account extends Collection
{
static $instance = null;
/**
* create a single instance
*
* @return Account
*/
public static function getInstance()
{
if(static::$instance === null){
static::$instance = new Account();
}
return static::$instance;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/13
* Time: 20:56
*/
namespace Hanson\Robot\Models;
use Illuminate\Support\Collection;
class ContactAccount extends Collection
{
static $instance = null;
/**
* create a single instance
*
* @return ContactAccount
*/
public static function getInstance()
{
if(static::$instance === null){
static::$instance = new ContactAccount();
}
return static::$instance;
}
}
\ No newline at end of file
......@@ -10,26 +10,58 @@ namespace Hanson\Robot\Models;
use Hanson\Robot\Core\Server;
use Hanson\Robot\Support\Log;
class ContactFactory
{
protected $server;
const SPECIAL_USERS = ['newsapp', 'fmessage', 'filehelper', 'weibo', 'qqmail',
'fmessage', 'tmessage', 'qmessage', 'qqsync', 'floatbottle',
'lbsapp', 'shakeapp', 'medianote', 'qqfriend', 'readerapp',
'blogapp', 'facebookapp', 'masssendapp', 'meishiapp',
'feedsapp', 'voip', 'blogappweixin', 'weixin', 'brandsessionholder',
'weixinreminder', 'wxid_novlwrv3lqwv11', 'gh_22b87fa7cb3c',
'officialaccounts', 'notification_messages', 'wxid_novlwrv3lqwv11',
'gh_22b87fa7cb3c', 'wxitil', 'userexperience_alarm', 'notification_messages'];
public function __construct(Server $server)
{
$this->server = $server;
$this->getContacts();
}
public function getContacts()
{
$url = sprintf(Server::BASE_URI . '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s', $this->server->passTicket, $this->server->skey, time());
$content = $this->http->json($url, [
'BaseRequest' => $this->baseRequest
$content = $this->server->http->json($url, [
'BaseRequest' => $this->server->baseRequest
]);
$memberList = json_decode($content, true)['MemberList'];
$this->makeContactList($memberList);
}
protected function makeContactList($memberList)
{
foreach ($memberList as $contact) {
if($contact['VerifyFlag'] & 8 != 0){ #公众号
$type = 'public';
OfficialAccount::getInstance()->push($contact);
}elseif (in_array($contact['UserName'], static::SPECIAL_USERS)){ # 特殊账户
$type = 'special';
SpecialAccount::getInstance()->push($contact);
}elseif (strstr($contact['UserName'], '@@') !== false){ # 群聊
$type = 'group';
GroupAccount::getInstance()->push($contact);
}else{
$type = 'contact';
ContactAccount::getInstance()->push($contact);
}
Account::getInstance()->put($contact['UserName'], ['type' => $type, 'info' => $contact]);
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/13
* Time: 20:56
*/
namespace Hanson\Robot\Models;
use Illuminate\Support\Collection;
class GroupAccount extends Collection
{
static $instance = null;
/**
* create a single instance
*
* @return GroupAccount
*/
public static function getInstance()
{
if(static::$instance === null){
static::$instance = new GroupAccount();
}
return static::$instance;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/13
* Time: 20:56
*/
namespace Hanson\Robot\Models;
use Illuminate\Support\Collection;
class OfficialAccount extends Collection
{
static $instance = null;
/**
* create a single instance
*
* @return OfficialAccount
*/
public static function getInstance()
{
if(static::$instance === null){
static::$instance = new OfficialAccount();
}
return static::$instance;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2016/12/13
* Time: 20:56
*/
namespace Hanson\Robot\Models;
use Illuminate\Support\Collection;
class SpecialAccount extends Collection
{
static $instance = null;
/**
* create a single instance
*
* @return SpecialAccount
*/
public static function getInstance()
{
if(static::$instance === null){
static::$instance = new SpecialAccount();
}
return static::$instance;
}
}
\ No newline at end of file
......@@ -37,4 +37,4 @@ $robot = new \Hanson\Robot\Foundation\Robot([
'tuling_key' => ''
]);
//$robot->server->run();
$robot->server->run();
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!