国内流行的内容管理系统(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.

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