项目作者: freyo

项目描述 :
📦 WeChat Enterprise SDK based on EasyWeChat 3.X
高级语言: PHP
项目地址: git://github.com/freyo/entwechat.git
创建时间: 2017-04-14T14:23:31Z
项目社区:https://github.com/freyo/entwechat

开源协议:MIT License

下载


EntWeChat

Software License
Quality Score
Packagist Version
Total Downloads

WeChat Enterprise SDK based on EasyWeChat 3.X

Requirement

  1. PHP >= 5.5.9
  2. composer
  3. openssl 拓展
  4. fileinfo 拓展(素材管理模块需要用到)

SDK 对所使用的框架并无特别要求

Installation

  1. composer require "freyo/entwechat" -vvv

Usage

使用示例:

  1. <?php
  2. use EntWeChat\Foundation\Application;
  3. $options = [
  4. 'debug' => true,
  5. 'corp_id' => 'wx3cf0f39249eb0e60',
  6. 'secret' => 'Nyn7Yuw-YbqDZeWiWZM6HqghGkXTFdZbaXpnk6w4G1IQwgtTuOl_TN09ciwpQ-5X',
  7. // ...
  8. ];
  9. $app = new Application($options);
  10. //微信端网页授权
  11. $app->oauth->setRedirectUrl('http://example.org')
  12. ->scopes(['snsapi_base'])
  13. ->redirect()
  14. ->send();
  15. //获取授权用户信息
  16. $user = $app->oauth->user();
  17. //$user->UserId //企业成员授权时
  18. //$user->DeviceId
  19. //$user->OpenId //非企业成员授权时
  20. //PC端扫码登录
  21. $app->auth->with(['usertype' => 'member'])
  22. ->setRedirectUrl('http://example.org')
  23. ->redirect()
  24. ->send();
  25. //获取登录用户信息
  26. $user = $app->auth->user();
  27. //登录用户为企业号成员时
  28. //$user->usertype
  29. //$user->user_info['userid'] //name,email,avatar
  30. //$user->redirect_login_info['login_ticket']
  31. //$user->corp_info['corpid']
  32. //通过userid获取用户信息
  33. $app->user->get('userid');
  34. //获取指定部门id下成员
  35. $deptId = 0;
  36. $app->user->lists($deptId);
  37. //获取部门列表
  38. $app->user_department->lists();
  39. //获取标签列表
  40. $app->user_tag->lists();
  41. //获取指定标签id下成员
  42. $tagId = 0;
  43. $app->user_tag->usersOfTag($tagId);
  44. //发送消息给指定用户通过指定应用id
  45. $news = new \EntWeChat\Message\News([
  46. 'title' => '图文标题',
  47. 'description' => '图文描述',
  48. 'url' => 'http://example.org',
  49. 'image' => 'http://mat1.gtimg.com/cq/js/news/tina/wenhua2.jpg',
  50. ]);
  51. $agentId = 0;
  52. $app->broadcast->message($news)->by($agentId)->toUser('userid')->send(); //单图文
  53. $app->broadcast->message([$news, $news])->by($agentId)->toUser('userid')->send(); //多图文
  54. $app->broadcast->message($news)->by($agentId)->toAll()->send(); //发送给所有人
  55. $app->broadcast->message($news) //发送给指定用户、部门、标签
  56. ->by($agentId)
  57. ->toUser('userid1', 'userid2')
  58. ->toParty($deptId)
  59. ->toTag($tagId)
  60. ->send();
  61. //服务端回调
  62. $server = $app->server;
  63. $user = $app->user;
  64. $server->setMessageHandler(function($message) use ($user) {
  65. // $message->FromUserName // 用户的 openid
  66. // $message->MsgType // 消息类型:event, text....
  67. $fromUser = $user->get($message->FromUserName);
  68. return "{$fromUser->nickname} 您好!欢迎关注!";
  69. });
  70. $server->serve()->send();

文档完善中。