{"id":23272834,"url":"https://github.com/fenguoz/notifyservice","last_synced_at":"2025-10-27T13:30:59.759Z","repository":{"id":53030708,"uuid":"321250522","full_name":"Fenguoz/notifyService","owner":"Fenguoz","description":"Notify service developed based on the hyperf framework.(Support drivers include SMS、Email、Wechat、GeTui、RabbitMQ drivers, support methods include single, batch, and asynchronous queues, and support customization)","archived":false,"fork":false,"pushed_at":"2022-01-23T20:33:25.000Z","size":10170,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T19:19:43.163Z","etag":null,"topics":["email","notify","php","sms","wechat"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fenguoz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-14T06:08:05.000Z","updated_at":"2024-11-22T08:19:05.000Z","dependencies_parsed_at":"2022-09-09T12:11:22.930Z","dependency_job_id":null,"html_url":"https://github.com/Fenguoz/notifyService","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fenguoz%2FnotifyService","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fenguoz%2FnotifyService/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fenguoz%2FnotifyService/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fenguoz%2FnotifyService/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fenguoz","download_url":"https://codeload.github.com/Fenguoz/notifyService/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238497799,"owners_count":19482317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["email","notify","php","sms","wechat"],"created_at":"2024-12-19T19:19:44.985Z","updated_at":"2025-10-27T13:30:59.375Z","avatar_url":"https://github.com/Fenguoz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e通知服务\u003c/h1\u003e\n\n## 概述\n\n通知服务是微服务就是一个独立的实体，它可以独立被部署，也可以作为一个操作系统进程存在。服务与服务之间存在隔离性，服务之间均通过网络调用进行通信，从而加强服务之间的隔离性，避免紧耦合。\n\n该服务基于 Hyperf2.0 框架实现。通过 JSON RPC 轻量级的 RPC 协议标准，可自定义基于 HTTP 协议来传输，或直接基于 TCP 协议来传输方式实现服务注册。客户端只需要通过协议标准直接调用已封装好的方法即可。\n\n适用范围：短信、邮箱、微信、APP消息推送\n\n## 环境要求\n\n- PHP \u003e= 7.2\n- Swoole PHP 扩展 \u003e= 4.5，并关闭了 `Short Name`\n- Nginx\n- Consul\n\n## 特点\n\n1. 支持多种通知方式\n1. 一套写法兼容所有平台\n1. 配置即可灵活增减\n\n### 支持发送渠道\n\n- 短信 `Sms`\n- 邮箱 `Mail`\n- 微信 `Wechat`\n- APP消息推送 `App`\n- 自定义\n\n### 支持方法\n\n#### 消息 (/notify/)\n- 单条发送 `send(int $code, string $action, array $params)`\n- 批量发送 `sendBatch(int $code, string $action, array $params)`\n\n## 快速开始\n\n### 部署\n\n``` bash\n# 克隆项目\ngit clone ...\n\n# 进入根目录\ncd {file}\n\n# 安装扩展包\ncomposer install\n\n# 配置env文件\ncp .env.example .env\n\n# 运行 Consul（若已运行，忽略）\nconsul agent -dev -bind 127.0.0.1\n\n# 运行\nphp bin/hyperf.php start\n```\n\n### 各驱动配置说明\n短信\n\n``` php\n$notifyDriver = 'Sms';\n$config = [\n    'default' =\u003e [\n        'gateways' =\u003e ['moduyun']\n    ],\n    'gateways' =\u003e [\n        'moduyun' =\u003e [\n            'signId' =\u003e '****',\n            'accesskey' =\u003e '****',\n            'secretkey' =\u003e '****']\n        ]\n    ];\n\n// 内容使用 content + data 或 template + data\n$params = [\n    'template' =\u003e '****',                 // 选填 模版ID\n    'content' =\u003e '您的验证码是888888....',  // 选填 内容\n    'data' =\u003e [\n        'phone_number' =\u003e '18888888888',  // 必填 手机号\n        'area' =\u003e '18888888888',          // 选填 手机区号 默认:86\n        'code' =\u003e 888888,                 // 选填 模版参数\n        // ....,                          // 选填 模版参数\n    ]\n];\n```\n\n#### 邮箱\n\n``` php\n$notifyDriver = 'Mail';\n$config = [\n    'host' =\u003e 'smtp.live.com',\n    'port' =\u003e 587,\n    'smtp_secure' =\u003e 'ssl',\n    'username' =\u003e '',\n    'password' =\u003e '',\n    'send_mail' =\u003e '',\n    'send_nickname' =\u003e '',\n    'attachment' =\u003e ''\n];\n\n// 内容使用 content + data\n$params = [\n    'content' =\u003e '尊敬的xx用户：....',  // 必填 内容\n    'data' =\u003e [\n        'subject' =\u003e '邮箱验证码'       // 必填 副标题\n        'address' =\u003e 'xx@qq.com'      // 必填 副标题\n    ]\n];\n```\n\n#### App\n``` php\n$notifyDriver = 'App';\n$config = [\n    'app_id' =\u003e 'xxx',\n    'app_key' =\u003e 'xxx',\n    'app_secret' =\u003e 'xxx',\n    'master_secret' =\u003e 'xxx'\n];\n\n// 内容使用 content + data\n$params = [\n    'content' =\u003e '恭喜成功注册成为xxx平台会员！', // 必填 内容\n    'data' =\u003e [\n        'title' =\u003e '注册成功通知',              // 必填 标题\n        'client_id' =\u003e 'xxx'                  // 必填 客户端ID\n    ]\n];\n```\n\n#### 微信\n``` php\n$notifyDriver = 'Wechat';\n$config = [\n    'officialAccount' =\u003e [\n        'app_id' =\u003e 'xxx',\n        'secret' =\u003e 'xxx',\n        'response_type' =\u003e 'array'\n    ],\n    'miniProgram' =\u003e [\n        'app_id' =\u003e 'xxx',\n        'secret' =\u003e 'xxx',\n        'response_type' =\u003e 'array'\n    ]\n];\n\n// 内容使用 template + data\n$params = [\n    'template' =\u003e 'xxx',            // 必填 公众号模版ID\n    'data' =\u003e [\n        'openid' =\u003e 'xxx',          // 必填 公众号OpenId\n        'data' =\u003e [                 // 必填 模版数据\n            'keyword1' =\u003e 'VALUE',\n            'keyword2' =\u003e 'VALUE2',\n            // ....,\n        ],\n        'url' =\u003e '',                // 选填 公众号跳转\n        'miniprogram_path' =\u003e ''    // 选填 小程序跳转(优先级高于公众号)\n    ]\n];\n```\n\n### 接口调用\nHyperf 调用示例：\n``` php\nuse Hyperf\\Di\\Annotation\\Inject;\nuse App\\Rpc\\NotifyServiceInterface;\n\nclass Xxx\n{\n    /**\n     * @Inject\n     * @var NotifyServiceInterface\n     */\n    protected $notifyService;\n\n    public function demo()\n    {\n        $ret = $this-\u003enotifyService-\u003esend($notifyDriver, $config, $params);\n    }\n}\n\n```\n\nPHP 调用示例：\n``` php\nuse GuzzleHttp\\Client;\n\n$host = 'http://127.0.0.1:9801';\n(new Client)-\u003epost($host, [\n    'json' =\u003e [\n        'jsonrpc' =\u003e '2.0',\n        'method' =\u003e '/notify/send',\n        'params' =\u003e [$notifyDriver, $config, $params],\n        'id' =\u003e 1,\n    ]\n]);\n```\n\n## 扩展包\n\n| 扩展包名 | 描述 | 应用场景 |\n| :-----| :---- | :---- |\n| [yurunsoft/phpmailer-swoole](https://github.com/Yurunsoft/PHPMailer-Swoole) | Swoole 协程环境下的可用的 PHPMailer | 发送邮箱通知 |\n| [overtrue/easy-sms](https://github.com/overtrue/easy-sms) | 一款满足你的多种发送需求的短信发送组件 | 发送短信通知 |\n| [overtrue/wechat](https://github.com/w7corp/easywechat) | 世界上最好的微信开发SDK | 发送微信通知 |\n| [getuilaboratory/getui-pushapi-php-client](https://github.com/GetuiLaboratory/getui-pushapi-php-client) | APP应用消息推送SDK | APP站内推送通知 |\n\n## 脚本命令\n\n| 命令行 | 说明 | crontab |\n| :-----| :---- | :---- |\n| composer install | 安装扩展包 | -- |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffenguoz%2Fnotifyservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffenguoz%2Fnotifyservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffenguoz%2Fnotifyservice/lists"}