AppService.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app;
  12. use app\listener\wechat\OffcialAccountListener;
  13. use app\listener\wechat\OpenPlatformListener;
  14. use app\listener\wechat\RoutineListener;
  15. use app\listener\wechat\WorkListener;
  16. use crmeb\services\SystemConfigService;
  17. use app\services\work\WorkConfigServices;
  18. use crmeb\services\GroupDataService;
  19. use crmeb\services\wechat\config\HttpCommonConfig;
  20. use crmeb\services\wechat\config\LogCommonConfig;
  21. use crmeb\services\wechat\config\WorkConfig;
  22. use crmeb\services\wechat\MiniProgram;
  23. use crmeb\services\wechat\OfficialAccount;
  24. use crmeb\services\wechat\OpenPlatform;
  25. use crmeb\services\wechat\Work;
  26. use crmeb\utils\Json;
  27. use think\Service;
  28. use Yurun\Util\Swoole\Guzzle\SwooleHandler;
  29. use GuzzleHttp\DefaultHandler;
  30. /**
  31. * Class AppService
  32. * @package app
  33. */
  34. class AppService extends Service
  35. {
  36. public $bind = [
  37. 'json' => Json::class,
  38. 'sysConfig' => SystemConfigService::class,
  39. 'sysGroupData' => GroupDataService::class
  40. ];
  41. public function boot()
  42. {
  43. defined('DS') || define('DS', DIRECTORY_SEPARATOR);
  44. DefaultHandler::setDefaultHandler(SwooleHandler::class);
  45. }
  46. /**
  47. * 注册
  48. */
  49. public function register()
  50. {
  51. //http配置服务
  52. $this->app->bind(HttpCommonConfig::class, function () {
  53. return (new HttpCommonConfig())->setServe(\app\services\system\config\SystemConfigServices::class);
  54. });
  55. //公众号
  56. $this->app->bind(OfficialAccount::class, function () {
  57. return (new OfficialAccount)->setPushMessageHandler(OffcialAccountListener::class);
  58. });
  59. //小程序
  60. $this->app->bind(MiniProgram::class, function () {
  61. return (new MiniProgram)->setPushMessageHandler(RoutineListener::class);
  62. });
  63. //开放平台
  64. $this->app->bind(OpenPlatform::class, function () {
  65. return (new OpenPlatform)->setPushMessageHandler(OpenPlatformListener::class);
  66. });
  67. //实例化企业微信配置
  68. $this->app->bind(WorkConfig::class, function () {
  69. return (new WorkConfig(new LogCommonConfig(), $this->app->make(HttpCommonConfig::class)))->setHandler(WorkConfigServices::class);
  70. });
  71. //企业微信
  72. $this->app->bind(Work::class, function () {
  73. return (new Work)->setPushMessageHandler(WorkListener::class)
  74. ->setConfigHandler(WorkConfigServices::class);
  75. });
  76. }
  77. }