5 changed files with 469 additions and 168 deletions
-
4src/main/java/com/gcc/flagpoles/service/PaymentService.java
-
53src/main/java/com/gcc/flagpoles/service/RequestService.java
-
225src/main/java/com/gcc/flagpoles/service/SMSService.java
-
314src/main/java/com/gcc/flagpoles/service/WhatsappMessageService.java
-
41src/main/java/com/gcc/flagpoles/util/MessageUtility.java
@ -1,39 +1,226 @@ |
|||||
package com.gcc.flagpoles.service; |
package com.gcc.flagpoles.service; |
||||
|
|
||||
|
import java.io.BufferedReader; |
||||
|
import java.io.InputStreamReader; |
||||
|
import java.net.HttpURLConnection; |
||||
|
import java.net.URL; |
||||
|
import java.net.URLEncoder; |
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.client.RestTemplate; |
import org.springframework.web.client.RestTemplate; |
||||
|
|
||||
import java.net.HttpURLConnection; |
|
||||
import java.net.URL; |
|
||||
|
import com.gcc.flagpoles.configuration.AppConfig; |
||||
|
import com.gcc.flagpoles.util.MessageUtility; |
||||
|
|
||||
@Service |
@Service |
||||
public class SMSService { |
public class SMSService { |
||||
public String sendMsg(String msgUrl) { |
|
||||
System.out.println("Whatsapp URL :-" + msgUrl); |
|
||||
|
|
||||
String response = ""; |
|
||||
|
@Autowired |
||||
|
private AppConfig appConfig; |
||||
|
|
||||
|
@Autowired |
||||
|
private MessageUtility messageUtility; |
||||
|
|
||||
|
private final String key = "pfTEYN6H"; |
||||
|
|
||||
|
public String sendBookingSuccesssms(String mobileNo, String requestId) { |
||||
|
|
||||
|
String message = "Your Flag Pole permission request has been submitted successfully. " |
||||
|
+ "Request ID: " + requestId |
||||
|
+ ". You will be notified once the status is updated. By GCC"; |
||||
|
|
||||
|
// Encode message and fix colon issue (gateway not decoding %3A) |
||||
|
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8) |
||||
|
.replace("%3A", ":"); |
||||
|
|
||||
|
String urlString = appConfig.getGetOtpUrl() |
||||
|
+ "from=GCCCRP" |
||||
|
+ "&key=" + key |
||||
|
+ "&sender=GCCCRP" |
||||
|
+ "&to=" + mobileNo |
||||
|
+ "&body=" + encodedMsg |
||||
|
+ "&entityid=1401572690000011081" |
||||
|
+ "&templateid=1407176959297472163"; |
||||
|
|
||||
|
System.out.println("SMS URL:- " + urlString); |
||||
|
|
||||
|
String response = messageUtility.sendSMS(urlString); |
||||
|
System.out.println("SMS RESPONSE:- " + response); |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
public String userrequestApprovedsms(String mobileNo, String requestId) { |
||||
|
|
||||
|
String message = "Your Flag Pole permission request has been approved. " |
||||
|
+ "Request ID: " + requestId |
||||
|
+ ". Please proceed as per the permitted guidelines. By GCC"; |
||||
|
|
||||
|
// Encode message and fix colon issue (gateway not decoding %3A) |
||||
|
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8) |
||||
|
.replace("%3A", ":"); |
||||
|
|
||||
|
String urlString = appConfig.getGetOtpUrl() |
||||
|
+ "from=GCCCRP" |
||||
|
+ "&key=" + key |
||||
|
+ "&sender=GCCCRP" |
||||
|
+ "&to=" + mobileNo |
||||
|
+ "&body=" + encodedMsg |
||||
|
+ "&entityid=1401572690000011081" |
||||
|
+ "&templateid=1407176959297472163"; |
||||
|
|
||||
|
System.out.println("SMS URL:- " + urlString); |
||||
|
|
||||
|
String response = messageUtility.sendSMS(urlString); |
||||
|
System.out.println("SMS RESPONSE:- " + response); |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
public String fineforunauthorizedflagpoleSms(String mobileNo, |
||||
|
String location, |
||||
|
String fineAmount, |
||||
|
String requestId) { |
||||
|
|
||||
|
String message = "An unauthorized flag pole installation was found at " + location + ". " |
||||
|
+ "Fine amount: Rs." + fineAmount |
||||
|
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId=" |
||||
|
+ requestId |
||||
|
+ " to avoid further action.\n" |
||||
|
+ "By GCC"; |
||||
|
|
||||
|
// Encode message and fix colon issue (gateway not decoding %3A) |
||||
|
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8) |
||||
|
.replace("%3A", ":"); |
||||
|
|
||||
|
String urlString = appConfig.getGetOtpUrl() |
||||
|
+ "from=GCCCRP" |
||||
|
+ "&key=" + key |
||||
|
+ "&sender=GCCCRP" |
||||
|
+ "&to=" + mobileNo |
||||
|
+ "&body=" + encodedMsg |
||||
|
+ "&entityid=1401572690000011081" |
||||
|
+ "&templateid=1407176984622316740"; // <-- replace with correct template id |
||||
|
|
||||
|
System.out.println("SMS URL:- " + urlString); |
||||
|
|
||||
|
String response = messageUtility.sendSMS(urlString); |
||||
|
System.out.println("SMS RESPONSE:- " + response); |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
public String restorationflagpoleSms(String mobileNo, |
||||
|
String streetName, |
||||
|
String amount, |
||||
|
String requestId) { |
||||
|
|
||||
try { |
try { |
||||
HttpURLConnection connection = null; |
|
||||
|
|
||||
URL url = new URL(msgUrl); |
|
||||
connection = (HttpURLConnection) url.openConnection(); |
|
||||
connection.setRequestMethod("GET"); |
|
||||
|
String message = "Your flagpole installation at " + streetName |
||||
|
+ " caused damage to the public property. " |
||||
|
+ "Restoration charges of RS." + amount |
||||
|
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId=" |
||||
|
+ requestId |
||||
|
+ " to avoid further action.\r\n" |
||||
|
+ "By GCC"; |
||||
|
|
||||
|
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8); |
||||
|
|
||||
|
String urlString = appConfig.getGetOtpUrl() |
||||
|
+ "from=GCCCRP" |
||||
|
+ "&key=" + key |
||||
|
+ "&sender=GCCCRP" |
||||
|
+ "&to=" + mobileNo |
||||
|
+ "&body=" + encodedMsg |
||||
|
+ "&entityid=1401572690000011081" |
||||
|
+ "&templateid=1407176984612580095"; |
||||
|
|
||||
|
System.out.println("FINAL SMS URL:- " + urlString); |
||||
|
|
||||
|
URL apiUrl = new URL(urlString); |
||||
|
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection(); |
||||
|
conn.setRequestMethod("GET"); |
||||
|
conn.setConnectTimeout(15000); |
||||
|
conn.setReadTimeout(15000); |
||||
|
|
||||
int responseCode = connection.getResponseCode(); |
|
||||
response = responseCode + ""; |
|
||||
System.out.println("Response Code: " + responseCode); |
|
||||
|
BufferedReader in = new BufferedReader( |
||||
|
new InputStreamReader(conn.getInputStream())); |
||||
|
String inputLine; |
||||
|
StringBuilder content = new StringBuilder(); |
||||
|
|
||||
|
while ((inputLine = in.readLine()) != null) { |
||||
|
content.append(inputLine); |
||||
|
} |
||||
|
|
||||
|
in.close(); |
||||
|
conn.disconnect(); |
||||
|
|
||||
|
System.out.println("DIRECT SMS RESPONSE:- " + content.toString()); |
||||
|
|
||||
|
return content.toString(); |
||||
|
|
||||
} catch (Exception e) { |
} catch (Exception e) { |
||||
e.printStackTrace(); |
e.printStackTrace(); |
||||
|
return "FAILED"; |
||||
} |
} |
||||
|
|
||||
return response; |
|
||||
} |
} |
||||
|
|
||||
public String sendSMS(String SMS_Url) { |
|
||||
System.out.println("SMS URL:- " + SMS_Url); |
|
||||
RestTemplate restTemplate = new RestTemplate(); |
|
||||
String response = restTemplate.getForObject(SMS_Url, String.class); |
|
||||
return response; |
|
||||
|
public String unauthorizedFlagPoleSms(String mobileNo, |
||||
|
String streetName, |
||||
|
String fineAmount, |
||||
|
String requestId) { |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
String message = "An unauthorized flag pole installation was found at " + streetName + ". " |
||||
|
+ "Fine amount: Rs." + fineAmount |
||||
|
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId=" |
||||
|
+ requestId |
||||
|
+ " to avoid further action.\r\n" |
||||
|
+ "By GCC"; |
||||
|
|
||||
|
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8); |
||||
|
|
||||
|
String urlString = appConfig.getGetOtpUrl() |
||||
|
+ "from=GCCCRP" |
||||
|
+ "&key=" + key |
||||
|
+ "&sender=GCCCRP" |
||||
|
+ "&to=" + mobileNo |
||||
|
+ "&body=" + encodedMsg |
||||
|
+ "&entityid=1401572690000011081" |
||||
|
+ "&templateid=1407176984622316740"; |
||||
|
|
||||
|
System.out.println("FINAL SMS URL:- " + urlString); |
||||
|
|
||||
|
URL apiUrl = new URL(urlString); |
||||
|
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection(); |
||||
|
conn.setRequestMethod("GET"); |
||||
|
conn.setConnectTimeout(15000); |
||||
|
conn.setReadTimeout(15000); |
||||
|
|
||||
|
BufferedReader in = new BufferedReader( |
||||
|
new InputStreamReader(conn.getInputStream())); |
||||
|
String inputLine; |
||||
|
StringBuilder content = new StringBuilder(); |
||||
|
|
||||
|
while ((inputLine = in.readLine()) != null) { |
||||
|
content.append(inputLine); |
||||
|
} |
||||
|
|
||||
|
in.close(); |
||||
|
conn.disconnect(); |
||||
|
|
||||
|
System.out.println("DIRECT SMS RESPONSE:- " + content.toString()); |
||||
|
|
||||
|
return content.toString(); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return "FAILED"; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
} |
} |
||||
@ -1,147 +1,167 @@ |
|||||
package com.gcc.flagpoles.service; |
|
||||
|
|
||||
import java.net.URLEncoder; |
|
||||
import java.nio.charset.StandardCharsets; |
|
||||
|
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
@Service |
|
||||
public class WhatsappMessageService { |
|
||||
|
|
||||
@Autowired |
|
||||
private SMSService smsService; |
|
||||
|
|
||||
// c & d waste template after user register |
|
||||
public void sendrequestraisedWhatsappMessage(String refId, String mobileNumber) { |
|
||||
try { |
|
||||
|
|
||||
String apiUrl = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" |
|
||||
+ mobileNumber |
|
||||
+ "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Thank+you%21+Your+request+has+been+successfully+submitted.%0ARequest+Id+%3A+" |
|
||||
+ refId |
|
||||
+ "&isTemplate=true&header=C%26D+Waste+Collection+Request+Registered&footer=Greater+Chennai+Corporation"; |
|
||||
|
|
||||
System.out.println("WhatsApp API URL: " + apiUrl); // Optional debug |
|
||||
smsService.sendMsg(apiUrl); |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// payment complete template |
|
||||
public void sendPaymentCompleteWhatsappMessage(String refId, double actualWeight, double totalCharge, |
|
||||
String mobileNumber) { |
|
||||
try { |
|
||||
String message = String.format( |
|
||||
"Your request (Request ID: *%s*) has been processed. Please proceed with the payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
|
||||
refId, actualWeight, totalCharge); |
|
||||
|
|
||||
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
|
||||
String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment Request", StandardCharsets.UTF_8); |
|
||||
String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", StandardCharsets.UTF_8); |
|
||||
|
|
||||
String redirectUrlParam = URLEncoder.encode( |
|
||||
"http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
|
||||
StandardCharsets.UTF_8); |
|
||||
|
|
||||
String apiUrl = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
|
||||
"&password=h2YjFNcJ" + |
|
||||
"&send_to=" + mobileNumber + |
|
||||
"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
|
||||
"&msg=" + encodedMessage + |
|
||||
"&isTemplate=true" + |
|
||||
"&header=" + encodedHeader + |
|
||||
"&footer=" + encodedFooter + |
|
||||
"&buttonUrlParam=" + redirectUrlParam; |
|
||||
|
|
||||
// Optional: log URL before hitting for debugging |
|
||||
System.out.println("WhatsApp API URL: " + apiUrl); |
|
||||
|
|
||||
// Make API call |
|
||||
// restTemplate.getForObject(apiUrl, String.class); |
|
||||
smsService.sendMsg(apiUrl); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
// Optionally log or alert failure |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// for fine collection |
|
||||
public void sendFineCollectionWhatsappMessage(String refId, double actualWeight, double totalCharge, |
|
||||
String mobileNumber) { |
|
||||
try { |
|
||||
String message = String.format( |
|
||||
"Your request (Request ID: *%s*) has been processed. Please proceed with the payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
|
||||
refId, actualWeight, totalCharge); |
|
||||
|
|
||||
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
|
||||
String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment Request", StandardCharsets.UTF_8); |
|
||||
String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", StandardCharsets.UTF_8); |
|
||||
|
|
||||
String redirectUrlParam = URLEncoder.encode( |
|
||||
"http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
|
||||
StandardCharsets.UTF_8); |
|
||||
|
|
||||
String apiUrl = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
|
||||
"&password=h2YjFNcJ" + |
|
||||
"&send_to=" + mobileNumber + |
|
||||
"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
|
||||
"&msg=" + encodedMessage + |
|
||||
"&isTemplate=true" + |
|
||||
"&header=" + encodedHeader + |
|
||||
"&footer=" + encodedFooter + |
|
||||
"&buttonUrlParam=" + redirectUrlParam; |
|
||||
|
|
||||
// Optional: log URL before hitting for debugging |
|
||||
System.out.println("WhatsApp API URL: " + apiUrl); |
|
||||
|
|
||||
// Make API call |
|
||||
// restTemplate.getForObject(apiUrl, String.class); |
|
||||
smsService.sendMsg(apiUrl); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
// Optionally log or alert failure |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// restoration message |
|
||||
public void sendRestorationWhatsappMessage(String refId, double actualWeight, double totalCharge, |
|
||||
String mobileNumber) { |
|
||||
try { |
|
||||
String message = String.format( |
|
||||
"Your request (Request ID: *%s*) has been processed. Please proceed with the payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
|
||||
refId, actualWeight, totalCharge); |
|
||||
|
|
||||
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
|
||||
String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment Request", StandardCharsets.UTF_8); |
|
||||
String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", StandardCharsets.UTF_8); |
|
||||
|
|
||||
String redirectUrlParam = URLEncoder.encode( |
|
||||
"http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
|
||||
StandardCharsets.UTF_8); |
|
||||
|
|
||||
String apiUrl = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
|
||||
"&password=h2YjFNcJ" + |
|
||||
"&send_to=" + mobileNumber + |
|
||||
"&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
|
||||
"&msg=" + encodedMessage + |
|
||||
"&isTemplate=true" + |
|
||||
"&header=" + encodedHeader + |
|
||||
"&footer=" + encodedFooter + |
|
||||
"&buttonUrlParam=" + redirectUrlParam; |
|
||||
|
|
||||
// Optional: log URL before hitting for debugging |
|
||||
System.out.println("WhatsApp API URL: " + apiUrl); |
|
||||
|
|
||||
// Make API call |
|
||||
// restTemplate.getForObject(apiUrl, String.class); |
|
||||
smsService.sendMsg(apiUrl); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
// Optionally log or alert failure |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
// package com.gcc.flagpoles.service; |
||||
|
|
||||
|
// import java.net.URLEncoder; |
||||
|
// import java.nio.charset.StandardCharsets; |
||||
|
|
||||
|
// import org.springframework.beans.factory.annotation.Autowired; |
||||
|
// import org.springframework.stereotype.Service; |
||||
|
|
||||
|
// import com.gcc.flagpoles.util.MessageUtility; |
||||
|
|
||||
|
// @Service |
||||
|
// public class WhatsappMessageService { |
||||
|
// @Autowired |
||||
|
// private MessageUtility messageUtility; |
||||
|
|
||||
|
// // c & d waste template after user register |
||||
|
// public void sendrequestraisedWhatsappMessage(String refId, String |
||||
|
// mobileNumber) { |
||||
|
// try { |
||||
|
|
||||
|
// String apiUrl = |
||||
|
// "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" |
||||
|
// + mobileNumber |
||||
|
// + |
||||
|
// "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Thank+you%21+Your+request+has+been+successfully+submitted.%0ARequest+Id+%3A+" |
||||
|
// + refId |
||||
|
// + |
||||
|
// "&isTemplate=true&header=C%26D+Waste+Collection+Request+Registered&footer=Greater+Chennai+Corporation"; |
||||
|
|
||||
|
// System.out.println("WhatsApp API URL: " + apiUrl); // Optional debug |
||||
|
// messageUtility.sendMsg(apiUrl); |
||||
|
|
||||
|
// } catch (Exception e) { |
||||
|
// e.printStackTrace(); |
||||
|
// } |
||||
|
// } |
||||
|
|
||||
|
// // payment complete template |
||||
|
// public void sendPaymentCompleteWhatsappMessage(String refId, double |
||||
|
// actualWeight, double totalCharge, |
||||
|
// String mobileNumber) { |
||||
|
// try { |
||||
|
// String message = String.format( |
||||
|
// "Your request (Request ID: *%s*) has been processed. Please proceed with the |
||||
|
// payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
||||
|
// refId, actualWeight, totalCharge); |
||||
|
|
||||
|
// String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
||||
|
// String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment |
||||
|
// Request", StandardCharsets.UTF_8); |
||||
|
// String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String redirectUrlParam = URLEncoder.encode( |
||||
|
// "http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String apiUrl = |
||||
|
// "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
||||
|
// "&password=h2YjFNcJ" + |
||||
|
// "&send_to=" + mobileNumber + |
||||
|
// "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
||||
|
// "&msg=" + encodedMessage + |
||||
|
// "&isTemplate=true" + |
||||
|
// "&header=" + encodedHeader + |
||||
|
// "&footer=" + encodedFooter + |
||||
|
// "&buttonUrlParam=" + redirectUrlParam; |
||||
|
|
||||
|
// // Optional: log URL before hitting for debugging |
||||
|
// System.out.println("WhatsApp API URL: " + apiUrl); |
||||
|
|
||||
|
// // Make API call |
||||
|
// // restTemplate.getForObject(apiUrl, String.class); |
||||
|
// messageUtility.sendMsg(apiUrl); |
||||
|
// } catch (Exception e) { |
||||
|
// e.printStackTrace(); |
||||
|
// // Optionally log or alert failure |
||||
|
// } |
||||
|
// } |
||||
|
|
||||
|
// // for fine collection |
||||
|
// public void sendFineCollectionWhatsappMessage(String refId, double |
||||
|
// actualWeight, double totalCharge, |
||||
|
// String mobileNumber) { |
||||
|
// try { |
||||
|
// String message = String.format( |
||||
|
// "Your request (Request ID: *%s*) has been processed. Please proceed with the |
||||
|
// payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
||||
|
// refId, actualWeight, totalCharge); |
||||
|
|
||||
|
// String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
||||
|
// String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment |
||||
|
// Request", StandardCharsets.UTF_8); |
||||
|
// String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String redirectUrlParam = URLEncoder.encode( |
||||
|
// "http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String apiUrl = |
||||
|
// "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
||||
|
// "&password=h2YjFNcJ" + |
||||
|
// "&send_to=" + mobileNumber + |
||||
|
// "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
||||
|
// "&msg=" + encodedMessage + |
||||
|
// "&isTemplate=true" + |
||||
|
// "&header=" + encodedHeader + |
||||
|
// "&footer=" + encodedFooter + |
||||
|
// "&buttonUrlParam=" + redirectUrlParam; |
||||
|
|
||||
|
// // Optional: log URL before hitting for debugging |
||||
|
// System.out.println("WhatsApp API URL: " + apiUrl); |
||||
|
|
||||
|
// // Make API call |
||||
|
// // restTemplate.getForObject(apiUrl, String.class); |
||||
|
// messageUtility.sendMsg(apiUrl); |
||||
|
// } catch (Exception e) { |
||||
|
// e.printStackTrace(); |
||||
|
// // Optionally log or alert failure |
||||
|
// } |
||||
|
// } |
||||
|
|
||||
|
// // restoration message |
||||
|
// public void sendRestorationWhatsappMessage(String refId, double actualWeight, |
||||
|
// double totalCharge, |
||||
|
// String mobileNumber) { |
||||
|
// try { |
||||
|
// String message = String.format( |
||||
|
// "Your request (Request ID: *%s*) has been processed. Please proceed with the |
||||
|
// payment.\n\nActual Weight: *%.0f kg*\nAmount Payable: *%.0f*", |
||||
|
// refId, actualWeight, totalCharge); |
||||
|
|
||||
|
// String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); |
||||
|
// String encodedHeader = URLEncoder.encode("C&D Waste Collection – Payment |
||||
|
// Request", StandardCharsets.UTF_8); |
||||
|
// String encodedFooter = URLEncoder.encode("Greater Chennai Corporation", |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String redirectUrlParam = URLEncoder.encode( |
||||
|
// "http://localhost:8077/flagpolesregistration/paymentform?requestId=" + refId, |
||||
|
// StandardCharsets.UTF_8); |
||||
|
|
||||
|
// String apiUrl = |
||||
|
// "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507" + |
||||
|
// "&password=h2YjFNcJ" + |
||||
|
// "&send_to=" + mobileNumber + |
||||
|
// "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE" + |
||||
|
// "&msg=" + encodedMessage + |
||||
|
// "&isTemplate=true" + |
||||
|
// "&header=" + encodedHeader + |
||||
|
// "&footer=" + encodedFooter + |
||||
|
// "&buttonUrlParam=" + redirectUrlParam; |
||||
|
|
||||
|
// // Optional: log URL before hitting for debugging |
||||
|
// System.out.println("WhatsApp API URL: " + apiUrl); |
||||
|
|
||||
|
// // Make API call |
||||
|
// // restTemplate.getForObject(apiUrl, String.class); |
||||
|
// messageUtility.sendMsg(apiUrl); |
||||
|
// } catch (Exception e) { |
||||
|
// e.printStackTrace(); |
||||
|
// // Optionally log or alert failure |
||||
|
// } |
||||
|
// } |
||||
|
|
||||
|
// } |
||||
@ -0,0 +1,41 @@ |
|||||
|
package com.gcc.flagpoles.util; |
||||
|
|
||||
|
import java.net.HttpURLConnection; |
||||
|
import java.net.URL; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.web.client.RestTemplate; |
||||
|
|
||||
|
@Service |
||||
|
public class MessageUtility { |
||||
|
|
||||
|
public String sendMsg(String msgUrl) { |
||||
|
System.out.println("Whatsapp URL :-" + msgUrl); |
||||
|
|
||||
|
String response = ""; |
||||
|
try { |
||||
|
HttpURLConnection connection = null; |
||||
|
|
||||
|
URL url = new URL(msgUrl); |
||||
|
connection = (HttpURLConnection) url.openConnection(); |
||||
|
connection.setRequestMethod("GET"); |
||||
|
|
||||
|
int responseCode = connection.getResponseCode(); |
||||
|
response = responseCode + ""; |
||||
|
System.out.println("Response Code: " + responseCode); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
public String sendSMS(String SMS_Url) { |
||||
|
// System.out.println("SMS URL:- " + SMS_Url); |
||||
|
RestTemplate restTemplate = new RestTemplate(); |
||||
|
String response = restTemplate.getForObject(SMS_Url, String.class); |
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue