Нужна помощь?
Задайте вопрос специалисту технической поддержки
Отправка СМС:
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
"use strict" ; exports.__esModule = true; var https = require ( "https" ); var querystring = require ( "querystring" ); var md5_typescript_1 = require ( "md5-typescript" ); /** * */ var EpochtaApiv3 = /** @class */ ( function () { /** * * @param public_key * @param private_key */ function EpochtaApiv3(public_key, private_key) { this.debug = false; this.gatewayhost = 'api.atompark.com' ; this.gatewaypath = '/api/sms/3.0/' ; this.public_key = public_key; this.private_key = private_key; } EpochtaApiv3.prototype.calcSum = function (params, action) { // action = action.toLowerCase(); params[ "key" ] = this.public_key; params[ "version" ] = "3.0" ; params[ "action" ] = action; var data = []; for ( var pkey in params) { data.push({ key: pkey, val: params[pkey] }); } data.sort( function (a, b) { if (a.key === b.key) return 0; return a.key > b.key ? 1 : -1; }); var control_str = "" ; for ( var i = 0; i < data.length; i++) { control_str += data[i].val; } control_str += this.private_key; return md5_typescript_1.Md5.init(control_str); }; /** * * @param sender * @param phone * @param text * @param datetime * @param callback * @param error_callback */ EpochtaApiv3.prototype.sendSMS = function (sender, phone, text, datetime, callback, error_callback) { if (datetime === void 0) { datetime = "" ; } var action = "sendSMS" ; var sms_lifetime = "0" ; var params = {}; params[ "sender" ] = sender; params[ "text" ] = text; params[ "phone" ] = phone; params[ "datetime" ] = datetime; params[ "sms_lifetime" ] = sms_lifetime; var control_sum = this.calcSum(params, action); var data = { "key" : this.public_key, "sum" : control_sum, "sender" : sender, "text" : text, "phone" : phone, "datetime" : "" , "sms_lifetime" : "0" }; return this.request(data, action, callback, error_callback); }; /** * * @param sender * @param phones * @param text * @param datetime * @param sms_lifetime * @param batch * @param batchinterval * @param callback * @param error_callback */ EpochtaApiv3.prototype.sendSMSGroup = function (sender, phones, text, datetime, sms_lifetime, batch, batchinterval, controlnumber, callback, error_callback) { if (datetime === void 0) { datetime = "" ; } if (sms_lifetime === void 0) { sms_lifetime = 0; } if (batch === void 0) { batch = 0; } if (batchinterval === void 0) { batchinterval = 0; } if (controlnumber === void 0) { controlnumber = "" ; } var action = "sendSMSGroup" ; action = action.toLowerCase(); var params = {}; params[ "sender" ] = sender; params[ "text" ] = text; params[ "phones" ] = JSON.stringify(phones); params[ "datetime" ] = datetime; params[ "sms_lifetime" ] = sms_lifetime; params[ "batch" ] = batch; params[ "batchinterval" ] = batchinterval; params[ "controlnumber" ] = controlnumber; var control_sum = this.calcSum(params, action); var data = { "sender" : sender, "text" : text, "phones" : JSON.stringify(phones), "datetime" : datetime, "sms_lifetime" : sms_lifetime, "batch" : batch, "batchinterval" : batchinterval, "sum" : control_sum, "key" : this.public_key, "controlnumber" : controlnumber }; return this.request(data, action, callback, error_callback); }; /** * Create campaign * * @param [string] sender * @param [string] text * @param [int] list_id * @param [string] datetime * @param [int] batch * @param [int] batchinterval * @param [int] sms_lifetime * @param [string] control_phone * @return [map] */ EpochtaApiv3.prototype.createCampaign = function (sender, text, list_id, datetime, batch, batchinterval, sms_lifetime, control_phone, callback, error_callback) { var action = "createCampaign" ; var params = {}; params[ "sender" ] = sender; params[ "text" ] = text; params[ "list_id" ] = list_id; params[ "datetime" ] = datetime; params[ "batch" ] = batch; params[ "batchinterval" ] = batchinterval; params[ "sms_lifetime" ] = sms_lifetime; params[ "control_phone" ] = control_phone; var control_sum = this.calcSum(params, action); var data = { "sender" : sender, "text" : text, "list_id" : list_id, "datetime" : datetime, "batch" : batch, "batchinterval" : batchinterval, "sms_lifetime" : sms_lifetime, "control_phone" : control_phone, "key" : this.public_key, "sum" : control_sum }; return this.request(data, action, callback, error_callback); }; /** * Add phone to addressbook * * @param [int] id_addressbook * @param [string] phone * @param [string] variables * @return [map] */ EpochtaApiv3.prototype.addPhoneToAddressBook = function (id_addressbook, phone, variables, callback, error_callback) { var action = "addPhoneToAddressBook" ; var params = {}; params[ "idAddressBook" ] = id_addressbook; params[ "phone" ] = phone; params[ "variables" ] = variables; var control_sum = this.calcSum(params, action); var data = { "idAddressBook" : id_addressbook, "phone" : phone, "variables" : variables, "key" : this.public_key, "sum" : control_sum }; return this.request(data, action, callback, error_callback); }; /** * Get user balance * * @param [string] currency * @return [map] */ EpochtaApiv3.prototype.getUserBalance = function (currency, callback, error_callback) { if (currency === void 0) { currency = "USD" ; } var action = "getUserBalance" ; var params = {}; params[ "currency" ] = currency; var control_sum = this.calcSum(params, action); var data = { "currency" : currency, "key" : this.public_key, "sum" : control_sum }; return this.request(data, action, callback, error_callback); }; /** * Add addressbook * * @param [string] name * @param [string] description * @return [map] */ EpochtaApiv3.prototype.addAddressbook = function (name, description, callback, error_callback) { var action = "addAddressbook" ; var params = {}; params[ "name" ] = name; params[ "description" ] = description; var control_sum = this.calcSum(params, action); var data = { "name" : name, "description" : description, "key" : this.public_key, "sum" : control_sum }; return this.request(data, action, callback, error_callback); }; EpochtaApiv3.prototype.handle_result = function (data) { if (data[ 'http_code' ] != 200) { data[ 'is_error' ] = true; } return data; }; /** * 1 * @param xml * @param type * @param callback * @param error_callback */ EpochtaApiv3.prototype.request = function (data, action, callback, error_callback) { if (this.debug) { console.log({ data: data, action: action }); return true; } var _this = this; var postData = querystring.stringify(data); var options = { hostname: this.gatewayhost, port: 443, path: this.gatewaypath + action, method: 'POST' , headers: { 'Content-Type' : 'application/x-www-form-urlencoded' , 'Content-Length' : postData.length } }; var req = https.request(options, function (res) { if (res.statusCode == 200) { res.on( 'data' , function (d) { var result = JSON.parse(d); var code = parseInt(result.code); if (code >= 0) { // OK callback(result); } else { error_callback(result); } }); } else { error_callback({ error: "uknown" , result: 'false' }); } }); req.on( 'error' , function (e) { error_callback({ error: "uknown" , message: e + '' , result: 'false' }); }); req.write(postData); req. end (); return true; }; /** * * @param status */ EpochtaApiv3.prototype.error_handler = function (custom_message) { var data = { 'is_error' : true }; if (custom_message) { data[ 'message' ] = custom_message; } return data; }; return EpochtaApiv3; }()); var api3 = new EpochtaApiv3( 'your public key' , 'your private key' ); // api3.addAddressbook("typeScript3", "create from typescript", (res: any) => {console.log(res)}, (res: any) => {console.log(res)}); // { result: { addressbook_id: 1485588 } } // api3.addPhoneToAddressBook(1485588, "380933630000", "", (res: any) => {console.log(res)}, (res: any) => {console.log(res)}); // { result: { phone_id: 457466228 } } // api3.createCampaign("smSender", "message from typescript", 1485588, "", 0, 0, 0, "", (res: any) => {console.log(res)}, (res: any) => {console.log(res)}); // { result: { id: 118970671, price: 0.013300399011970358, currency: 'USD' } } // api3.getUserBalance("USD", (res: any) => {console.log(res)}, (res: any) => {console.log(res)}); // api3.sendSMS("smSender", "380933630000", "", "", (res: any) => {console.log(res)}, (res: any) => {console.log(res)}); // api3.sendSMSGroup( "smSender" , [[ "380933630000" ]], "qeqeqeqwe" , "" , 0, 0, 0, "" , function (res) { console.log(res); }, function (res) { console.log(res); }); // |