Plugs.php 3.7 KB

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