final pom changes
This commit is contained in:
parent
1ea9e72024
commit
1ee353c179
5 changed files with 159 additions and 28 deletions
22
README.md
22
README.md
|
@ -139,7 +139,7 @@ Before you begin, ensure you have the following installed:
|
||||||
* Navigate to the "WAR file to deploy" section.
|
* Navigate to the "WAR file to deploy" section.
|
||||||
* Choose the `shorten.war` file using the file upload button.
|
* Choose the `shorten.war` file using the file upload button.
|
||||||
* Click the "Deploy" button.
|
* Click the "Deploy" button.
|
||||||
3. **Configure environment variables:**
|
3. **Configure Variables on deployed war:**
|
||||||
|
|
||||||
Set environment variables for cloud-specific settings.
|
Set environment variables for cloud-specific settings.
|
||||||
|
|
||||||
|
@ -246,6 +246,26 @@ Wait until the pod is in the "Running" state.
|
||||||
Access your application using the provided external IP.
|
Access your application using the provided external IP.
|
||||||
|
|
||||||
|
|
||||||
|
### SMS Service Configuration
|
||||||
|
|
||||||
|
To configure the SMS service, you need to specify parameters related to the SMS provider in the `application.properties` file.
|
||||||
|
|
||||||
|
* #### Managed SMS Provider (Uses HttpSms API from https://httpsms.com/)
|
||||||
|
* Generate API Key : https://httpsms.com/settings/
|
||||||
|
* HttpSms API Docs : https://api.httpsms.com/
|
||||||
|
|
||||||
|
```properties
|
||||||
|
sms.provider=managed
|
||||||
|
managed.sms.api.key=your_managed_sms_api_key
|
||||||
|
managed.sms.phone-number=123456789
|
||||||
|
|
||||||
|
* #### Self-hosted SMS Provider (Host our open source android-based SMS web gateway : https://api.httpsms.com/)
|
||||||
|
|
||||||
|
```properties
|
||||||
|
sms.provider=selfhosted
|
||||||
|
selfhosted.gateway.url=https://your-smsgateway-url/index.php
|
||||||
|
selfhosted.device.id=your_device_id
|
||||||
|
selfhosted.hash=your_device_hash
|
||||||
|
|
||||||
### App Health
|
### App Health
|
||||||
|
|
||||||
|
|
|
@ -5,23 +5,48 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SmsService {
|
public class SmsService {
|
||||||
|
|
||||||
|
private final SmsServiceConfig smsServiceConfig;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SmsService.class);
|
private static final Logger logger = LoggerFactory.getLogger(SmsService.class);
|
||||||
|
|
||||||
|
public SmsService(SmsServiceConfig smsServiceConfig) {
|
||||||
|
this.smsServiceConfig = smsServiceConfig;
|
||||||
|
}
|
||||||
|
|
||||||
public void sendSms(String toNumber, String message) {
|
public void sendSms(String toNumber, String message) {
|
||||||
try {
|
try {
|
||||||
// Send the SMS to the user (you need to implement this part)
|
if ("managed".equals(smsServiceConfig.getSmsProvider())) {
|
||||||
|
sendSmsToManagedProvider(toNumber, message);
|
||||||
|
} else if ("selfhosted".equals(smsServiceConfig.getSmsProvider())) {
|
||||||
|
sendSmsToSelfHostedGateway(toNumber, message);
|
||||||
|
} else {
|
||||||
|
logger.error("Invalid SMS provider configuration");
|
||||||
|
}
|
||||||
|
logger.info("SMS sent successfully to {}", toNumber);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Log and handle SMS sending failure
|
||||||
|
logger.error("Failed to send SMS to {}: {}", toNumber, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendSmsToManagedProvider(String toNumber, String message) throws Exception {
|
||||||
var client = HttpClient.newHttpClient();
|
var client = HttpClient.newHttpClient();
|
||||||
var apiKey = "Vucf1nCa4ed-AMNGv6CnsycfQT28yLUA8NEvY7IZ87-Piv855UBcjfo29Zb8XPZt";
|
|
||||||
|
var apiKey = smsServiceConfig.getManagedSmsApiKey();
|
||||||
|
var phoneNumber = smsServiceConfig.getManagedPhoneNumber();
|
||||||
|
|
||||||
String payload = "{\n" +
|
String payload = "{\n" +
|
||||||
" \"content\": \"" + message + "\",\n" + // Use concatenation for variables
|
" \"content\": \"" + message + "\",\n" +
|
||||||
" \"from\": \"+9038556097\",\n" +
|
" \"from\": \"+"+ phoneNumber + "\",\n" +
|
||||||
" \"to\": \"" + toNumber + "\"\n" +
|
" \"to\": \"" + toNumber + "\"\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
@ -35,11 +60,33 @@ public class SmsService {
|
||||||
|
|
||||||
var response = client.send(requestBuild, HttpResponse.BodyHandlers.ofString());
|
var response = client.send(requestBuild, HttpResponse.BodyHandlers.ofString());
|
||||||
System.out.println(response.body());
|
System.out.println(response.body());
|
||||||
logger.info("SMS sent successfully to {}", toNumber);
|
logger.info("External SMS API response: {}", response.body());
|
||||||
logger.debug("SMS API response: {}", response.body());
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
// Log and handle SMS sending failure
|
private void sendSmsToSelfHostedGateway(String toNumber, String message) throws Exception {
|
||||||
logger.error("Failed to send SMS to {}: {}", toNumber, e.getMessage(), e);
|
// Replace with your actual SMSGateway server URL, device ID, and hash
|
||||||
}
|
|
||||||
|
String gatewayUrl = smsServiceConfig.getSelfHostedGatewayUrl();
|
||||||
|
String deviceId = smsServiceConfig.getSelfHostedDeviceId();
|
||||||
|
String hash = smsServiceConfig.getSelfHostedHash();
|
||||||
|
|
||||||
|
// Encode special characters in the message
|
||||||
|
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8.toString());
|
||||||
|
|
||||||
|
// Build the final URL
|
||||||
|
var finalUrl = String.format("%s?id=%s&h=%s&to=%s&message=%s", gatewayUrl, deviceId, hash, toNumber, encodedMessage);
|
||||||
|
|
||||||
|
var client = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
var requestBuild = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(finalUrl))
|
||||||
|
.header("accept", "application/json")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var response = client.send(requestBuild, HttpResponse.BodyHandlers.ofString());
|
||||||
|
System.out.println(response.body());
|
||||||
|
logger.info("SMSGateway API response: {}", response.body());
|
||||||
}
|
}
|
||||||
}
|
}
|
50
src/main/java/com/bitmutex/shortener/SmsServiceConfig.java
Normal file
50
src/main/java/com/bitmutex/shortener/SmsServiceConfig.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package com.bitmutex.shortener;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SmsServiceConfig {
|
||||||
|
|
||||||
|
@Value("${sms.provider}")
|
||||||
|
private String smsProvider;
|
||||||
|
|
||||||
|
@Value("${managed.sms.api.key}")
|
||||||
|
private String managedSmsApiKey;
|
||||||
|
|
||||||
|
@Value("${managed.sms.phone-number}")
|
||||||
|
private String managedPhoneNumber;
|
||||||
|
|
||||||
|
@Value("${selfhosted.gateway.url}")
|
||||||
|
private String selfHostedGatewayUrl;
|
||||||
|
|
||||||
|
@Value("${selfhosted.device.id}")
|
||||||
|
private String selfHostedDeviceId;
|
||||||
|
|
||||||
|
@Value("${selfhosted.hash}")
|
||||||
|
private String selfHostedHash;
|
||||||
|
|
||||||
|
public String getSmsProvider() {
|
||||||
|
return smsProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getManagedPhoneNumber() {
|
||||||
|
return managedPhoneNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getManagedSmsApiKey() {
|
||||||
|
return managedSmsApiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelfHostedGatewayUrl() {
|
||||||
|
return selfHostedGatewayUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelfHostedDeviceId() {
|
||||||
|
return selfHostedDeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelfHostedHash() {
|
||||||
|
return selfHostedHash;
|
||||||
|
}
|
||||||
|
}
|
|
@ -91,9 +91,20 @@ springdoc.api-docs.path=/docs
|
||||||
springdoc.swagger-ui.path=/docs-ui
|
springdoc.swagger-ui.path=/docs-ui
|
||||||
springdoc.swagger-ui.operationsSorter=method
|
springdoc.swagger-ui.operationsSorter=method
|
||||||
springdoc.show-actuator=true
|
springdoc.show-actuator=true
|
||||||
|
#Springdoc Swagger Config
|
||||||
springdoc.swagger-ui.oauthClientId=Iv1.8d3d0ea51b7e7da3
|
springdoc.swagger-ui.oauthClientId=Iv1.8d3d0ea51b7e7da3
|
||||||
springdoc.swagger-ui.oauthClientSecret=2176086761d073b2082afdc4af0207fa7d1d274b
|
springdoc.swagger-ui.oauthClientSecret=2176086761d073b2082afdc4af0207fa7d1d274b
|
||||||
springdoc.swagger-ui.oauthAppName=Bitmutex Shortener
|
springdoc.swagger-ui.oauthAppName=Bitmutex Shortener
|
||||||
springdoc.swagger-ui.oauthScopeSeparator=/v
|
springdoc.swagger-ui.oauthScopeSeparator=/v
|
||||||
springdoc.swagger-ui.showRequestHeaders=true
|
springdoc.swagger-ui.showRequestHeaders=true
|
||||||
|
|
||||||
|
|
||||||
|
# SMS Provider Configuration (managed/selfhosted)
|
||||||
|
sms.provider=selfhosted
|
||||||
|
# For Managed SMS Provider (uses httpSms API from https://httpsms.com/settings)
|
||||||
|
managed.sms.api.key=Vucf1nCa4ed-AMNGv6CnsycfQT28yLUA8NEvY7IZ87-Piv855UBcjfo29Zb8XPZt
|
||||||
|
managed.sms.phone-number=9038556097
|
||||||
|
# For Self-Hosted SMSGateway (android app url : https://bitmutexsms.000webhostapp.com/index.php?id=f0edf9a81c2461b5&h=b4132c)
|
||||||
|
selfhosted.gateway.url=https://bitmutexsms.000webhostapp.com/index.php
|
||||||
|
selfhosted.device.id=f0edf9a81c2461b5
|
||||||
|
selfhosted.hash=b4132c
|
||||||
|
|
|
@ -17,10 +17,13 @@
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
<fileNamePattern>${LOG_ARCHIVE}/shortener.log.%d{yyyy-MM-dd}.log</fileNamePattern>
|
<fileNamePattern>${LOG_PATH}/shortener.log.%d{yyyy-MM-dd}.%i.zip</fileNamePattern>
|
||||||
|
<minIndex>1</minIndex>
|
||||||
|
<maxIndex>4</maxIndex>
|
||||||
|
<!-- keep 30 days' worth of history -->
|
||||||
<maxHistory>30</maxHistory>
|
<maxHistory>30</maxHistory>
|
||||||
<maxFileSize>10MB</maxFileSize>
|
<maxFileSize>5MB</maxFileSize>
|
||||||
<totalSizeCap>1GB</totalSizeCap>
|
<totalSizeCap>1GB</totalSizeCap>
|
||||||
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
|
@ -33,7 +36,7 @@
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Root Logger -->
|
<!-- Root Logger -->
|
||||||
<root level="info">
|
<root level="debug">
|
||||||
<appender-ref ref="async" />
|
<appender-ref ref="async" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue