git 代码推送通知
在公司进行开发时,如何优雅而又不尴尬的让老板知道自己每天几点下班,好让老板加工资,这是一个问题。
现在应该基本每个公司用钉钉,而钉钉又有机器人可以自动推送,😆,git 可以使用 webhook,于是,就有了这样一个系统。
当然,根据 git 的 webhook 特性,大家可以打开脑洞,随意实现有意思的功能。
- 隐藏不需要关心的内部流程
- 可以随意增加现有类库中没有的服务
- gitee (码云)
- dingtalk (钉钉)
实现消息推送功能
composer require yansongda/git-notify
http://your-domain/?from=gitee&to=dingtalk
<?php
require './vendor/autoload.php';
$notify = new Yansongda\GitNotify\GitNotify();
// 可选。gitee 可以设置 webhook 密码,防止 URL 被恶意请求
// $notify->from->password = '123456';
// 可选。可以随意设置发送模板与格式。这里用到闭包。
// $from 为 git 服务。
/* $notify->destination->setTemplate(function ($from) {
$data['msgtype'] = 'hahaha';
$data['text']['content'] = "姓名:" . $from->user_name .
"\n\before:" . $from->before .
"\n\nafter:" . $from->after .
"\n\n推送时间:" . date('Y-m-d H:i:s');
return $data;
});*/
$notify->destination->gateway = 'https://oapi.dingtalk.com/robot/send?access_token=36c01ca8552fa8f9f6xxxxx';
$response = $notify->destination->apply();
$result = $response->getBody()->getContents();
MIT