| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.processor;
|
1 |
package com.spice.profitmandi.web.processor;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.ArrayList;
|
- |
|
| 5 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| 6 |
import java.util.List;
|
5 |
import java.util.List;
|
| 7 |
import java.util.Map;
|
6 |
import java.util.Map;
|
| 8 |
import java.util.Random;
|
7 |
import java.util.Random;
|
| 9 |
|
8 |
|
| Line 13... |
Line 12... |
| 13 |
import org.springframework.beans.factory.annotation.Value;
|
12 |
import org.springframework.beans.factory.annotation.Value;
|
| 14 |
import org.springframework.mail.javamail.JavaMailSender;
|
13 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 15 |
import org.springframework.stereotype.Component;
|
14 |
import org.springframework.stereotype.Component;
|
| 16 |
|
15 |
|
| 17 |
import com.fasterxml.jackson.annotation.JsonProperty;
|
16 |
import com.fasterxml.jackson.annotation.JsonProperty;
|
| - |
|
17 |
import com.google.common.collect.ImmutableMap;
|
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.web.client.RestClient;
|
19 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 20 |
import com.spice.profitmandi.dao.entity.dtr.Otp;
|
20 |
import com.spice.profitmandi.dao.entity.dtr.Otp;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
21 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
| 22 |
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
|
22 |
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
|
| Line 27... |
Line 27... |
| 27 |
public class OtpProcessor {
|
27 |
public class OtpProcessor {
|
| 28 |
|
28 |
|
| 29 |
private static final Logger LOGGER = LogManager.getLogger(SchemeServiceImpl.class);
|
29 |
private static final Logger LOGGER = LogManager.getLogger(SchemeServiceImpl.class);
|
| 30 |
private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
|
30 |
private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
|
| 31 |
private static final int len = 5;
|
31 |
private static final int len = 5;
|
| - |
|
32 |
private static final String SENDER = "SMTDKN";
|
| - |
|
33 |
|
| - |
|
34 |
|
| 32 |
private static final String numbers = "0123456789";
|
35 |
private static final String numbers = "0123456789";
|
| 33 |
private static final String OTP_TEMPLATE = "Dear Customer, %s is the OTP that you have requested to login into SmartDukaan. Don't share your OTP with anyone";
|
36 |
private static final String OTP_TEMPLATE = "Dear Customer, %s is the OTP that you have requested to login into SmartDukaan. Don't share your OTP with anyone";
|
| - |
|
37 |
private static final String OTP_TEMPLATE_ID = "1507161889822750240";
|
| - |
|
38 |
public static final String SELF_CANCELLED_TEMPLATE = "Order Cancelled PO%s: Dear Customer, your order with SmartDukaan of %s has been cancelled on %s as per your request. Team SmartDukaan";
|
| - |
|
39 |
public static final String SELF_CANCELLED_TEMPLATE_ID = "1507161943392646481";
|
| 34 |
|
40 |
|
| 35 |
// This should remain unused reference template id is -->
|
41 |
// This should remain unused reference template id is -->
|
| 36 |
private static final String orderConfirmationText = "Dear customer, your order of <productname> <+3 more pcs> has been successfully placed with SmartDukaan. We will get in touch with you soon.\n"
|
42 |
private static final String orderConfirmationText = "Dear customer, your order of <productname> <+3 more pcs> has been successfully placed with SmartDukaan. We will get in touch with you soon.\n"
|
| 37 |
+ "SmartDukaan Team";
|
43 |
+ "SmartDukaan Team";
|
| 38 |
|
44 |
|
| Line 135... |
Line 141... |
| 135 |
public void sendOtp(Otp otp) throws Exception {
|
141 |
public void sendOtp(Otp otp) throws Exception {
|
| 136 |
// In case of Cant receive SMS?
|
142 |
// In case of Cant receive SMS?
|
| 137 |
// String mailMessage = java.text.MessageFormat.format(text, otp.getOtp());
|
143 |
// String mailMessage = java.text.MessageFormat.format(text, otp.getOtp());
|
| 138 |
String otpString = otp.getOtp();
|
144 |
String otpString = otp.getOtp();
|
| 139 |
try {
|
145 |
try {
|
| 140 |
this.sendSms(String.format(OTP_TEMPLATE, otpString), otp.getMobile());
|
146 |
this.sendSms(OTP_TEMPLATE_ID, String.format(OTP_TEMPLATE, otpString), otp.getMobile());
|
| 141 |
} catch (Exception e) {
|
147 |
} catch (Exception e) {
|
| 142 |
e.printStackTrace();
|
148 |
e.printStackTrace();
|
| 143 |
}
|
149 |
}
|
| 144 |
|
150 |
|
| 145 |
}
|
151 |
}
|
| 146 |
|
152 |
|
| 147 |
public void sendSms(String message, String mobileNumber) throws Exception {
|
153 |
public void sendSms(String dltTemplateId, String message, String mobileNumber) throws Exception {
|
| 148 |
Map<String, String> map = new HashMap<>();
|
154 |
Map<String, String> map = new HashMap<>();
|
| 149 |
|
155 |
|
| 150 |
map.put("sender", "SMTDKN");
|
156 |
map.put("sender", SENDER);
|
| 151 |
map.put("numbers", "91"+mobileNumber);
|
- |
|
| 152 |
map.put("message", message);
|
- |
|
| 153 |
map.put("messagetype", "TXT");
|
157 |
map.put("messagetype", "TXT");
|
| 154 |
map.put("apikey", "b866f7-c6c483-682ff5-054420-ad9e2c");
|
158 |
map.put("apikey", "b866f7-c6c483-682ff5-054420-ad9e2c");
|
| - |
|
159 |
|
| - |
|
160 |
map.put("numbers", "91"+mobileNumber);
|
| 155 |
LOGGER.info("Message {}", message);
|
161 |
LOGGER.info("Message {}", message);
|
| 156 |
//OTP Message Template
|
162 |
//OTP Message Template
|
| 157 |
map.put("dlttempid", "1507161889822750240");
|
- |
|
| 158 |
//SD
|
- |
|
| 159 |
//map.put("dltentityid", "1501589330000013091");
|
- |
|
| 160 |
//SMTDKN
|
- |
|
| 161 |
//map.put("dltheaderid", "1505159255691251261");
|
- |
|
| 162 |
//Consent Template
|
- |
|
| 163 |
//map.put("dlttagid", "");
|
163 |
map.put("message", message);
|
| 164 |
//Speqtra Innov - Our SMS Provider
|
- |
|
| 165 |
//map.put("tmid", "1502472910000014692");
|
164 |
map.put("dlttempid", dltTemplateId);
|
| 166 |
|
- |
|
| 167 |
|
165 |
|
| 168 |
String response = restClient.post(SMS_GATEWAY, map, new HashMap<>());
|
166 |
String response = restClient.post(SMS_GATEWAY, map, new HashMap<>());
|
| 169 |
LOGGER.info(response);
|
167 |
LOGGER.info(response);
|
| 170 |
|
168 |
|
| 171 |
}
|
169 |
}
|
| 172 |
|
170 |
|
| 173 |
public void sendSmsNew(String message, String mobileNumber) throws Exception {
|
- |
|
| 174 |
Map<String, String> obj = new HashMap<>();
|
- |
|
| 175 |
obj.put("message", message);
|
- |
|
| 176 |
String response = restClient.get(String.format(SMS_GATEWAY, mobileNumber), null, null);
|
- |
|
| 177 |
LOGGER.info(response);
|
- |
|
| 178 |
}
|
- |
|
| 179 |
|
- |
|
| 180 |
class SmsMessage {
|
171 |
class SmsMessage {
|
| 181 |
private String sender = "SMTDKN";
|
172 |
private String sender = "SMTDKN";
|
| 182 |
@JsonProperty(value = "templateid")
|
173 |
@JsonProperty(value = "templateid")
|
| 183 |
private String templateId = "54";
|
174 |
private String templateId = "54";
|
| 184 |
|
175 |
|