PHP code example of snappmarket / smnotif-php-bridge

1. Go to this page and download the library: Download snappmarket/smnotif-php-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

snappmarket / smnotif-php-bridge example snippets



{
    $api_token = "Your API Token";
    $api_version = 1;
    $is_secure = true;
    $app_env = \Notifier\NotifierApi::PRODUCTION;
    $notifier = new \Notifier\NotifierApi($api_token,$api_version,$is_secure,$app_env);
    $sms_notifier = $notifier->setType(\Notifier\NotifierApi::SMS);
    $response = $sms_notifier->setBypassLimitControl(1) // to bypass time limit control (like activation codes)
        ->setExpireTime('1h 15m') // expires in 1 hour and 15 minutes
        ->setMode(\Notifier\NotifierApi::ASYNC_MODE) // send notification async or sync
        ->setPriority(\Notifier\NotifierApi::BLOCKER_PRIORITY) // priority : blocker, high, medium, low
        ->setProviderCode('10002') // get sms provider codes from notification service
        ->setSmsBodyStructure(\Notifier\NotifierApi::DYNAMIC_STRUCTURE) // static or dynamic?
        ->setSmsBody('Hello {{name}}. Your discount is {{discount}}!!') // sms body (you can also use sms templates)
        ->setReceivers([
            [
                'number' => "0939*******",
                'sms_template_data' => [
                    'name' => 'Alireza Jangi',
                    'discount' => 45
                ]
            ],
            [
                'number' => "0937*******",
                'sms_template_data' => [
                    'name' => 'Another Name',
                    'discount' => 77
                ]
            ]
        ])
        ->send();
} catch (Exception $e) {
    throw $e;
}

use Notifier\NotifierApi;

try {
    $api_token = "Your API Token";
    $api_version = 1;
    $is_secure = true;
    $app_env = NotifierApi::PRODUCTION;
    $notifier = new NotifierApi($api_token,$api_version,$is_secure,$app_env);
    $sms_notifier = $notifier->setType(\Notifier\NotifierApi::SMS);
    $response = $sms_notifier->setBypassLimitControl(1) // to bypass time limit control (like activation codes)
        ->setExpireTime('1h 15m') // expires in 1 hour and 15 minutes
        ->setMode(NotifierApi::ASYNC_MODE) // send notification async or sync
        ->setPriority(NotifierApi::BLOCKER_PRIORITY) // priority : blocker, high, medium, low
        ->setProviderCode('10002') // get sms provider codes from notification service
        ->setSmsBodyStructure(NotifierApi::DYNAMIC_STRUCTURE) // static or dynamic?
        ->setSmsBody('Hello {{name}}. Your discount is {{discount}}!!') // sms body (you can also use sms templates)
        ->setReceivers([
            [
                'number' => "0939*******",
                'sms_template_data' => [
                    'name' => 'Alireza Jangi',
                    'discount' => 45
                ]
            ],
            [
                'number' => "0937*******",
                'sms_template_data' => [
                    'name' => 'Another Name',
                    'discount' => 77
                ]
            ]
        ])
        ->send();
} catch (Exception $e) {
    throw $e;
}

// Static Push Notification
try {
    $api_token = "5df0d20cd6b9c5df0d20cd6ba3";
    $api_version = 1;
    $is_secure = true;
    $app_env = NotifierApi::TEST;
    $notifier = new NotifierApi($api_token,$api_version,$is_secure,$app_env);
    $push_notifier = $notifier->setType(\Notifier\NotifierApi::PUSH);
    $response = $push_notifier->setBypassLimitControl(1) // to bypass time limit control (like activation codes)
        ->setExpireTime('10m') // expires in 10 minutes
        ->setMode(NotifierApi::ASYNC_MODE) // send notification async or sync
        ->setReceivers(["3502960","4727193"]) // Receivers for static push notification are user IDs
        ->setPriority(NotifierApi::BLOCKER_PRIORITY) // priority : blocker, high, medium, low
        ->setProviderCode('20001') // get push provider codes from notification service
        ->setBodyStructure(NotifierApi::STATIC_STRUCTURE) // you set it to static in this type
        ->setTitle('This is a test ') // push title
        ->setBody('This is a test message without any variables!!') // push body
        ->setMessagePageTitle("") // This is the message title you want to save in user phone
        ->setMessagePageBody("") // This is the message body you want to save in user phone
        ->setImage("https://m.snapp.market/logo.png") // set push notification image
        ->setBanner("https://m.snapp.market/logo.png") // set push notification banner
        ->setSound("default") // set push notification sound
        ->setModalText("Some text for modal") // if you set it a modal will be open in application
        ->setDeepLink("") // set Deep Link
        ->setWebView("") // set Web View
        ->setWebLink("") // set Web Link
        ->send();
    die($response);
} catch (Exception $e) {
    throw $e;
}
// Dynamic Push Notification
try {
    $api_token = "5df0d20cd6b9c5df0d20cd6ba3";
    $api_version = 1;
    $is_secure = true;
    $app_env = NotifierApi::TEST;
    $notifier = new NotifierApi($api_token,$api_version,$is_secure,$app_env);
    $push_notifier = $notifier->setType(\Notifier\NotifierApi::PUSH);
    $response = $push_notifier->setBypassLimitControl(1) // to bypass time limit control (like activation codes)
        ->setExpireTime('10m') // expires in 10 minutes
        ->setMode(NotifierApi::ASYNC_MODE) // send notification async or sync
        ->setReceivers([
                [
                    'user_id' => "********",
                    'push_template_data' => [
                        'first_name' => 'Alireza',
                        'last_name' => "jangi",
                        'code' => "3434"
                    ]
                ],
                [
                    'number' => "*******",
                    'push_template_data' => [
                        'first_name' => 'Another Name',
                        'last_name' =>  'Another Name',
                        'code' => '9833'
                    ]
                ]
        ]) // Receivers for static push notification are user IDs
        ->setPriority(NotifierApi::BLOCKER_PRIORITY) // priority : blocker, high, medium, low
        ->setProviderCode('20001') // get push provider codes from notification service
        ->setBodyStructure(NotifierApi::DYNAMIC_STRUCTURE) // you set it to static in this type
        ->setTitle('Hello {{first_name}} {{last_name}}') // push title
        ->setBody('Welcome! This is your code : {{code}} ') // push body
        ->setMessagePageTitle("") // This is the message title you want to save in user phone
        ->setMessagePageBody("") // This is the message body you want to save in user phone
        ->setImage("https://m.snapp.market/logo.png") // set push notification image
        ->setBanner("https://m.snapp.market/logo.png") // set push notification banner
        ->setSound("default") // set push notification sound
        ->setModalText("Some text for modal") // if you set it a modal will be open in application
        ->setDeepLink("") // set Deep Link
        ->setWebView("") // set Web View
        ->setWebLink("") // set Web Link
        ->send();
    die($response);
} catch (Exception $e) {
    throw $e;
}