Skip to content

Commit b841923

Browse files
Merge pull request #60 from lienze741/master
增加图文消息留言管理,修改获取视频素材保存本地 修改一次性订阅消息问题 修改Jssdk,自定义菜单等
2 parents ce0745d + de57c9e commit b841923

File tree

11 files changed

+358
-20
lines changed

11 files changed

+358
-20
lines changed

src/Bean/OfficialAccount/MediaResponse.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use EasySwoole\HttpClient\Bean\Response;
1212
use EasySwoole\Utility\Mime\MimeDetectorException;
1313
use EasySwoole\Utility\MimeType;
14+
use EasySwoole\WeChat\Exception\RequestError;
15+
use EasySwoole\WeChat\Utility\NetWork;
1416
use InvalidArgumentException;
1517
use Swoole\Coroutine;
1618

@@ -44,6 +46,22 @@ public function isJson(): bool
4446
return false;
4547
}
4648

49+
50+
public function isVideo()
51+
{
52+
if (isset($this->httpResponse()->getHeaders()['content-type']) && $this->httpResponse()->getHeaders()['content-type'] === 'text/plain') {
53+
$data = json_decode($this->getContent(), true);
54+
if (isset($data['down_url'])) {
55+
return $data['down_url'];
56+
}
57+
if (isset($data['video_url'])) {
58+
return $data['video_url'];
59+
}
60+
}
61+
62+
return false;
63+
}
64+
4765
public function isEmpty(): bool
4866
{
4967
return empty($this->getContent());
@@ -61,7 +79,7 @@ public function getContent(): string
6179
* @return string
6280
* @throws MimeDetectorException
6381
*/
64-
public function save(string $directory, string $filename = null)
82+
public function save(string $directory, string $filename = null, int $timeout = 15)
6583
{
6684
$directory = rtrim($directory, '/');
6785

@@ -73,18 +91,32 @@ public function save(string $directory, string $filename = null)
7391
throw new InvalidArgumentException(sprintf("'%s' is not writable.", $directory));
7492
}
7593

94+
if ($fileUrl = $this->isVideo()) {
95+
NetWork::$TIMEOUT = $timeout;
96+
97+
$fileData = NetWork::get($fileUrl);
98+
99+
if (($fileData->getClient()->errCode)) {
100+
throw new RequestError($fileData->getClient()->errMsg);
101+
}
102+
103+
$this->httpResponse = $fileData;
104+
}
105+
76106
$contents = $this->httpResponse()->getBody();
77107

78108
if (empty($filename)) {
79-
if (preg_match('/filename="(?<filename>.*?)"/', $this->httpResponse()->getHeaders()['content-disposition'], $match)) {
109+
if (isset($this->httpResponse()->getHeaders()['content-disposition']) && preg_match('/filename=["]{0,1}(?<filename>.*)/', $this->httpResponse()->getHeaders()['content-disposition'], $match)) {
80110
$filename = $match['filename'];
81111
} else {
82112
$filename = md5($contents);
83113
}
84114
}
85115

116+
$filename = trim($filename, '"');
117+
86118
if (empty(pathinfo($filename, PATHINFO_EXTENSION))) {
87-
$filename .= MimeType::getExtFromStream($contents);
119+
$filename .= '.'.MimeType::getExtFromStream($contents);
88120
}
89121

90122
Coroutine::writeFile($directory . '/' . $filename, $contents);

src/Bean/OfficialAccount/RequestConst.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,40 @@ class RequestConst
4141
*/
4242
const MSG_TYPE_MPVIDEO = 'mpvideo';
4343

44+
4445
/*
4546
* 事件大小写不同,主要是微信自己本身事件大小写就不一样,不规范
4647
*/
47-
const EVENT_SUBSCRIBE = 'subscribe';
48-
const EVENT_UNSUBSCRIBE = 'unsubscribe';
49-
const EVENT_SCAN = 'SCAN';
50-
const EVENT_LOCATION = 'LOCATION';
51-
const EVENT_CLICK = 'CLICK';
52-
const EVENT_VIEW = 'VIEW';
48+
// 用户关注事件
49+
const EVENT_SUBSCRIBE = 'subscribe';
50+
// 用户取消关注事件
51+
const EVENT_UNSUBSCRIBE = 'unsubscribe';
52+
// 用户已关注事件
53+
const EVENT_SCAN = 'SCAN';
54+
// 上报地理位置事件
55+
const EVENT_LOCATION = 'LOCATION';
56+
// 点击自定义菜单拉取消息事件
57+
const EVENT_CLICK = 'CLICK';
58+
// 点击自定义菜单跳转事件
59+
const EVENT_VIEW = 'VIEW';
60+
// 发送模板消息通知事件
5361
const EVENT_TEMPLATE_SEND_JOB_FINISH = 'TEMPLATESENDJOBFINISH';
62+
// 群发结果事件
5463
const EVENT_MASS_SEND_JOB_FINISH = 'MASSSENDJOBFINISH';
64+
//扫码推事件的事件推送
65+
const EVENT_SCANCODE_PUSH = 'scancode_push';
66+
//扫码推事件且弹出“消息接收中”提示框的事件推送
67+
const EVENT_SCANCODE_WAITMSG = 'scancode_waitmsg';
68+
//弹出系统拍照发图的事件推送
69+
const EVENT_PIC_SYSPHOTO = 'pic_sysphoto';
70+
//弹出拍照或者相册发图的事件推送
71+
const EVENT_PIC_PHOTO_OR_ALBUM = 'pic_photo_or_album';
72+
//弹出微信相册发图器的事件推送
73+
const EVENT_PIC_WEIXIN = 'pic_weixin';
74+
//弹出地理位置选择器的事件推送
75+
const EVENT_LOCATION_SELECT = 'location_select';
76+
//点击菜单跳转小程序的事件推送
77+
const EVENT_VIEW_MINIPROGRAM = 'view_miniprogram';
78+
79+
5580
}

src/Bean/OfficialAccount/TemplateMsg.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,25 @@ class TemplateMsg extends SplBean
1818
protected $url;
1919
protected $miniprogram;
2020
protected $scene;
21-
protected $appid;
22-
protected $pagepath;
21+
protected $title;
2322
protected $data = [];
23+
24+
/**
25+
* @return mixed
26+
*/
27+
public function getTitle()
28+
{
29+
return $this->title;
30+
}
31+
32+
/**
33+
* @param string $title
34+
*/
35+
public function setTitle(string $title): void
36+
{
37+
$this->title = $title;
38+
}
39+
2440
/**
2541
* @return mixed
2642
*/
@@ -96,7 +112,7 @@ public function getMiniprogram()
96112
/**
97113
* @param mixed $miniprogram
98114
*/
99-
public function setMiniprogram($miniprogram): void
115+
public function setMiniprogram(array $miniprogram): void
100116
{
101117
$this->miniprogram = $miniprogram;
102118
}
@@ -106,31 +122,31 @@ public function setMiniprogram($miniprogram): void
106122
*/
107123
public function getAppid()
108124
{
109-
return $this->appid;
125+
return $this->miniprogram['appid'];
110126
}
111127

112128
/**
113129
* @param mixed $appid
114130
*/
115131
public function setAppid($appid): void
116132
{
117-
$this->appid = $appid;
133+
$this->miniprogram['appid'] = $appid;
118134
}
119135

120136
/**
121137
* @return mixed
122138
*/
123139
public function getPagepath()
124140
{
125-
return $this->pagepath;
141+
return $this->miniprogram['pagepath'];
126142
}
127143

128144
/**
129145
* @param mixed $pagepath
130146
*/
131147
public function setPagepath($pagepath): void
132148
{
133-
$this->pagepath = $pagepath;
149+
$this->miniprogram['pagepath'] = $pagepath;
134150
}
135151

136152
/**

src/OfficialAccount/ApiUrl.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ class ApiUrl
4040
/*
4141
* 获取临时素材
4242
*/
43-
const MEDIA_GET = 'https://file.api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID';
43+
const MEDIA_GET = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID';
44+
45+
/*
46+
* 获取高清语音素材
47+
*/
48+
const MEDIA_HD_GET = 'https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=ACCESS_TOKEN&media_id=MEDIA_ID';
4449

4550
/*
4651
* 上传临时素材

0 commit comments

Comments
 (0)