From 2174c332067d02f81c0e39a7cd28a2f32f00a509 Mon Sep 17 00:00:00 2001 From: Bill li Date: Wed, 20 Jun 2018 17:39:21 +0800 Subject: [PATCH 1/3] Template --- src/Qcold/Qcloud.php | 26 +++++ src/Qcold/Template.php | 235 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+) diff --git a/src/Qcold/Qcloud.php b/src/Qcold/Qcloud.php index 763c1ed..3500691 100644 --- a/src/Qcold/Qcloud.php +++ b/src/Qcold/Qcloud.php @@ -41,6 +41,12 @@ class Qcloud extends Handlers 'remove' => 'tlssmssvr/del_sign', 'query' => 'tlssmssvr/get_sign' ], + 'template' => [ + 'add' => 'tlssmssvr/add_template', + 'edit' => 'tlssmssvr/mod_template', + 'remove' => 'tlssmssvr/del_template', + 'query' => 'tlssmssvr/get_template', + ], 'tatol' => [ 'sender' => 'tlssmssvr/pullsendstatus' ] @@ -80,4 +86,24 @@ public function getSignature(?string $method = null, ...$attributes) return $instance; } + + /** + * Get the Template instance. + * + * @param string|null $method + * @param array $attributes + * + * @return mixed + */ + public function getTemplate(?string $method = null, ...$attributes) + { + $instance = new Template($this); + + if ( $method && method_exists($instance, $method) ) + { + return $instance->$method(...$attributes); + } + + return $instance; + } } \ No newline at end of file diff --git a/src/Qcold/Template.php b/src/Qcold/Template.php index e69de29..e3f549c 100644 --- a/src/Qcold/Template.php +++ b/src/Qcold/Template.php @@ -0,0 +1,235 @@ + + * @author Olivia Fu + * @author Bill Li + * + * @package Ofcold\LuminousSMS\Qcold\Template + * + * @copyright Copyright (c) 2017-2018, Ofcold. All rights reserved. + */ +class Template +{ + /** + * The qcloud instance. + * + * @var Qcloud + */ + protected $qcloud; + + /** + * Create an a new Sender. + * + * @param Qcloud $qcloud + */ + public function __construct(Qcloud $qcloud) + { + $this->qcloud = $qcloud; + } + + /** + * Add template. + * + * @param string $template + * @param string $text + * @param string $remark + * @param int $type + * + * @return array + */ + public function add(string $title, string $text, string $remark = '', $type = 0) : array + { + $params = [ + 'title' => $title, + 'text' => $text, + 'remark' => $remark, + 'time' => time() + ]; + + $random = Helpers::random(10); + + $params['sig'] = $this->createSign($params, $random); + + return Results::render($this->qcloud->request( + 'post', + sprintf( + '%s%s?sdkappid=%s&random=%s', + Qcloud::REQUEST_URL, + $this->requestMehtod('add'), + $this->qcloud->getConfig('app_id'), + $random + ), + [ + 'headers' => [ + 'Accept' => 'application/json' + ], + 'json' => $params, + ] + )); + } + + /** + * Edit template. + * + * @param int $id + * @param string $title + * @param string $text + * @param string $remark + * @param int $type + * + * @return array + */ + public function edit(int $id, string $title, string $text, string $remark = '', $type = 0) : array + { + $params = [ + 'title' => $title, + 'text' => $text, + 'tpl_id' => $id, + 'pic' => $picture, + 'remark' => $remark, + 'time' => time() + ]; + + $random = Helpers::random(10); + + $params['sig'] = $this->createSign($params, $random); + + return Results::render($this->qcloud->request( + 'post', + sprintf( + '%s%s?sdkappid=%s&random=%s', + Qcloud::REQUEST_URL, + $this->requestMehtod('edit'), + $this->qcloud->getConfig('app_id'), + $random + ), + [ + 'headers' => [ + 'Accept' => 'application/json' + ], + 'json' => $params, + ] + )); + } + + /** + * Query template. + * + * @param array $ids + * + * @return array + */ + public function query(array $ids) : array + { + $random = Helpers::random(10); + + $params = [ + 'time' => time() + ]; + + $params['sig'] = $this->createSign($params, $random); + $params['template_id'] = $ids; + + return Results::render($this->qcloud->request( + 'post', + sprintf( + '%s%s?sdkappid=%s&random=%s', + Qcloud::REQUEST_URL, + $this->requestMehtod('query'), + $this->qcloud->getConfig('app_id'), + $random + ), + [ + 'headers' => [ + 'Accept' => 'application/json' + ], + 'json' => $params, + ] + )); + } + + /** + * Remove Sign. + * + * @param array $ids + * + * @return array + */ + public function remove($ids) : array + { + $random = Helpers::random(10); + + $params = [ + 'time' => time() + ]; + + $params['sig'] = $this->createSign($params, $random); + $params['template_id'] = $ids; + + return Results::render($this->qcloud->request( + 'post', + sprintf( + '%s%s?sdkappid=%s&random=%s', + Qcloud::REQUEST_URL, + $this->requestMehtod('remove'), + $this->qcloud->getConfig('app_id'), + $random + ), + [ + 'headers' => [ + 'Accept' => 'application/json' + ], + 'json' => $params, + ] + )); + } + + /** + * Generate Sign. + * + * @param array $params + * @param string $random + * + * @return string + */ + protected function createSign(array $params, string $random) : string + { + ksort($params); + + return hash( + 'sha256', + sprintf( + 'appkey=%s&random=%s&time=%s', + $this->qcloud->getConfig('app_key'), + $random, + $params['time'] + ), + false + ); + } + + /** + * Request uri path. + * + * @param string $name + * + * @return string + */ + protected function requestMehtod(string $name) : string + { + return Qcloud::REQUEST_METHOD['template'][$name]; + } + +} \ No newline at end of file From 2313cac637e0f7f9180fca0e2662cb5ab565fd23 Mon Sep 17 00:00:00 2001 From: Bill li Date: Wed, 20 Jun 2018 17:41:33 +0800 Subject: [PATCH 2/3] Yunpian --- src/Yunpian/Yunpian.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Yunpian/Yunpian.php diff --git a/src/Yunpian/Yunpian.php b/src/Yunpian/Yunpian.php new file mode 100644 index 0000000..16ad5b2 --- /dev/null +++ b/src/Yunpian/Yunpian.php @@ -0,0 +1,24 @@ + + * @author Olivia Fu + * @author Bill Li + * + * @package Ofcold\LuminousSMS\Qcold\Yunpian + * + * @copyright Copyright (c) 2017-2018, Ofcold. All rights reserved. + */ +class Yunpian extends Handlers +{ + +} \ No newline at end of file From 85d3f2fb210604be1812902cc8093720e587bddb Mon Sep 17 00:00:00 2001 From: Bill li Date: Wed, 20 Jun 2018 17:41:39 +0800 Subject: [PATCH 3/3] update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7954099..e079ca2 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ A powerful international SMS push. ## Platform support |供应商|开发状态|时间| |--------|--------|--------| -|[腾讯云 SMS](https://cloud.tencent.com/product/sms)|:clock8:|2018-06-20| -|[云片](https://www.yunpian.com)|:x:|--| +|[腾讯云 SMS](https://cloud.tencent.com/product/sms)|:white_check_mark:|2018-06-20| +|[云片](https://www.yunpian.com)|:clock8:|2018-06-21| |[阿里大鱼](https://www.alidayu.com)|:x:|--| |[百度云](https://cloud.baidu.com)|:x:|--|