Draft.php 4.7 KB

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