var https = require('https') var querystring = require('querystring') var messageContent = 'CommzGate test SMS message' //If non chinese use 'A' Else 'U' var messageType = /^[\x00-\x7F]*$/.test(messageContent) if(!messageType){ //We need to convert the message content to hex padded with zeros. var convertedContent = ''; for(var i = 0; i < messageContent.length;i++){ var tmp = messageContent.charCodeAt(i).toString(16) //Padd with zeros until its 4 chars long. var pad = ''; for(var j =0; j< 4 - tmp.length ; j++){ pad += '0' } convertedContent += pad+tmp } } var cgPostString = querystring.stringify({ 'ID' : '', 'Password' : '', 'Mobile' : '6591000000', 'Type' : (messageType)?'A':'U', 'Message' : (messageType)?messageContent:convertedContent }) var cghttpsOptions = { hostname: 'www.commzgate.net', port: 443, path: '/gateway/SendMsg', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': cgPostString.length } } var cgReq = https.request(cghttpsOptions, (cgRes) => { cgRes.on('data', (value) =>{ if(value.indexOf('01010') > -1){ console.log('Success! :'+value) } else{ console.log('Error : '+value) } }) }) cgReq.on('error', (cgError) =>{ console.log('CG error: %j',cgError) }) cgReq.write(cgPostString) cgReq.end()