Skip to content

Commit

Permalink
Add type function to Messager and fix Oclod.
Browse files Browse the repository at this point in the history
  • Loading branch information
bill li authored and bill li committed Jan 24, 2018
1 parent 71cc994 commit f78b07b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/Handlers/Qclod.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Qclod extends Handler
{
protected const REQUEST_URL = 'https://yun.tim.qq.com/v5/';

protected const REQUEST_METHOD = 'tlssmssvr/sendsms';
protected const REQUEST_METHOD = [
'text' => 'tlssmssvr/sendsms',
'voice' => 'tlsvoicesvr/sendvoiceprompt'
];

protected const REQUEST_FORMAT = 'json';

Expand All @@ -46,17 +49,7 @@ class Qclod extends Handler
*/
public function send(MessagerInterface $messager) : array
{
$params = [
'tel' => [
'nationcode' => $messager->getCode(),
'mobile' => $messager->getMobilePhone()
],
'type' => MessagerInterface::TEXT_MESSAGE,
'msg' => $messager->getContent(),
'time' => time(),
'extend' => '',
'ext' => ''
];
$params = $this->{$messager->getType()}($messager);

$random = Stringy::random(10);

Expand All @@ -67,7 +60,7 @@ public function send(MessagerInterface $messager) : array
sprintf(
'%s%s?sdkappid=%s&random=%s',
static::REQUEST_URL,
static::REQUEST_METHOD,
static::REQUEST_METHOD[$messager->getType()],
Arrays::get($this->config, 'app_id'),
$random
),
Expand All @@ -87,6 +80,35 @@ public function send(MessagerInterface $messager) : array
return $result;
}

protected function text(MessagerInterface $messager) : array
{
return [
'tel' => [
'nationcode' => $messager->getCode(),
'mobile' => $messager->getMobilePhone()
],
'type' => (int)($messager->getType() !== 'text'),
'msg' => $messager->getContent(),
'time' => time(),
'extend' => '',
'ext' => ''
];
}

protected function voice(MessagerInterface $messager) : array
{
return [
'tel' => [
'nationcode' => $messager->getCode(),
'mobile' => $messager->getMobilePhone()
],
'msg' => $messager->getContent(),
'playtimes' => 2,
'time' => time(),
'ext' => ''
];
}

/**
* Generate Sign.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ class Messenger implements MessagerInterface

protected $mobilePhone;

public function getType()
{
return $this->type ?: static::TEXT_MESSAGE;
}

public function setType(string $type) : MessagerInterface
{
$this->type = $type;

return $this;
}

/**
* Return the country code.
*
Expand Down

0 comments on commit f78b07b

Please sign in to comment.