Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 接受UniCode短信_Java_Smpp_Jsmpp - Fatal编程技术网

Java 接受UniCode短信

Java 接受UniCode短信,java,smpp,jsmpp,Java,Smpp,Jsmpp,我想从jSMPP接收UniCode短信 如果数据编码为8,我想将其转换为Unicode符号 为此,我使用了HexUtil.convertBytesToHexString函数 但它不能正确地转换它。如何转换此字符串 @Override public void onAcceptDeliverSm(DeliverSm arg0) throws ProcessRequestException { if (MessageType.SMSC_D

我想从jSMPP接收UniCode短信

如果数据编码为8,我想将其转换为Unicode符号

为此,我使用了
HexUtil.convertBytesToHexString
函数

但它不能正确地转换它。如何转换此字符串

        @Override
    public void onAcceptDeliverSm(DeliverSm arg0)
            throws ProcessRequestException {
        if (MessageType.SMSC_DEL_RECEIPT.containedIn(arg0.getEsmClass())) {
            // Deliver SM
        } else {
            byte[] data = arg0.getShortMessage();
            String text = null;

            if (arg0.getShortMessage() != null) {
                if (arg0.getDataCoding() == (byte) 8) {
                    text = HexUtil.convertBytesToHexString(data, 0,
                            data.length);
                } else {
                    text = new String(data);
                }
            }

                    System.out.println("Text -> " + text);
        }
    }
尝试以下方法(使用您自己的编码检测):


如果UTF-16显示不正确,您也可以尝试UTF-16LE、UTF-16BE编码

如何获取字符串?粘贴您的代码我使用“getShortMessage”方法从DeliverSm获取
        if (msg.getEncoding().equals(Message.MessageEncodings.ENC7BIT)) {
            text = msg.getText();
        } else if (msg.getEncoding().equals(Message.MessageEncodings.ENCUCS2)) {
            try {
                text = new String(msg.getText().getBytes(), "UTF-16");
            } catch (Exception ex) {
                Logger.getLogger("smpp").error("Can't parce USC2 text: " + msg.getText() + ", " + ex.getMessage());
            }
        }