简体   繁体   English

如何发送OTP到多条短信Api?

[英]How to Send OTP to Multiple SMS Api?

I have a php script which allows me to send OTPs to an SMS Api;我有一个 php 脚本,它允许我将 OTP 发送到 SMS Api; but sometimes the sms gets delayed or not delivered so I was thinking of adding another Api to the code so now the OTP is sent to WhatsApp as well.但有时短信会延迟或未发送,所以我正在考虑在代码中添加另一个 Api,所以现在 OTP 也被发送到 WhatsApp。

Can any one help me modify the code to add another api in the following code?任何人都可以帮我修改代码以在以下代码中添加另一个 api 吗?

    $phone = preg_replace('/[^0-9]/', '', $phone);
    $curl = curl_init();

    $curl = curl_init();
    $params = array(
        'Username' => '030XXXXXX',
        'Password' => 'XXXXXX',
        'From' => 'XXXXXX',
        'To' => $phone,
        'Message' => $message,
    );
    $encoded_query = http_build_query($params);
    curl_setopt($curl, CURLOPT_URL, 'https://connect.jazz.com/sendsms_url.html?' . $encoded_query);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($curl);
    $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    $curl_error = curl_errno($curl);
    curl_close($curl);

    if($test_call) return $result;

    if ($curl_error !== 0) {
        return false;
    }



    if ($err) {
        return false;
    } else {
        return true;
    }
}

Thank You谢谢你

Use the strategy pattern to implement your SMS providers.使用策略模式来实现您的 SMS 提供程序。 Then you can send your messages with jobs and when the job was failed retry that with another strategy (provider like WhatsApp).然后你可以用工作发送你的消息,当工作失败时用另一种策略(像 WhatsApp 这样的提供者)重试。

Example job to handle the failing situation:处理失败情况的示例作业:

class SendExampleSmsJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
 
    public function handle()
    {
        // Process sending message ...
    }
 
    /**
     * Handle a job failure.
     */
    public function failed(Throwable $exception)
    {
        // dispatch another job to send Whatsapp message or something else
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM