Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Aug 7, 2023
2 parents 67252a6 + 78b9bda commit 90643d9
Show file tree
Hide file tree
Showing 11 changed files with 711 additions and 31 deletions.
28 changes: 0 additions & 28 deletions .php_cs

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 overtrue

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [百度云](https://cloud.baidu.com/)
- [华信短信平台](http://www.ipyy.com/)
- [253云通讯(创蓝)](https://www.253.com/)
- [创蓝云智](https://www.chuanglan.com/)
- [融云](http://www.rongcloud.cn)
- [天毅无线](http://www.85hu.com/)
- [阿凡达数据](http://www.avatardata.cn/)
Expand All @@ -58,6 +59,7 @@
- [融合云信](https://maap.wo.cn/)
- [天瑞云](http://cms.tinree.com/)
- [时代互联](https://www.now.cn/)
- [火山引擎](https://console.volcengine.com/sms/)

## 环境需求

Expand Down Expand Up @@ -520,6 +522,45 @@ $easySms->send($phone_number, [
],
```

### [创蓝云智](https://www.chuanglan.com/)

普通短信发送内容使用 `content`

```php
'chuanglanv1' => [
'account' => '',
'password' => '',
'needstatus' => false,
'channel' => \Overtrue\EasySms\Gateways\ChuanglanV1Gateway::CHANNEL_NORMAL_CODE,
],
```
发送示例:

```php
$easySms->send(18888888888, [
'content' => xxxxxxx
]);
```

变量短信发送内容使用 `template` + `data`

```php
'chuanglanv1' => [
'account' => '',
'password' => '',
'needstatus' => false,
'channel' => \Overtrue\EasySms\Gateways\ChuanglanV1Gateway::CHANNEL_VARIABLE_CODE,
],
```
发送示例:

```php
$easySms->send(18888888888, [
'template' => xxxxxx, // 模板内容
'data' => 'phone":"15800000000,1234;15300000000,4321',
]);
```

### [融云](http://www.rongcloud.cn)

短信分为两大类,验证类和通知类短信。 发送验证类短信使用 `template` + `data`
Expand Down Expand Up @@ -886,6 +927,7 @@ $easySms->send(18888888888, [
```

### [时代互联](https://www.now.cn/)

短信使用 `content`

```php
Expand All @@ -903,6 +945,43 @@ $easySms->send(18888888888, [
]);
```

### [火山引擎](https://console.volcengine.com/sms/)

短信内容使用 `template` + `data`

```php
'volcengine' => [
'access_key_id' => '', // 平台分配给用户的access_key_id
'access_key_secret' => '', // 平台分配给用户的access_key_secret
'region_id' => 'cn-north-1', // 国内节点 cn-north-1,国外节点 ap-singapore-1,不填或填错,默认使用国内节点
'sign_name' => '', // 平台上申请的接口短信签名或者签名ID,可不填,发送短信时data中指定
'sms_account' => '', // 消息组帐号,火山短信页面右上角,短信应用括号中的字符串,可不填,发送短信时data中指定
],
```

发送示例1:

```php
$easySms->send(18888888888, [
'template' => 'SMS_123456', // 模板ID
'data' => [
"code" => 1234 // 模板变量
],
]);
```

发送示例2:
```php
$easySms->send(18888888888, [
'template' => 'SMS_123456', // 模板ID
'data' => [
"template_param" => ["code" => 1234], // 模板变量参数
"sign_name" => "yoursignname", // 签名,覆盖配置文件中的sign_name
"sms_account" => "yoursmsaccount", // 消息组帐号,覆盖配置文件中的sms_account
"phone_numbers" => "18888888888,18888888889", // 手机号,批量发送,英文的逗号连接多个手机号,覆盖发送方法中的填入的手机号
],
]);
```

## :heart: 支持我

Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/AliyunGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config

$result = $this->get(self::ENDPOINT_URL, $params);

if ('OK' != $result['Code']) {
if (!empty($result['Code']) && 'OK' != $result['Code']) {
throw new GatewayErrorException($result['Message'], $result['Code'], $result);
}

Expand Down
147 changes: 147 additions & 0 deletions src/Gateways/Chuanglanv1Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

/*
* This file is part of the overtrue/easy-sms.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Overtrue\EasySms\Gateways;

use Overtrue\EasySms\Contracts\MessageInterface;
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
use Overtrue\EasySms\Exceptions\GatewayErrorException;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
use Overtrue\EasySms\Support\Config;
use Overtrue\EasySms\Traits\HasHttpRequest;

/**
* Class ChuanglanGateway.
*
* @see https://www.chuanglan.com/document/6110e57909fd9600010209de/62b3dc1d272e290001af3e75
*/
class Chuanglanv1Gateway extends Gateway
{
use HasHttpRequest;

/**
* 国际短信
*/
const INT_URL = 'http://intapi.253.com/send/json';

/**
* URL模板
*/
const ENDPOINT_URL_TEMPLATE = 'https://smssh1.253.com/msg/%s/json';

/**
* 支持单发、群发短信
*/
const CHANNEL_NORMAL_CODE = 'v1/send';

/**
* 单号码对应单内容批量下发
*/
const CHANNEL_VARIABLE_CODE = 'variable';

/**
* @param PhoneNumberInterface $to
* @param MessageInterface $message
* @param Config $config
*
* @return array
*
* @throws GatewayErrorException
* @throws InvalidArgumentException
*/
public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
{
$IDDCode = !empty($to->getIDDCode()) ? $to->getIDDCode() : 86;

$params = [
'account' => $config->get('account'),
'password' => $config->get('password'),
'report' => $config->get('needstatus') ?? false
];

if (86 != $IDDCode) {
$params['mobile'] = $to->getIDDCode() . $to->getNumber();
$params['account'] = $config->get('intel_account') ?: $config->get('account');
$params['password'] = $config->get('intel_password') ?: $config->get('password');
}

if (self::CHANNEL_VARIABLE_CODE == $this->getChannel($config, $IDDCode)) {
$params['params'] = $message->getData($this);
$params['msg'] = $this->wrapChannelContent($message->getTemplate($this), $config, $IDDCode);
} else {
$params['phone'] = $to->getNumber();
$params['msg'] = $this->wrapChannelContent($message->getContent($this), $config, $IDDCode);
}

$result = $this->postJson($this->buildEndpoint($config, $IDDCode), $params);

if (!isset($result['code']) || '0' != $result['code']) {
throw new GatewayErrorException(json_encode($result, JSON_UNESCAPED_UNICODE), isset($result['code']) ? $result['code'] : 0, $result);
}

return $result;
}

/**
* @param Config $config
* @param int $IDDCode
*
* @return string
*
* @throws InvalidArgumentException
*/
protected function buildEndpoint(Config $config, $IDDCode = 86)
{
$channel = $this->getChannel($config, $IDDCode);

if (self::INT_URL === $channel) {
return $channel;
}

return sprintf(self::ENDPOINT_URL_TEMPLATE, $channel);
}

/**
* @param Config $config
* @param int $IDDCode
*
* @return mixed
*
* @throws InvalidArgumentException
*/
protected function getChannel(Config $config, $IDDCode)
{
if (86 != $IDDCode) {
return self::INT_URL;
}
$channel = $config->get('channel', self::CHANNEL_NORMAL_CODE);

if (!in_array($channel, [self::CHANNEL_NORMAL_CODE, self::CHANNEL_VARIABLE_CODE])) {
throw new InvalidArgumentException('Invalid channel for ChuanglanGateway.');
}

return $channel;
}

/**
* @param string $content
* @param Config $config
* @param int $IDDCode
*
* @return string|string
*
* @throws InvalidArgumentException
*/
protected function wrapChannelContent($content, Config $config, $IDDCode)
{
return $content;
}
}
2 changes: 1 addition & 1 deletion src/Gateways/QcloudGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config
'Host' => self::ENDPOINT_HOST,
'Content-Type' => 'application/json; charset=utf-8',
'X-TC-Action' => self::ENDPOINT_METHOD,
'X-TC-Region' => self::ENDPOINT_REGION,
'X-TC-Region' => $this->config->get('region', self::ENDPOINT_REGION),
'X-TC-Timestamp' => $time,
'X-TC-Version' => self::ENDPOINT_VERSION,
],
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/UcloudGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa
$data = $message->getData($this);
$params = [
'Action' => self::ENDPOINT_Action,
'SigContent' => $config->get('sig_content'),
'SigContent' => !empty($data['sig_content']) ? $data['sig_content'] : $config->get('sig_content', ''),
'TemplateId' => $message->getTemplate($this),
'PublicKey' => $config->get('public_key'),
];
Expand Down
Loading

0 comments on commit 90643d9

Please sign in to comment.