Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
caicheng committed Dec 10, 2018
0 parents commit ac0428f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/*
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "dishcheng/dd_notice",
"description": "网易云短信包",
"keywords": [
"叮叮",
"推送",
"通知",
"机器人"
],
"license": "MIT",
"authors": [
{
"name": "caicheng",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.0.0",
"laravel/framework": ">=5.5"
},
"autoload": {
"psr-4": {
"DishCheng\\DdNotice\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"DishCheng\\DdNotice\\DdNoticeProvider"
],
"aliases": {
"DdNotice": "DishCheng\\DdNotice\\DdNotice"
}
}
},
"minimum-stability": "dev"
}
12 changes: 12 additions & 0 deletions config/dd_notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Created by PhpStorm.
* User: caicheng
* Date: 2018-12-10
* Time: 11:16
*/

return [
'robot_webhook' => env('DD_WEBHOOK', ''), //叮叮机器人请求地址
'notice_active' => env('DD_NOTICE_ACTIVE', true)
];
26 changes: 26 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 叮叮机器人sdk

For laravel >= 5.5

> composer require dishcheng/dd_notice
[官方设置说明](https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1)

sdk设置说明
> php artisan vendor:publish --tag=dd_notice
将webhook地址粘贴到config/dd_notice.php中的robot_webhook位置

文本推送方法:
```
use DishCheng\DdNotice\DdNotice;
DdNotice::send([
'msgtype' => 'text',
'text' => [
'content' => '测试文本'
]
]);
```

更多方法参考官方设置说明
36 changes: 36 additions & 0 deletions src/DdNotice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace DishCheng\DdNotice;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Facade;

/**
* Created by PhpStorm.
* User: caicheng
* Date: 2018-11-28
* Time: 18:42
*/
class DdNotice extends Facade
{
public static function send(array $params)
{
$client = new Client();
try {
if (config('dd_notice.notice_active')) {
$res = $client->request('post', config('dd_notice.robot_webhook'),
[
'headers' =>
[
'Content-Type' => 'application/json;charset=utf-8',
],
'body' => json_encode($params),
]
);
return $res->getBody();
}
} catch (\GuzzleHttp\Exception\GuzzleException $exception) {
\Log::error(json_encode($exception->getMessage()));
}
}
}
28 changes: 28 additions & 0 deletions src/DdNoticeProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace DishCheng\DdNotice;

use Illuminate\Support\ServiceProvider;

class DdNoticeProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../config' => config_path(),],
'dd_notice'
);
}

public function register()
{
$this->app->bind(DdNotice::class, function () {
return new DdNotice();
});
}
}

0 comments on commit ac0428f

Please sign in to comment.