Parse SMS PDU on go

huangapple go评论148阅读模式
英文:

Parse SMS PDU on go

问题

在使用Go语言解析SMS PDU时是否可能?

执行AT命令:

AT+CMGF=0
OK

AT+CMGL=4
+CMGL: 0,1,,26
0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3

有没有办法在Go语言中解码这个呢?

0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3

如果没有,你能提供一个解决方法吗?

英文:

Is it possible to parse SMS PDU using just golang

executing AT command

AT+CMGF=0
OK

AT+CMGL=4
+CMGL: 0,1,,26
0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3

is there way to decode this in go?

0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3

if there's not, can you suggest a work around.

答案1

得分: 4

是的。快速搜索结果如下:github.com/xlab/at/sms。这是一个示例程序:

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/xlab/at/sms"
)

func main() {
	bs, err := hex.DecodeString("0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3")
	if err != nil {
		panic(err)
	}
	msg := new(sms.Message)
	msg.ReadFrom(bs)
	fmt.Println(msg)
}

运行该程序会得到以下结果:

&{0 0 0 0 {63567471770 0 0x57bac0} +639170000293 +639178840731 Hahahaha 0 false false false false false false false}

此外,父包似乎有一些你可能会发现有用的函数。

英文:

Yep. A quick search turned up: github.com/xlab/at/sms. Here's an example program:

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/xlab/at/sms"
)

func main() {
	bs, err := hex.DecodeString("0791361907002039040C9136198748701300005150713220052308C8303A8C0EA3C3")
	if err != nil {
		panic(err)
	}
	msg := new(sms.Message)
	msg.ReadFrom(bs)
	fmt.Println(msg)
}

Running that gives me:

&{0 0 0 0 {63567471770 0 0x57bac0} +639170000293 +639178840731 Hahahaha 0 false false false false false false false}

Also the parent package seems like it has a bunch of functions you may find useful.

huangapple
  • 本文由 发表于 2015年5月18日 04:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/30291987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定