Mini.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Mini
  18. * @package WeChat
  19. */
  20. class Mini extends BasicWeChat
  21. {
  22. /**
  23. * 1. 获取公众号关联的小程序
  24. * @return array
  25. * @throws \WeChat\Exceptions\InvalidResponseException
  26. * @throws \WeChat\Exceptions\LocalCacheException
  27. */
  28. public function getLinkWxamp()
  29. {
  30. $url = 'https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=ACCESS_TOKEN';
  31. $this->registerApi($url, __FUNCTION__, func_get_args());
  32. return $this->httpPostForJson($url, [], true);
  33. }
  34. /**
  35. * 2. 关联小程序
  36. * @param string $miniAppid 小程序appid
  37. * @param integer $notifyUsers 是否发送模板消息通知公众号粉丝
  38. * @param integer $showProfile 是否展示公众号主页中
  39. * @return array
  40. * @throws Exceptions\InvalidResponseException
  41. * @throws Exceptions\LocalCacheException
  42. */
  43. public function linkWxamp($miniAppid, $notifyUsers = 1, $showProfile = 1)
  44. {
  45. $url = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=ACCESS_TOKEN";
  46. $this->registerApi($url, __FUNCTION__, func_get_args());
  47. return $this->httpPostForJson($url, [
  48. 'appid' => $miniAppid,
  49. 'notify_users' => $notifyUsers,
  50. 'show_profile' => $showProfile,
  51. ]);
  52. }
  53. /**
  54. * 3.解除已关联的小程序
  55. * @param string $miniAppid 小程序appid
  56. * @return array
  57. * @throws Exceptions\InvalidResponseException
  58. * @throws Exceptions\LocalCacheException
  59. */
  60. public function unlinkWxamp($miniAppid)
  61. {
  62. $url = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=ACCESS_TOKEN";
  63. $this->registerApi($url, __FUNCTION__, func_get_args());
  64. return $this->httpPostForJson($url, ['appid' => $miniAppid]);
  65. }
  66. /**
  67. * 第三方平台调用快速注册API完成注册
  68. * @param string $ticket 公众号扫码授权的凭证(公众平台扫码页面回跳到第三方平台时携带)
  69. * @return array
  70. * @throws Exceptions\InvalidResponseException
  71. * @throws Exceptions\LocalCacheException
  72. */
  73. public function fastRegister($ticket)
  74. {
  75. $url = 'https://api.weixin.qq.com/cgi-bin/account/fastregister?access_token=ACCESS_TOKEN';
  76. $this->registerApi($url, __FUNCTION__, func_get_args());
  77. return $this->httpPostForJson($url, ['ticket' => $ticket]);
  78. }
  79. }