cz.mmsparams.api.connections.AndroidConnectBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MmsParamsAPI Show documentation
Show all versions of MmsParamsAPI Show documentation
Common library for MmsParams system
The newest version!
package cz.mmsparams.api.connections;
import cz.mmsparams.api.http.auth.JwtRequest;
import cz.mmsparams.api.utils.SimplePasswordUtil;
import cz.mmsparams.api.utils.StringUtil;
public class AndroidConnectBuilder
{
private AndroidConnectBuilder()
{
}
public static final String PREFIX = "MMSPARAMS_CONNECT_WS";
/**
* Create SMS message text for remote phone connect
*
* @param address server address
* @param forceReconect force reconect WebSocket when already connected
* @param customPhoneName custom phone name to set
* @param jwtRequest username and password for authentication
* @return SMS message with remote connect info
*/
public static String createConnectMessage(String address, boolean forceReconect,
String customPhoneName, JwtRequest jwtRequest)
{
StringBuilder sb = new StringBuilder();
sb.append(PREFIX);
sb.append(";");
sb.append(address);
sb.append(";");
sb.append(forceReconect);
sb.append(";");
if (!StringUtil.isEmptyOrNull(customPhoneName))
sb.append(customPhoneName);
String auth = SimplePasswordUtil.encrypt(jwtRequest);
sb.append(";");
if (!StringUtil.isEmptyOrNull(auth))
sb.append(auth);
return sb.toString();
}
public static AndroidConnectModel parse(String connectionText)
{
String[] params = connectionText.split(";");
JwtRequest jwtRequest = SimplePasswordUtil.decrypt(params[4]);
return new AndroidConnectModel(params[1], Boolean.parseBoolean(params[2]), params[3], jwtRequest);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy