shipu/banglalink-sms-gateway

Banglalink短信网关

v1.2 2018-07-27 16:24 UTC

This package is auto-updated.

Last update: 2024-09-19 10:30:30 UTC


README

这是一个Banglalink SMS网关API的PHP客户端。此包也支持Laravel和Lumen。

安装

转到终端并运行此命令

composer require shipu/banglalink-sms-gateway

等待几分钟。Composer会自动为您项目安装此包。

对于Laravel

对于低于Laravel 5.5的版本,打开config/app并在providers部分添加此行

Shipu\BanglalinkSmsGateway\Providers\BanglalinkSmsGatewayServiceProvider::class,

为了支持外观,您必须在此处的aliases部分添加此行。

'Banglalink'   =>  Shipu\BanglalinkSmsGateway\Facades\Banglalink::class,

然后运行此命令

php artisan vendor:publish --provider="Shipu\BanglalinkSmsGateway\Providers\BanglalinkSmsGatewayServiceProvider"

对于PHP配置

此包需要两个配置。

  1. user_id = Banglalink提供的您的user_id。
  2. password = Banglalink提供的您的密码。

banglalink-sms-gateway接受一个数组作为配置文件。让我们看看服务

use Shipu\BanglalinkSmsGateway\Banglalink;

$config = [
    'user_id' => 'Your User Id',
    'password' => 'Your Password'
];

$sms = new Banglalink($config);

对于Laravel配置

此包也支持Laravel。对于Laravel,您必须按照Laravel风格进行配置。

转到config/banglalink-sms-gateway.php并使用您的凭证进行配置。

return [
    'user_id' => 'Your User id',
    'password' => 'Your Password'
];

用法

使用非常简单。此包具有许多功能和特性。

向单个用户发送短信

在PHP中

use \Shipu\BanglalinkSmsGateway\Services\Banglalink;

...

$sms = new Banglalink($config);
$response = $sms->message('your text here !!!', '01606022000')->send(); // Guzzle Response with request data

// For another example please see below laravel section. 
 
return $response->autoParse(); // Getting only response contents.

在Laravel中

use \Shipu\BanglalinkSmsGateway\Facades\Banglalink;

...

$sms = Banglalink::message('your text here !!!', '01606022000')->send(); // Guzzle Response with request data

// or

$sms = Banglalink::message('your text here !!!')->to('01606022000')->send();

// or

$sms = Banglalink::send(
    [
        'message' => "your text here",
        'to' => '01616022000'
    ]
);
return $sms->autoParse(); // Getting only response contents.

向所有用户发送相同的消息

$sms = Banglalink::message('your text here !!!')
            ->to('01616022669')
            ->to('01845736124')
            ->to('01745987364')
            ->send();
            
// or you can try below statements also

$sms = Banglalink::message('your text here !!!', '01616022669')
            ->to('01845736124')
            ->to('01745987364')
            ->send();
            
// or           

$users = [
    '01616022669',
    '01845736124',
    '01745987364'
];        
$sms = Banglalink::message('your text here !!!',$users)->send(); 

向更多用户发送短信

$sms = Banglalink::message('your text here one !!!')->to('01616022669')
            ->message('your text here two !!!')->to('01845736124')
            ->message('your text here three !!!')->to('01745987364')
            ->send();
// or

$sms = Banglalink::message('your text here one !!!', '01616022669')
            ->message('your text here two !!!', '01845736124')
            ->message('your text here three !!!', '01745987364')
            ->send();
            
// or 

$sms = Banglalink::send([
    [
        'message' => "your text here one !!!",
        'to' => '01616022669'
    ],
    [
        'message' => "your text here two !!!",
        'to' => '01707722669'
    ],
    [
        'message' => "your text here three !!!",
        'to' => '01745987364'
    ]
]);

// or 

$sms = Banglalink::message('your text here one !!!', '01616022669')->send([
    [
        'message' => "your text here two !!!",
        'to' => '01707722669'
    ],
    [
        'message' => "your text here three !!!",
        'to' => '01745987364'
    ]
]);         

使用短信模板发送短信

假设您需要向多个用户发送短信,但您想动态地在消息中提及他们的名字。您能做什么?哈哈,这个包已经处理了这种情况。让我们看看

$users = [
    ['01670420420', ['Nahid', '1234']],
    ['01970420420', ['Rana', '3213']],
    ['01770420420', ['Shipu', '5000']],
    ['01570420420', ['Kaiser', '3214']],
    ['01870420420', ['Eather', '7642']]
]
$sms = new \Shipu\BanglalinkSmsGateway\Services\Banglalink(config('banglalink-sms-gateway'));
$msg = $sms->message("Hello %s , Your promo code is: %s", $users)->send();

// or 

$users = [
    '01670420420' => ['Nahid', '1234'],
    '01970420420' => ['Rana', '3213'],
    '01770420420' => ['Shipu', '5000'],
    '01570420420' => ['Kaiser', '3214'],
    '01870420420' => ['Eather', '7642']
]
$sms = new \Shipu\BanglalinkSmsGateway\Services\Banglalink(config('banglalink-sms-gateway'));
$msg = $sms->message("Hello %s , Your promo code is: %s", $users)->send();

在这里,这条消息将发送给每个用户,包含他们的名字和促销代码,如

  • 8801670420420 - Hello Nahid,您的促销代码是:1234
  • 8801970420420 - Hello Rana,您的促销代码是:3213
  • 8801770420420 - Hello Shipu,您的促销代码是:5000
  • 8801570420420 - Hello Kaiser,您的促销代码是:1234
  • 8801870420420 - Hello Eather,您的促销代码是:7642

更改号码前缀

$sms = Banglalink::numberPrefix('91')->message('your text here !!!', '01606022000')->send();

默认号码前缀是88

使用发送者名称发送短信

$sms = Banglalink::sender('XYZ Company')->message('your text here !!!', '01606022000')->send();

默认发送者名称是null。有关详细信息,请联系Banglalink客户支持;

调试

$sms = Banglalink::debug(true)->message('your text here !!!', '01606022000')->send(); // // debug true or blank.

默认值为false。当调试为true时,它将停止发送短信并返回发送查询字符串。

响应数据自动解析

$sms = Banglalink::autoParse(true)->message('your text here !!!', '01606022000')->send(); // autoParse true or blank.

默认值为false

禁用模板

$sms = Banglalink::template(false)->message('your text here !!!', '01606022000')->send();

默认值为true

响应数据

dd($sms);

响应

Response {#463 ▼
  #response: Response {#446 ▶}
  #request: Request {#428 ▼
    -method: "GET"
    -requestTarget: null
    -uri: Uri {#429 ▶}
    -headers: []
    -headerNames: []
    -protocol: "1.1"
    -stream: null
    +"details": array:3 [▼
      "url" => "https://vas.banglalinkgsm.com/sendSMS/sendSMS"
      "method" => "GET"
      "parameters" => array:1 [▼
        "query" => array:5 [▶]
      ]
    ]
  }
  #contents: "Success Count : 2 and Fail Count : 0"
}

响应自动解析

dd($sms->autoParse());

响应

"Success Count : 2 and Fail Count : 0"

响应详情

$sms = Banglalink::details()->message('your text here !!!', '01606022000')->send();

响应

[
    'success' => 1,
    'failed' => 0
]