Commit 00b0c1f1 by HanSon

增加了ShareFactory,增加了File类型、Content工具类

1 parent 3ff71adf
......@@ -33,9 +33,7 @@ class ContactFactory
{
$url = sprintf(server()->baseUri . '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s', server()->passTicket, server()->skey, time());
$content = http()->json($url, [
'BaseRequest' => server()->baseRequest
], true);
$content = http()->json($url, [], true);
$this->makeContactList($content['MemberList']);
}
......
......@@ -18,6 +18,7 @@ use Hanson\Vbot\Message\Entity\Recommend;
use Hanson\Vbot\Message\Entity\RedPacket;
use Hanson\Vbot\Message\Entity\RequestFriend;
use Hanson\Vbot\Message\Entity\Share;
use Hanson\Vbot\Message\Entity\ShareFactory;
use Hanson\Vbot\Message\Entity\Text;
use Hanson\Vbot\Message\Entity\Touch;
use Hanson\Vbot\Message\Entity\Transfer;
......@@ -69,7 +70,7 @@ class MessageFactory
if($msg['Status'] == 3 && $msg['FileName'] === '微信转账'){
return new Transfer($msg);
}else{
return new Share($msg);
return (new ShareFactory())->make($msg);
}
case 37: // 好友验证
return new RequestFriend($msg);
......
......@@ -170,7 +170,6 @@ class Server
case '200':
preg_match('/window.redirect_uri="(\S+?)";/', $content, $matches);
$this->redirectUri = $matches[1] . '&fun=new';
Console::log('登录URL:'.$this->redirectUri);
$domainList = [
'wx2.qq.com' => ['file.wx2.qq.com', 'webpush.wx2.qq.com'],
'wx.qq.com' => ['file.wx.qq.com', 'webpush.wx.qq.com'],
......@@ -188,7 +187,6 @@ class Server
break;
}
}
Console::log('url is:'. $this->baseUri);
return;
case '408':
Console::log('[ERROR] 登录超时,请重试');
......
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/15
* Time: 12:29
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MediaInterface;
use Hanson\Vbot\Message\MessageInterface;
use Hanson\Vbot\Message\UploadAble;
use Hanson\Vbot\Support\FileManager;
class File extends Message implements MessageInterface, MediaInterface
{
use UploadAble;
public $title;
static $folder = 'file';
public function __construct($msg)
{
parent::__construct($msg);
$this->make();
}
public function make()
{
$array = (array)simplexml_load_string($this->msg['Content'], 'SimpleXMLElement', LIBXML_NOCDATA);
$info = (array)$array['appmsg'];
$this->title = $info['title'];
$this->download();
}
public function download()
{
$url = server()->fileUri . '/webwxgetmedia';
$content = http()->get($url, [
'sender' => $this->msg['FromUserName'],
'mediaid' => $this->msg['MediaId'],
'filename' => $this->msg['FileName'],
'fromuser' => myself()->username,
'pass_ticket' => server()->passTicket,
'webwx_data_ticket' => static::getTicket()
]);
FileManager::download($this->msg['FileName'], $content, static::$folder);
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ use Hanson\Vbot\Core\Server;
use Hanson\Vbot\Collections\Contact;
use Hanson\Vbot\Collections\Official;
use Hanson\Vbot\Collections\Special;
use Hanson\Vbot\Support\Content;
use Hanson\Vbot\Support\FileManager;
use Hanson\Vbot\Support\Console;
......@@ -56,7 +57,7 @@ class Message
$this->setFrom();
$this->setFromType();
$this->msg['Content'] = html_entity_decode($this->formatContent($this->msg['Content']));
$this->msg['Content'] = Content::formatContent($this->msg['Content']);
if($this->fromType === 'Group'){
$this->handleGroupContent($this->msg['Content']);
}
......@@ -104,12 +105,7 @@ class Message
list($uid, $content) = explode(":\n", $content, 2);
$this->sender = account()->getAccount($uid);
$this->msg['Content'] = $this->formatContent($content);
}
protected function formatContent($content)
{
return str_replace('<br/>', "\n", $content);
$this->msg['Content'] = Content::replaceBr($content);
}
public function __toString()
......
......@@ -21,13 +21,6 @@ class Share extends Message implements MessageInterface
public $app;
/**
* 转账金额 单位 元
*
* @var string
*/
public $fee;
public function __construct($msg)
{
parent::__construct($msg);
......
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/15
* Time: 12:29
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MessageInterface;
use Hanson\Vbot\Support\Content;
class ShareFactory
{
protected $xml;
public $type;
public function make($msg)
{
$xml = Content::formatContent($msg['Content']);
$this->parse($xml);
if($this->type == 6){
return new File($msg);
}else{
return new Share($msg);
}
}
private function parse($xml)
{
$array = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->xml = $info = (array)$array['appmsg'];
$this->type = $info['type'];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/1/24
* Time: 17:44
*/
namespace Hanson\Vbot\Support;
/**
* Content 处理类
*
* Class Content
* @package Hanson\Vbot\Support
*/
class Content
{
/**
* 格式化Content
*
* @param $content
* @return string
*/
public static function formatContent($content)
{
return self::htmlDecode(self::replaceBr($content));
}
public static function htmlDecode($content)
{
return html_entity_decode($content);
}
public static function replaceBr($content)
{
return str_replace('<br/>', "\n", $content);
}
}
\ 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!