cynojine /
cynsms-api
| 1 | <?php |
||
| 2 | |||
| 3 | /* Send an SMS using Cyn SMS. You can run this file 3 different ways: |
||
| 4 | * |
||
| 5 | * 1. Save it as example.php and at the command line, run |
||
| 6 | * php example.php |
||
| 7 | * |
||
| 8 | * 2. Upload it to a web host and load mywebhost.com/example.php |
||
| 9 | * in a web browser. |
||
| 10 | * |
||
| 11 | * 3. Download a local server like WAMP, MAMP or XAMPP. Point the web root |
||
| 12 | * directory to the folder containing this file, and load |
||
| 13 | * localhost:8888/example.php in a web browser. |
||
| 14 | */ |
||
| 15 | |||
| 16 | |||
| 17 | // Step 1: Get the Cyn SMS API library from https://github.com/cynojine/cynsms-api, |
||
| 18 | // following the instructions to install it with Composer. |
||
| 19 | |||
| 20 | require_once 'src/Class_Cyn_SMS_API.php'; |
||
| 21 | use CynSMS\CynSMSAPI; |
||
| 22 | |||
| 23 | |||
| 24 | // Step 2: set your API_KEY from https://sms.cynojine.com/sms-api/info |
||
| 25 | |||
| 26 | $api_key = 'YWRtaW46YWRtaW4ucGFzc3dvcmQ='; |
||
| 27 | |||
| 28 | |||
| 29 | // Step 3: Change the from number below. It can be a valid phone number or a String |
||
| 30 | $from = 'Cynojine'; |
||
| 31 | |||
| 32 | // Step 4: the number we are sending to - Any phone number |
||
| 33 | $destination = '260965858668'; |
||
| 34 | |||
| 35 | |||
| 36 | // <sms/api> is mandatory. |
||
| 37 | |||
| 38 | $url = 'https://sms.cynojine.com/sms/api'; |
||
| 39 | |||
| 40 | // the sms body |
||
| 41 | $sms = 'test message from Cyn SMS'; |
||
| 42 | |||
| 43 | // unicode sms |
||
| 44 | $unicode = 0; //For Plain Message |
||
| 45 | $unicode = 1; //For Unicode Message |
||
| 46 | |||
| 47 | |||
| 48 | // Create SMS Body for request |
||
| 49 | $sms_body = array( |
||
| 50 | 'api_key' => $api_key, |
||
| 51 | 'to' => $destination, |
||
| 52 | 'from' => $from, |
||
| 53 | 'sms' => $sms, |
||
| 54 | 'unicode' => $unicode, |
||
| 55 | ); |
||
| 56 | |||
| 57 | // Step 6: instantiate a new Cyn SMS API request |
||
| 58 | $client = new CynSMSAPI(); |
||
| 59 | |||
| 60 | // Step 7: Send SMS |
||
| 61 | $response = $client->send_sms($sms_body, $url); |
||
| 62 | |||
| 63 | print_r($response); |
||
| 64 | |||
| 65 | |||
| 66 | // Step 8: Get Response |
||
| 67 | $response=json_decode($response); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 68 | |||
| 69 | // Display a confirmation message on the screen |
||
| 70 | echo 'Message: '.$response->message; |
||
| 71 | |||
| 72 | |||
| 73 | //Step 9: Get your inbox |
||
| 74 | $get_inbox=$client->get_inbox($api_key,$url); |
||
| 75 | |||
| 76 | //Step 10: Get your account balance |
||
| 77 | |||
| 78 | $check_balance=$client->check_balance($api_key,$url); |
||
| 79 | |||
| 80 |