Draft.php
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
/**
* 微信草稿箱管理
* Class Draft
* @author taoxin
* @package WeChat
*/
class Draft extends BasicWeChat
{
/**
* 新建草稿
* @param $articles
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function add($articles)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['articles' => $articles]);
}
/**
* 获取草稿
* @param string $mediaId
* @param string $outType 返回处理函数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get($mediaId, $outType = null)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/get?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['media_id' => $mediaId]);
}
/**
* 删除草稿
* @param string $mediaId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delete($mediaId)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/delete?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['media_id' => $mediaId]);
}
/**
* 新增图文素材
* @param array $data 文件名称
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addNews($data)
{
$url = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data);
}
/**
* 修改草稿
* @param string $media_id 要修改的图文消息的id
* @param int $index 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0
* @param $articles
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function update($media_id, $index, $articles)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/update?access_token=ACCESS_TOKEN";
$data = ['media_id' => $media_id, 'index' => $index, 'articles' => $articles];
return $this->callPostApi($url, $data);
}
/**
* 获取草稿总数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getCount()
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/count?access_token=ACCESS_TOKEN";
return $this->callGetApi($url);
}
/**
* 获取草稿列表
* @param int $offset 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
* @param int $count 返回素材的数量,取值在1到20之间
* @param int $noContent 1 表示不返回 content 字段,0 表示正常返回,默认为 0
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function batchGet($offset = 0, $count = 20, $noContent = 0)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['no_content' => $noContent, 'offset' => $offset, 'count' => $count]);
}
}