-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot; | ||
|
||
class Client extends \Guanguans\Notify\Foundation\Client | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot; | ||
|
||
use Guanguans\Notify\Foundation\UriTemplateTokenCredential; | ||
|
||
class Credential extends UriTemplateTokenCredential | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot\Messages; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
|
||
class ImageMessage extends Message | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $defined = [ | ||
'imagePath', | ||
]; | ||
|
||
public function __construct(string $imagePath) | ||
{ | ||
parent::__construct([ | ||
'imagePath' => $imagePath, | ||
]); | ||
} | ||
|
||
public function toHttpOptions(): array | ||
{ | ||
return [ | ||
RequestOptions::JSON => [ | ||
'msgtype' => $this->type(), | ||
$this->type() => [ | ||
'base64' => base64_file($this->options['imagePath']), | ||
'md5' => md5_file($this->options['imagePath']), | ||
], | ||
], | ||
]; | ||
} | ||
|
||
protected function type(): string | ||
{ | ||
return 'image'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot\Messages; | ||
|
||
class MarkdownMessage extends Message | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $defined = [ | ||
'content', | ||
]; | ||
|
||
public function __construct(string $content) | ||
{ | ||
parent::__construct([ | ||
'content' => $content, | ||
]); | ||
} | ||
|
||
protected function type(): string | ||
{ | ||
return 'markdown'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot\Messages; | ||
|
||
use Guanguans\Notify\Foundation\Concerns\AsJson; | ||
use Guanguans\Notify\Foundation\Concerns\AsPost; | ||
use Guanguans\Notify\WeWorkGroupBot\Credential; | ||
use GuzzleHttp\RequestOptions; | ||
|
||
abstract class Message extends \Guanguans\Notify\Foundation\Message | ||
{ | ||
use AsPost; | ||
use AsJson; | ||
|
||
public function httpUri() | ||
{ | ||
return sprintf('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s', Credential::TEMPLATE_TOKEN); | ||
} | ||
|
||
public function toHttpOptions(): array | ||
{ | ||
return [ | ||
RequestOptions::JSON => [ | ||
'msgtype' => $this->type(), | ||
$this->type() => $this->getOptions(), | ||
], | ||
]; | ||
} | ||
|
||
abstract protected function type(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot\Messages; | ||
|
||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class NewsMessage extends Message | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $defined = [ | ||
'articles', | ||
]; | ||
|
||
/** | ||
* @var array<string, string> | ||
*/ | ||
protected $allowedTypes = [ | ||
'articles' => 'array', | ||
]; | ||
|
||
/** | ||
* @var array[] | ||
*/ | ||
protected array $options = [ | ||
'articles' => [], | ||
]; | ||
|
||
public function __construct(array $articles = []) | ||
{ | ||
parent::__construct([ | ||
'articles' => $articles, | ||
]); | ||
} | ||
|
||
protected function configureOptionsResolver(OptionsResolver $optionsResolver): OptionsResolver | ||
{ | ||
return tap(parent::configureOptionsResolver($optionsResolver), static function (OptionsResolver $resolver): void { | ||
$resolver->setNormalizer('articles', static function (OptionsResolver $optionsResolver, array $value): array { | ||
return isset($value[0]) ? $value : [$value]; | ||
}); | ||
}); | ||
} | ||
|
||
public function setArticles(array $articles): self | ||
{ | ||
return $this->addArticles($articles); | ||
} | ||
|
||
public function addArticles(array $articles): self | ||
{ | ||
foreach ($articles as $article) { | ||
$this->addArticle($article); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function setArticle(array $article): self | ||
{ | ||
return $this->addArticle($article); | ||
} | ||
|
||
public function addArticle(array $article): self | ||
{ | ||
$this->options['articles'][] = configure_options($article, static function (OptionsResolver $optionsResolver): void { | ||
$optionsResolver->setDefined([ | ||
'title', | ||
'description', | ||
'url', | ||
'picurl', | ||
]); | ||
}); | ||
|
||
return $this; | ||
} | ||
|
||
protected function type(): string | ||
{ | ||
return 'news'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/notify. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\Notify\WeWorkGroupBot\Messages; | ||
|
||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class TextMessage extends Message | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $defined = [ | ||
'content', | ||
'mentioned_list', | ||
'mentioned_mobile_list', | ||
]; | ||
|
||
/** | ||
* @var array<string, array<string>> | ||
*/ | ||
protected $allowedTypes = [ | ||
'mentioned_list' => ['int', 'string', 'array'], | ||
'mentioned_mobile_list' => ['int', 'string', 'array'], | ||
]; | ||
|
||
protected function configureOptionsResolver(OptionsResolver $optionsResolver): OptionsResolver | ||
{ | ||
return tap(parent::configureOptionsResolver($optionsResolver), static function (OptionsResolver $resolver): void { | ||
$resolver->setNormalizer('mentioned_list', static function (OptionsResolver $optionsResolver, $value): array { | ||
return (array) $value; | ||
}); | ||
$resolver->setNormalizer('mentioned_mobile_list', static function (OptionsResolver $optionsResolver, $value): array { | ||
return (array) $value; | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setContent(string $content): self | ||
{ | ||
$this->setOption('content', $content); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setMentionedList(array $mentionedList): self | ||
{ | ||
$this->setOption('mentioned_list', $mentionedList); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setMentionedMobileList(array $mentionedMobileList): self | ||
{ | ||
$this->setOption('mentioned_mobile_list', $mentionedMobileList); | ||
|
||
return $this; | ||
} | ||
|
||
protected function type(): string | ||
{ | ||
return 'text'; | ||
} | ||
} |