Plugs.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  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. $this->registerApi($url, __FUNCTION__, func_get_args());
  33. return $this->callPostApi($url, ['action' => 'apply', 'plugin_appid' => $plugin_appid], true);
  34. }
  35. /**
  36. * 2.查询已添加的插件
  37. * @return array
  38. * @throws \WeChat\Exceptions\InvalidResponseException
  39. * @throws \WeChat\Exceptions\LocalCacheException
  40. */
  41. public function getList()
  42. {
  43. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  44. $this->registerApi($url, __FUNCTION__, func_get_args());
  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. $this->registerApi($url, __FUNCTION__, func_get_args());
  58. return $this->callPostApi($url, ['action' => 'unbind', 'plugin_appid' => $plugin_appid], true);
  59. }
  60. /**
  61. * 获取当前所有插件使用方
  62. * 修改插件使用申请的状态
  63. * @param array $data
  64. * @return array
  65. * @throws \WeChat\Exceptions\InvalidResponseException
  66. * @throws \WeChat\Exceptions\LocalCacheException
  67. */
  68. public function devplugin($data)
  69. {
  70. $url = 'https://api.weixin.qq.com/wxa/devplugin?access_token=ACCESS_TOKEN';
  71. $this->registerApi($url, __FUNCTION__, func_get_args());
  72. return $this->callPostApi($url, $data, true);
  73. }
  74. /**
  75. * 4.获取当前所有插件使用方(供插件开发者调用)
  76. * @param integer $page 拉取第page页的数据
  77. * @param integer $num 表示每页num条记录
  78. * @return array
  79. * @throws \WeChat\Exceptions\InvalidResponseException
  80. * @throws \WeChat\Exceptions\LocalCacheException
  81. */
  82. public function devApplyList($page = 1, $num = 10)
  83. {
  84. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  85. $this->registerApi($url, __FUNCTION__, func_get_args());
  86. $data = ['action' => 'dev_apply_list', 'page' => $page, 'num' => $num];
  87. return $this->callPostApi($url, $data, true);
  88. }
  89. /**
  90. * 5.修改插件使用申请的状态(供插件开发者调用)
  91. * @param string $action dev_agree:同意申请;dev_refuse:拒绝申请;dev_delete:删除已拒绝的申请者
  92. * @return array
  93. * @throws \WeChat\Exceptions\InvalidResponseException
  94. * @throws \WeChat\Exceptions\LocalCacheException
  95. */
  96. public function devAgree($action = 'dev_agree')
  97. {
  98. $url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
  99. $this->registerApi($url, __FUNCTION__, func_get_args());
  100. return $this->callPostApi($url, ['action' => $action], true);
  101. }
  102. }