Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- createSMTelSignature: function(partnerTrxId, trxTime, smtelData) {
- if(!smtelData.posId) {
- smtelData.posId = '';
- }
- const firstSignature = smtelData.pin + smtelData.secretKey + partnerTrxId;
- const firstMd5 = LIBRARY.crypto
- .createHash("md5")
- .update(firstSignature)
- .digest("hex");
- const lockMethod = smtelData.channelId + smtelData.storeId + smtelData.posId;
- const secondSignature = lockMethod + trxTime;
- const secondMd5 = LIBRARY.crypto
- .createHash("md5")
- .update(secondSignature)
- .digest("hex");
- const finalSignature = firstMd5 + secondMd5;
- const password = LIBRARY.crypto
- .createHash("md5")
- .update(finalSignature)
- .digest("hex");
- return password;
- },
- createStringDateFormat: function(dt) {
- let currentTime;
- if (dt) {
- currentTime = new Date(dt);
- } else {
- currentTime = new Date();
- }
- let year = currentTime.getFullYear().toString();
- let month =
- currentTime.getMonth() + 1 < 10
- ? "0" + (currentTime.getMonth() + 1)
- : currentTime.getMonth() + 1;
- month = month.toString();
- let date =
- currentTime.getDate() < 10
- ? "0" + currentTime.getDate()
- : currentTime.getDate();
- date = date.toString();
- let hour =
- currentTime.getHours() < 10
- ? "0" + currentTime.getHours()
- : currentTime.getHours();
- hour = hour.toString();
- let minute =
- currentTime.getMinutes() < 10
- ? "0" + currentTime.getMinutes()
- : currentTime.getMinutes();
- minute = minute.toString();
- let second =
- currentTime.getSeconds() < 10
- ? "0" + currentTime.getSeconds()
- : currentTime.getSeconds();
- second = second.toString();
- let trxTime = year + month + date + hour + minute + second; // for smtel format
- let dateObject = {
- trxTime
- };
- return dateObject;
- },
- connectXmpp: function(){
- LIBRARY.xmpp.connect({
- jid: GLOBAL_CONFIG.xmpp.jid,
- password: GLOBAL_CONFIG.xmpp.password,
- host: GLOBAL_CONFIG.xmpp.host,
- port: GLOBAL_CONFIG.xmpp.port
- });
- LIBRARY.xmpp.on('online', function(data) {
- console.log('Terkoneksi dengan Jabber ID : ' + data.jid);
- });
- },
- connectMysql__: function(){
- var con = LIBRARY.mysql.createConnection({
- host: GLOBAL_CONFIG.mysql.host,
- port: GLOBAL_CONFIG.mysql.port,
- database: GLOBAL_CONFIG.mysql.database,
- user: GLOBAL_CONFIG.mysql.user,
- password: GLOBAL_CONFIG.mysql.password
- });
- con.connect(function(err) {
- if (err) throw err;
- console.log("success connect to databse");
- });
- return con;
- },
- getChat: function (trxTime) {
- LIBRARY.xmpp.on('chat', function(from, message) {
- var arr = message.trim().split(".").map(val => String(val));
- var productCode = arr[0];
- var msidn = arr[1];
- var pin = arr[2];
- var agenId = arr[3];
- if(productCode === undefined || msidn === undefined || pin === undefined || agenId === undefined){
- LIBRARY.xmpp.send(from,'WRONG FORMAT')
- return 'WRONG FORMAT';
- }
- agenId = agenId.replace(/(\n|\r)+$/, '');
- var con = LIBRARY.mysql.createConnection({
- host: GLOBAL_CONFIG.mysql.host,
- port: GLOBAL_CONFIG.mysql.port,
- database: GLOBAL_CONFIG.mysql.database,
- user: GLOBAL_CONFIG.mysql.user,
- password: GLOBAL_CONFIG.mysql.password
- });
- con.connect(function(err) {
- if (err) throw err;
- console.log("success connect to databse");
- });
- let sql = "SELECT pin,chan_suffix,channel_id,store_id,pos_id FROM channel_agen left join stockiest on stockiest.agenid = channel_agen.agen_id where channel_agen.agen_id='"+agenId+"'";
- con.query(sql, function (err, result) {
- if (err) throw err;
- //CURL TO SMTEL
- if(result.length <= 0){
- LIBRARY.xmpp.send(from,'DATA NOT FOUND')
- return 'DATA NOT FOUND';
- }
- var partnerTrxId = LIBRARY.uniqid(agenId+'-');
- let smtelData = {
- channelId: result[0].channel_id,
- storeId:result[0].store_id,
- posId:'',
- secretKey: result[0].chan_suffix,
- pin:pin
- };
- const password = LIBRARY.function.createSMTelSignature(
- partnerTrxId,
- trxTime,
- smtelData
- );
- const smtelUrl =
- GLOBAL_CONFIG.smtel.baseurl +
- "?channelid=" +
- result[0].channel_id +
- "&password=" +
- password +
- "&cmd=" +
- "topup" +
- "&hp=" +
- msidn +
- "&vtype=" +
- productCode +
- "&trxtime=" +
- trxTime +
- "&partner_trxid=" +
- partnerTrxId +
- "&storeid=" +
- result[0].store_id;
- let isRequestTimeout = false;
- const topupResponseXML = LIBRARY.axios
- .get(smtelUrl, { timeout: 35000 })
- .then(function(response) {
- topupResponseJSON = LIBRARY.xml2json.toJson(response.data, {
- object: true
- });
- var resMessage = 'STATUS:'+topupResponseJSON.response.rescode+','+
- 'TOPUP:'+topupResponseJSON.response.hp+' '+topupResponseJSON.response.scrmessage+','+
- 'SN:'+topupResponseJSON.response.sn +','+
- 'TRXID:'+topupResponseJSON.response.server_trxid +','+
- 'BALANCE:'+topupResponseJSON.response.balance +','+
- 'PRICE:'+topupResponseJSON.response.harga
- LIBRARY.xmpp.send(from,resMessage)
- })
- .catch(function(err) {
- if (err.code === "ECONNABORTED") {
- isRequestTimeout = true;
- } else {
- throw err;
- }
- });
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement