Skip to content

Commit

Permalink
加入国际短信支持 (overtrue#180)
Browse files Browse the repository at this point in the history
加入国际短信支持
  • Loading branch information
keacefull authored and overtrue committed Apr 16, 2019
1 parent 58bfc0b commit 1a3107f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Gateways/ChuanglanGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class ChuanglanGateway extends Gateway
* URL模板
*/
const ENDPOINT_URL_TEMPLATE = 'https://%s.253.com/msg/send/json';


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

/**
* 验证码渠道code.
*/
Expand Down Expand Up @@ -60,8 +65,13 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config
'phone' => $to->getNumber(),
'msg' => $this->wrapChannelContent($message->getContent($this), $config),
];
$IDDCode = !empty($to->getIDDCode()) ? $to->getIDDCode() : 86;

$result = $this->postJson($this->buildEndpoint($config), $params);
if ($IDDCode != 86) {
$params['mobile'] = $to->getIDDCode() . $to->getNumber();
}

$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);
Expand All @@ -72,12 +82,13 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config

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

Expand All @@ -93,6 +104,9 @@ protected function buildEndpoint(Config $config)
*/
protected function getChannel(Config $config)
{
if ($idDCode != 86) {
return self::INT_URL;
}
$channel = $config->get('channel', self::CHANNEL_VALIDATE_CODE);

if (!in_array($channel, [self::CHANNEL_VALIDATE_CODE, self::CHANNEL_PROMOTION_CODE])) {
Expand Down

0 comments on commit 1a3107f

Please sign in to comment.