Skip to content

Commit

Permalink
Merge pull request #9 from ofcold/dev-3
Browse files Browse the repository at this point in the history
Dev 3
  • Loading branch information
lilianjin authored Jun 20, 2018
2 parents e02a6ca + 85d3f2f commit 5297afc
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:|--|

Expand Down
26 changes: 26 additions & 0 deletions src/Qcold/Qcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down Expand Up @@ -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;
}
}
235 changes: 235 additions & 0 deletions src/Qcold/Template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<?php

namespace Ofcold\LuminousSMS\Qcold;

use Ofcold\LuminousSMS\Helpers;
use Ofcold\LuminousSMS\Results;
use Ofcold\LuminousSMS\Exceptions\HandlerBadException;

/**
* Class Template
*
* @link https://ofcold.com
* @link https://ofcold.com/license
*
* @author Ofcold <support@ofcold.com>
* @author Olivia Fu <olivia@ofcold.com>
* @author Bill Li <bill.li@ofcold.com>
*
* @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];
}

}
24 changes: 24 additions & 0 deletions src/Yunpian/Yunpian.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Ofcold\LuminousSMS\Qcold;

use Ofcold\LuminousSMS\Handlers;

/**
* Class Yunpian
*
* @link https://ofcold.com
* @link https://ofcold.com/license
*
* @author Ofcold <support@ofcold.com>
* @author Olivia Fu <olivia@ofcold.com>
* @author Bill Li <bill.li@ofcold.com>
*
* @package Ofcold\LuminousSMS\Qcold\Yunpian
*
* @copyright Copyright (c) 2017-2018, Ofcold. All rights reserved.
*/
class Yunpian extends Handlers
{

}

0 comments on commit 5297afc

Please sign in to comment.