Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mario45211 opened this issue Oct 10, 2022 · 2 comments
Labels

Comments

@mario45211
Copy link

mario45211 commented Oct 10, 2022

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
Copy link
Member

pmoerenhout commented Jan 16, 2023

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
Copy link
Author

mario45211 commented Jan 17, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants