package com.realllinkbilling.message;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.opensymphony.xwork2.ActionSupport;




public class SendTextLocalMessage extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3700627871201985886L;


public static void main(String[] args) {
	
	SendTextLocalMessage messageTextLocal = new SendTextLocalMessage();
	
	//String msg = "प्रिय ग्राहक ,आपले कपडे शिवून तय्यार आहेत. लवकरात लवकर घेणून जाणे. धन्यवाद! मॅक्सलो मेन्स वेअर, इंदापूर-प्रो. प्रा. राम पवार";
	String msg2= "न्यू दत्त बेकरी मधून खरेदी केल्याबद्दल धन्यवाद! आपली एकूण बिलाची रक्कम:2345 रुपये,आपली बचत:34 रुपये . पुन्हा अवश्य भेट द्या.";
	String s = messageTextLocal.sendSms("9730791040",msg2);// "{\"balance\":1978,\"batch_id\":617704018,\"cost\":2,\"num_messages\":1,\"message\":{\"num_parts\":2,\"sender\":\"MAXLOT\",\"content\":\"@U092A094D0930093F092F00200917094D0930093E093909150020002C0906092A0932094700200915092A0921094700200936093F09350942092800200924092F094D092F093E093000200906093909470924002E00200932093509150930093E0924002009320935091509300020091809470923094209280020091C093E09230947002E002009270928094D092F0935093E092600210020092E09450915094D09380932094B0020092E09470928094D093800200935094709050930002C0020090709020926093E092A09420930002D092A094D0930094B002E0020092A094D0930093E002E00200930093E092E0020092A0935093E0930\"},\"receipt_url\":\"\",\"custom\":\"\",\"messages\":[{\"id\":\"1757672126\",\"recipient\":918208064913}],\"status\":\"success\"}";// 
	System.out.println(s);


}

	public String sendSms(String mobileNumber,String msg) {
		
	
		String resp = "";
	try {
		// Construct data //Shaurya : vLNeK/29no8-gGfv0hVv0PNn5BQPp7Cr9Lh16Epbkw
		//gugale = 
		
		String apiKey = "apikey=" + "vLNeK/29no8-gGfv0hVv0PNn5BQPp7Cr9Lh16Epbkw";
		String unicode= "&unicode=true";
		String message = "&message=" + msg;
		String sender = "&sender=" + "SSALES";
		String numbers = "&numbers=" + mobileNumber;
		
		// Send data
		HttpURLConnection conn = (HttpURLConnection) new URL("https://api.textlocal.in/send/?").openConnection();
		String data = apiKey+unicode + numbers + message + sender;
		conn.setDoOutput(true);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
		conn.getOutputStream().write(data.getBytes("UTF-8"));
		final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		final StringBuffer stringBuffer = new StringBuffer();
		String line;
		while ((line = rd.readLine()) != null) {
			stringBuffer.append(line);
		}
		rd.close();
		resp = stringBuffer.toString();
		
		
		
	} catch (Exception e) {
		
	}
	return resp;
}
	
	

}
