Bind.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ 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 WeChat;
  14. use WeChat\Contracts\BasicWeChat;
  15. /**
  16. * 微信开放平台帐号管理
  17. * Class Bind
  18. * @package WeChat
  19. */
  20. class Bind extends BasicWeChat
  21. {
  22. /**
  23. * 创建开放平台帐号并绑定公众号
  24. * @return array
  25. * @throws Exceptions\InvalidResponseException
  26. * @throws Exceptions\LocalCacheException
  27. */
  28. public function create()
  29. {
  30. $url = 'https://api.weixin.qq.com/cgi-bin/open/create?access_token=ACCESS_TOKEN';
  31. $this->registerApi($url, __FUNCTION__, func_get_args());
  32. return $this->httpPostForJson($url, ['appid' => $this->config->get('appid')]);
  33. }
  34. /**
  35. * 将公众号绑定到开放平台帐号下
  36. * @param string $openidAppid 开放平台帐号APPID
  37. * @return array
  38. * @throws Exceptions\InvalidResponseException
  39. * @throws Exceptions\LocalCacheException
  40. */
  41. public function link($openidAppid)
  42. {
  43. $url = 'https://api.weixin.qq.com/cgi-bin/open/bind?access_token=ACCESS_TOKEN';
  44. $this->registerApi($url, __FUNCTION__, func_get_args());
  45. return $this->httpPostForJson($url, ['appid' => $this->config->get('appid'), 'open_appid' => $openidAppid]);
  46. }
  47. /**
  48. * 将公众号从开放平台帐号下解绑
  49. * @param string $openidAppid 开放平台帐号APPID
  50. * @return array
  51. * @throws Exceptions\InvalidResponseException
  52. * @throws Exceptions\LocalCacheException
  53. */
  54. public function unlink($openidAppid)
  55. {
  56. $url = 'https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=ACCESS_TOKEN';
  57. $this->registerApi($url, __FUNCTION__, func_get_args());
  58. return $this->httpPostForJson($url, ['appid' => $this->config->get('appid'), 'open_appid' => $openidAppid]);
  59. }
  60. /**
  61. * 获取公众号所绑定的开放平台帐号
  62. * @return array
  63. * @throws Exceptions\InvalidResponseException
  64. * @throws Exceptions\LocalCacheException
  65. */
  66. public function get()
  67. {
  68. $url = 'https://api.weixin.qq.com/cgi-bin/open/get?access_token=ACCESS_TOKEN';
  69. $this->registerApi($url, __FUNCTION__, func_get_args());
  70. return $this->httpPostForJson($url, ['appid' => $this->config->get('appid')]);
  71. }
  72. }