opentelecoms-org / jsmpp

SMPP implemented in Java
Apache License 2.0
232 stars 164 forks source link

[help wanted] How to parse decimal id in deliver receipt with leading zero #178

Open mario45211 opened 2 years ago

mario45211 commented 2 years ago

Hi,

Recently, SMSC which whom I integrate starts sending decimal id in deliver receipt with leading zero like this id:0221067780 sub:001 dlvrd:001 [...]. Based on example I wrote parsing logic, which use below snippet:

var longId = Long.parseLong(decimalIdFromReceipt)
var messageIdHex = Long.toString(longId, 16)

which obviously truncates leading zero on first line, parsing String to Long and fails matching with messageId from submit_sm_resp.

Is there any known better approach to parse messageId from deliver receipts ? Or maybe anyone knows how SMSC converts messageId into decimal representation, which I can invert on my side (assuming there is some well-known technic, not the custom one in each SMSC) ?

I know some deliver receipt's type can include messageId in optional parameter but as far I am concerned that SMSC does not support it...

Thanks for any tips in advance!

pmoerenhout commented 1 year ago

I had a similar problem. If the messageId in the delivery receipt is always 10 digits, you could use something like: (The StringUtils is teh Apache Commons Lang3 library)

public static String messageIdIntToHex(final String messageId) {
    final Long value = Long.parseLong(messageId);
    if (value < 0L || value > 1099511627775L) {
      throw new NumberFormatException("Message ID " + messageId + " cannot be converted to hexadecimals string with length 10");
    }
    return StringUtils.leftPad(Long.toHexString(value).toUpperCase(), 10, "0");
}
mario45211 commented 1 year ago

My SMSC does not guarantee that messageId is composed with a 10-digit value. For me the only way to solve that issue is to read messageId from the optional parameter of a deliverSm - lucky, my SMSC confirmed to fill that parameter.