-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
104 lines (92 loc) · 4 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @var $api_key
* @var $sms_line
* @var $test_mobile_number
* @var $pattern_code
* @var $pattern_values
*/
require "vendor/autoload.php";
use Yiiman\MedianaSms\MedianaSMS;
use Yiiman\MedianaSms\RequestClasses\SendPatternRequest;
use Yiiman\MedianaSms\RequestClasses\SendSMSRequest;
require __DIR__.'/env.php';
$api = new MedianaSMS();
$api->apiKey = $api_key;
$creditResult = $api->getCredit();
if ($creditResult->isSuccess() && $creditResult->credit > 1000) {
// < Initializing data >
{
$dataSms = new SendSMSRequest();
$dataSms->originator0 = $sms_line;
$dataSms->recipients0 = [$test_mobile_number];
$dataSms->message0 = 'this is test';
}
// </ Initializing data >
if ($dataSms->validate()) {
$sendResult = $api->send($dataSms);
if ($sendResult && $sendResult->bulk_id) {
echo "Sms sent and bulk id is :\n";
echo $sendResult->bulk_id."\n";
$message_info = $api->getMessage($sendResult->bulk_id);
if ($message_info->isSuccess()) {
echo "Message info for normal send message is :\n\n";
echo '-- message:'.$message_info->message."\n";
echo '-- status:'.$message_info->status."\n";
echo '-- created at:'.$message_info->created_at."\n";
echo '-- type:'.$message_info->type."\n";
echo '-- confirm status:'.$message_info->confirm_state."\n";
echo '-- number:'.$message_info->number."\n";
echo '-- sent at:'.$message_info->sent_at."\n";
echo '-- cost:'.$message_info->cost."\n";
echo '-- payback cost:'.$message_info->payback_cost."\n";
echo '-- count of receivers:'.$message_info->recipients_count."\n";
echo '-- count of valid receivers:'.$message_info->valid_recipients_count."\n";
} else {
echo "Server returned some errors:\n\n";
var_dump($message_info->getError()->message);
}
}
} else {
echo "Your posted data has some errors:\n\n";
var_dump($dataSms->errors());
}
$dataPattern = new SendPatternRequest();
$dataPattern->originator0 = $sms_line;
$dataPattern->recipient0 = $test_mobile_number;
$dataPattern->pattern_code0 = $pattern_code;
$dataPattern->values0 = $pattern_values;
if ($dataPattern->validate()) {
$patternResult = $api->sendPattern($dataPattern);
if ($patternResult->isSuccess()) {
echo 'Bulk id for sent pattern is :'.$patternResult->bulk_id."\n\n";
$message_info = $api->getMessage($patternResult->bulk_id);
if ($message_info->isSuccess()) {
echo "Message info for pattern is :\n\n";
echo '-- message:'.$message_info->message."\n";
echo '-- status:'.$message_info->status."\n";
echo '-- created at:'.$message_info->created_at."\n";
echo '-- type:'.$message_info->type."\n";
echo '-- confirm status:'.$message_info->confirm_state."\n";
echo '-- number:'.$message_info->number."\n";
echo '-- sent at:'.$message_info->sent_at."\n";
echo '-- cost:'.$message_info->cost."\n";
echo '-- payback cost:'.$message_info->payback_cost."\n";
echo '-- count of receivers:'.$message_info->recipients_count."\n";
echo '-- count of valid receivers:'.$message_info->valid_recipients_count."\n";
} else {
echo "Server returned some errors:\n\n";
var_dump($message_info->getError()->message);
}
} else {
echo "Server returned some errors:\n\n";
var_dump($patternResult->getError()->message);
}
} else {
echo "Your posted data has some errors:\n\n";
var_dump($dataPattern->errors());
}
} else {
echo "Server returned some errors:\n\n";
var_dump($creditResult->getError()->message);
}