ouredenlife/ laravel-sendchamp
Laravel sendchamp api 的扩展包
1.0.4
2024-01-05 11:58 UTC
Requires
- php: ^7.2|^8.0|^8.1
- guzzlehttp/guzzle: ~6|~7
- illuminate/support: ~6|~7|~8|^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.2
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-05 13:29:08 UTC
README
sendchamp api 的 Laravel 扩展包
安装
要获取 Sendchamp 的最新版本,只需要求即可
composer require mujhtech/sendchamp
或者将以下行添加到您的 composer.json
文件的 require 块中。
"mujhtech/sendchamp": "1.0.*"
一旦安装了 Laravel Sendchamp,您需要注册服务提供者。打开 config/app.php
并将以下内容添加到 providers
键中。
'providers' => [ ... Mujhtech\SendChamp\SendChampServiceProvider::class, ... ]
如果您使用 Laravel >= 5.5,则可以跳过此步骤并转到
配置
SendChamp\SendChamp\SendChampServiceProvider::class
此外,还可以按如下方式注册 Facade
'aliases' => [ ... 'SendChamp' => Mujhtech\SendChamp\Facades\SendChamp::class, ... ]
配置
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Mujhtech\SendChamp\SendChampServiceProvider"
将名为 sendchamp.php
的配置文件(带有一些合理的默认值)放置在您的 config
目录中
<?php return [ /** * Mode * live or test * */ 'mode' => 'live', // test mode has been removed, the user must buy testing credit on the platform /** * Public Key * */ 'publicKey' => getenv('SENDCHAMP_PUBLIC_KEY'), ];
Lumen 配置
- 打开您的 bootstrap/app.php
- 注册您的服务提供者
- 添加您的 Facade
- 注册配置
$app->register(Mujhtech\SendChamp\SendChampServiceProvider::class); $app->withFacades(true, [ SendChamp::class => 'SendChamp', ]); $app->configure('sendchamp');
使用
打开您的 .env 文件并添加您的 API 密钥,如下所示
SENDCHAMP_PUBLIC_KEY=sendchamp_xxxxxxxxxxx
如果您使用像 heroku 这样的托管服务,请确保将上述详细信息添加到您的配置变量中。
用例
/** * Get wallet report * @return array */ SendChamp::getWalletReport() /** * Alternatively, use the helper. */ sendchamp()->getWalletReport(); /** * Create or update contact * @param string $lastname * @param string $firstname * @param string $phone * @param string $email * @param string $reference * @return array */ SendChamp::createOrUpdateContact($lastname, $firstname, $phone, $email, $reference) /** * Alternatively, use the helper. */ sendchamp()->createOrUpdateContact($lastname, $firstname, $phone, $email, $reference); /** * Delete contact * @param string $id * @return array */ SendChamp::deleteContact($id) /** * Alternatively, use the helper. */ sendchamp()->deleteContact($id); /** * * Create sms sender * * @param string $send_name * * @param string $use_case * * You should pass either of the following: Transactional, Marketing, or Transactional & Marketing * * @param string $sample_message * * @return array */ SendChamp::createSmsSender($sender_name, $use_case, $sample_message) /** * Alternatively, use the helper. */ sendchamp()->createSmsSender($sender_name, $use_case, $sample_message); /** * Send sms * @param string $message * @param string $sender_name * Represents the sender of the message. * This Sender ID must have been requested * via the dashboard or use "Sendchamp" as default * @param array $numbers * This represents the destination phone number. * The phone number(s) must be in the international format * (Example: 23490126727). You can also send to multiple numbers. * To do that put numbers in an array * (Example: [ '234somenumber', '234anothenumber' ]). * @param string $route e.g ['non_dnd', 'dnd', 'international'] * @return array * */ SendChamp::sendSms($message, $sender_name, $numbers, $route) /** * Alternatively, use the helper. */ sendchamp()->sendSms($message, $sender_name, $numbers, $route); /** * Get sms status * @param string $sms_id * ID of the SMS that was sent * @return array */ SendChamp::fetchSmsStatus($sms_id) /** * Alternatively, use the helper. */ sendchamp()->fetchSmsStatus($sms_id); /** * Send voice * @param string $message * @param string $sender_name * Represents the sender of the message. * This Sender ID must have been requested via * the dashboard or use "Sendchamp" as default * @param string $number * The number represents the destination phone number. * The number must be in international format (E.g. 2348012345678) * @return array */ SendChamp::sendVoice($message, $sender_name, $number) /** * Alternatively, use the helper. */ sendchamp()->sendVoice($message, $sender_name, $number); /** * Send whatsapp otp * @param string $template_code * You can find this on the template page under Whatsapp Channel of your Sendchamp dashboard * @param string $sender_number * Your approved Whatsapp number on Sendchamp. * You can use our phone number if you have not registered a number 2347067959173 * @param string $recipient * Whatsapp number of the customer you are sending the message to * @param string $message * @return array */ SendChamp::sendWhatsappOtp($template_code, $message, $sender_number, $recipient) /** * Alternatively, use the helper. */ sendchamp()->sendWhatsappOtp($template_code, $message, $sender_number, $recipient); /** * Send otp message * @param string $channel * @param string $token_type // numeric or alphanumeric * @param int $token_length * The length of the token you want to send to your customer. Minimum is 5 * @param int $expiry_day * How long you want to the to be active for in minutes. (E.g. 10 means 10 minutes ) * @param string $customer_email * @param string $customer_mobile_number * @param array $meta_data can be empty but you need to pass array like ['data' => []] * @param string $sender * Specify the sender you want to use. This is important * when using SMS OR Whatsapp Channel or we will select a * default sender from your account. Eg: KUDA OR +234810000000 * @return array */ SendChamp::sendOtp($channel, $token_type, $token_length, $expiry_day, $customer_email $customer_mobile_number, $meta_data, $sender) /** * Alternatively, use the helper. */ sendchamp()->sendOtp($channel, $token_type, $token_length, $expiry_day, $customer_email $customer_mobile_number, $meta_data, $sender); /** * Confirm otp * @param string $reference * The unique reference that was returned as response when the OTP was created * @param string $otp * The OTP that was sent to the customer. * @return array */ SendChamp::confirmOtp($reference, $otp) /** * Alternatively, use the helper. */ sendchamp()->confirmOtp($reference, $otp);
代码质量
- 运行
vendor/bin/pint
许可证
MIT 许可证(MIT)。请参阅许可证文件以获取更多信息。