Freepublish.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. namespace WeChat;
  16. use WeChat\Contracts\BasicWeChat;
  17. /**
  18. * 发布能力
  19. * Class Freepublish
  20. * @author taoxin
  21. * @package WeChat
  22. */
  23. class Freepublish extends BasicWeChat
  24. {
  25. /**
  26. * 发布接口
  27. * 开发者需要先将图文素材以草稿的形式保存(见“草稿箱/新建草稿”,如需从已保存的草稿中选择,见“草稿箱/获取草稿列表”)
  28. * @param mixed $media_id 选择要发布的草稿的media_id
  29. * @return array
  30. * @throws \WeChat\Exceptions\InvalidResponseException
  31. * @throws \WeChat\Exceptions\LocalCacheException
  32. */
  33. public function submit($media_id)
  34. {
  35. $url = "https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token=ACCESS_TOKEN";
  36. $this->registerApi($url, __FUNCTION__, func_get_args());
  37. return $this->httpPostForJson($url, ['media_id' => $media_id]);
  38. }
  39. /**
  40. * 发布状态轮询接口
  41. * @param mixed $publish_id
  42. * @return array
  43. * @throws \WeChat\Exceptions\InvalidResponseException
  44. * @throws \WeChat\Exceptions\LocalCacheException
  45. */
  46. public function get($publish_id)
  47. {
  48. $url = "https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token=ACCESS_TOKEN";
  49. $this->registerApi($url, __FUNCTION__, func_get_args());
  50. return $this->httpPostForJson($url, ['publish_id' => $publish_id]);
  51. }
  52. /**
  53. * 删除发布
  54. * 发布成功之后,随时可以通过该接口删除。此操作不可逆,请谨慎操作。
  55. * @param mixed $article_id 成功发布时返回的 article_id
  56. * @param int $index 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章
  57. * @return array
  58. * @throws \WeChat\Exceptions\InvalidResponseException
  59. * @throws \WeChat\Exceptions\LocalCacheException
  60. */
  61. public function delete($article_id, $index = 0)
  62. {
  63. $url = "https://api.weixin.qq.com/cgi-bin/freepublish/delete?access_token=ACCESS_TOKEN";
  64. $this->registerApi($url, __FUNCTION__, func_get_args());
  65. return $this->httpPostForJson($url, ['article_id' => $article_id, 'index' => $index]);
  66. }
  67. /**
  68. * 通过 article_id 获取已发布文章
  69. * @param mixed $article_id 要获取的草稿的article_id
  70. * @return array
  71. * @throws \WeChat\Exceptions\InvalidResponseException
  72. * @throws \WeChat\Exceptions\LocalCacheException
  73. */
  74. public function getArticle($article_id)
  75. {
  76. $url = "https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=ACCESS_TOKEN";
  77. $this->registerApi($url, __FUNCTION__, func_get_args());
  78. return $this->httpPostForJson($url, ['article_id' => $article_id]);
  79. }
  80. /**
  81. * 获取成功发布列表
  82. * @param int $offset 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
  83. * @param int $count 返回素材的数量,取值在1到20之间
  84. * @param int $no_content 1 表示不返回 content 字段,0 表示正常返回,默认为 0
  85. * @return array
  86. * @throws \WeChat\Exceptions\InvalidResponseException
  87. * @throws \WeChat\Exceptions\LocalCacheException
  88. */
  89. public function batchGet($offset = 0, $count = 20, $no_content = 0)
  90. {
  91. $url = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token=ACCESS_TOKEN";
  92. $this->registerApi($url, __FUNCTION__, func_get_args());
  93. return $this->httpPostForJson($url, ['no_content' => $no_content, 'offset' => $offset, 'count' => $count]);
  94. }
  95. }