Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit 045b804

Browse files
committed
支持Push响应
1 parent f7e0121 commit 045b804

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

index.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function object_to_array(object $obj): array
2020
* @param object $event
2121
* @param object $context
2222
* @return array
23+
* @noinspection PhpMissingReturnTypeInspection
24+
* @noinspection PhpMissingParamTypeInspection
25+
* @noinspection PhpUnusedParameterInspection
2326
*/
2427
function main_handler($event, $context)
2528
{
@@ -33,6 +36,31 @@ function main_handler($event, $context)
3336
case "ping":
3437
$res = $wechat->sendMessage("收到Ping请求,字符串为".$body['zen'].",hookId为".$body['hook_id']."");
3538
break;
39+
case "push":
40+
$message = <<<EOF
41+
### 有新的Push事件
42+
43+
仓库: [{$body['repository']['name']}]({$body['repository']['html_url']})
44+
45+
推送者: [{$body['pusher']['name']}({$body['pusher']['email']})]({$body['sender']['html_url']})
46+
47+
EOF;
48+
foreach ($body['commits'] as $commit) {
49+
$message .= <<<EOF
50+
51+
> Commit {$commit['id']}:
52+
>
53+
> <font color=\"comment\">{$commit['message']}</font>
54+
>
55+
> on {$commit['timestamp']}
56+
>
57+
> [查看详情]({$commit['url']})
58+
59+
EOF;
60+
}
61+
$message .= "\nSHA: ".$body['after'];
62+
$res = $wechat->sendMarkdownMessage($message);
63+
break;
3664
}
3765

3866
return [

wework.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public function sendMessage(string $message, array $mentioned_list = []): array
3939
return $this->curl_send($data);
4040
}
4141

42+
/**
43+
* @describe 发送Markdown消息
44+
* @param string $message
45+
* @return array
46+
*/
47+
public function sendMarkdownMessage(string $message): array
48+
{
49+
$data = json_encode([
50+
"msgtype" => "markdown",
51+
"markdown" => [
52+
"content" => $message
53+
]
54+
]);
55+
return $this->curl_send($data);
56+
}
57+
4258
/**
4359
* 获取Gateway Url
4460
* @return string 企业微信发送地址

0 commit comments

Comments
 (0)