yhshanto/walletmix-sms-channel

laravel的Walletmix通知通道。

1.1 2019-06-30 09:08 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:32 UTC


README

先决条件

在开始之前,您必须了解Laravel通知。您可以在此处查看:.. https://laravel.net.cn/docs/5.8/notifications

在您可以通过Walletmix发送通知之前,您需要安装yhshanto/walletmix-sms-channel Composer包

composer require yhshanto/walletmix-sms-channel

接下来,您需要将一些配置选项添加到您的config/services.php配置文件中。您可以将下面的示例配置复制过来开始

'walletmix' => [
  'sms' => [
    'username'  => env('WALLETMIX_SMS_USERNAME'),
    'password'  => env('WALLETMIX_SMS_PASSWORD'),
    'from' 	=> env('WALLETMIX_SMS_FROM') // SMS Mask
  ]
]

from选项是指您的短信消息将从该电话号码或掩码发送。您可以联系Walletmix获取更多信息。

短信通知的格式化

如果通知支持作为短信发送,您应该在通知类上定义一个toWalletmix方法。此方法将接收一个$notifiable实体,并应返回一个YHShanto\WalletmixSMS\Messages\WalletmixMessage实例

/**
 * Get the Walletmix / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return WalletmixMessage
 */
public function toWalletmix($notifiable)
{
    return (new WalletmixMessage)
                ->content('Your SMS message content');
}
Unicode内容

如果您的短信消息将包含unicode字符,您应该在构造WalletmixMessage实例时调用unicode方法

/**
 * Get the Walletmix / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return WalletmixMessage
 */
public function toWalletmix($notifiable)
{
    return (new WalletmixMessage)
                ->content('Your unicode message')
                ->unicode();
}

自定义"发送方"号码

如果您希望从与config/services.php文件中指定的电话号码/掩码不同的电话号码/掩码发送一些通知,您可以在WalletmixMessage实例上使用from方法

/**
 * Get the Walletmix / SMS representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return WalletmixMessage
 */
public function toWalletmix($notifiable)
{
    return (new WalletmixMessage)
                ->content('Your SMS message content')
                ->from('15554443333');
}

路由短信通知

在通过walletmix通道发送通知时,通知系统将自动查找notifiable实体上的phone属性。如果您想自定义通知送达的电话号码,在实体上定义routeNotificationForWalletmix方法

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Walletmix channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForWalletmix($notification)
    {
        return $this->phone;
    }
}