Plugs.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 WeMini;
  16. use WeChat\Contracts\BasicWeChat;
  17. /**
  18. * 微信小程序插件管理
  19. * Class Plugs
  20. * @package WeMini
  21. */
  22. class Plugs extends BasicWeChat
  23. {
  24. /**
  25. * 1.申请使用插件
  26. * @param string $plugin_appid 插件appid
  27. * @return array
  28. * @throws \WeChat\Exceptions\InvalidResponseException
  29. * @throws \WeChat\Exceptions\LocalCacheException
  30. */
  31. public function apply($plugin_appid)
  32. {
  33. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  34. return $this->callPostApi($url, ['action' => 'apply', 'plugin_appid' => $plugin_appid], true);
  35. }
  36. /**
  37. * 2.查询已添加的插件
  38. * @return array
  39. * @throws \WeChat\Exceptions\InvalidResponseException
  40. * @throws \WeChat\Exceptions\LocalCacheException
  41. */
  42. public function getList()
  43. {
  44. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  45. return $this->callPostApi($url, ['action' => 'list'], true);
  46. }
  47. /**
  48. * 3.删除已添加的插件
  49. * @param string $plugin_appid 插件appid
  50. * @return array
  51. * @throws \WeChat\Exceptions\InvalidResponseException
  52. * @throws \WeChat\Exceptions\LocalCacheException
  53. */
  54. public function unbind($plugin_appid)
  55. {
  56. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  57. return $this->callPostApi($url, ['action' => 'unbind', 'plugin_appid' => $plugin_appid], true);
  58. }
  59. /**
  60. * 获取当前所有插件使用方
  61. * 修改插件使用申请的状态
  62. * @param array $data
  63. * @return array
  64. * @throws \WeChat\Exceptions\InvalidResponseException
  65. * @throws \WeChat\Exceptions\LocalCacheException
  66. */
  67. public function devplugin($data)
  68. {
  69. $url = 'https://api.weixin.qq.com/wxa/devplugin?access_token=ACCESS_TOKEN';
  70. return $this->callPostApi($url, $data, true);
  71. }
  72. /**
  73. * 4.获取当前所有插件使用方(供插件开发者调用)
  74. * @param integer $page 拉取第page页的数据
  75. * @param integer $num 表示每页num条记录
  76. * @return array
  77. * @throws \WeChat\Exceptions\InvalidResponseException
  78. * @throws \WeChat\Exceptions\LocalCacheException
  79. */
  80. public function devApplyList($page = 1, $num = 10)
  81. {
  82. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  83. $data = ['action' => 'dev_apply_list', 'page' => $page, 'num' => $num];
  84. return $this->callPostApi($url, $data, true);
  85. }
  86. /**
  87. * 5.修改插件使用申请的状态(供插件开发者调用)
  88. * @param string $action dev_agree:同意申请;dev_refuse:拒绝申请;dev_delete:删除已拒绝的申请者
  89. * @return array
  90. * @throws \WeChat\Exceptions\InvalidResponseException
  91. * @throws \WeChat\Exceptions\LocalCacheException
  92. */
  93. public function devAgree($action = 'dev_agree')
  94. {
  95. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  96. return $this->callPostApi($url, ['action' => $action], true);
  97. }
  98. }