ussd.js
1.22 KB
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
'use strict';
const config = require('./config.json');
const modem = require('./modem');
const common = require('./common');
let count = 1;
exports.sendUssd = async function sendUssd (req, res){
let msg = req.query.msg;
let reqid = req.query.reqid;
let apiKey = req.query.apikey;
//apiKey="746573206D6F64656D2074656C6D6F73656C20666C617368";
if(!reqid||!apiKey){
common.log("invalid reqid or apikey;msg "+msg);
res.json({"status": "invalid parameter", "msg": msg, "apikey" : apikey, "reqid": reqid});
return;
} else if (apiKey !== config.core.api_key){
common.log("invalid apiKey;msg \""+msg+"\"reqid \""+reqid);
res.json({"status": "invalid parameter", "msg": msg, "apikey" : apikey, "reqid": reqid});
return;
}
common.log("msg "+ msg+" - "+reqid);
count++;
common.log("count "+ count);
if (count > 2){
common.log("modem busy!");
count--;
res.json({status: "reject", info: "modem busy,try a few second", msg: msg});
return;
}
//----------------
let newData = await modem.sendingUSSD(msg, count);
common.log("data diterima "+newData);
count--;
res.json({data : newData, code: "200"});
}