国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.1KB

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