使用Golang SMPP协议发送短信时发件地址显示未知问题
SMPP发送短信发件地址显示“Unknown address”的解决方法
问题现象
使用Golang的fiorix/go-smpp库发送短信,消息可成功送达,但接收方手机显示发件地址为“Unknown address”。
问题原因
SMPP协议要求发送方地址(Source Address)必须明确指定地址类型(TON)和地址编码(NPI)。仅设置Src字段时,库会使用默认值,而这个默认值不匹配字母数字签名(如"MyCompany")的类型要求,导致运营商无法识别发件地址,从而显示为Unknown address。
解决方案
在提交短信时,通过ShortMessage结构体的SrcTON和SrcNPI字段指定正确的地址类型和编码:
- 对于字母数字签名,设置
SrcTON为pdufield.Alphanumeric,SrcNPI为pdufield.ISDN(多数运营商兼容此配置)。
修改后的完整代码:
package main import ( "log" "github.com/fiorix/go-smpp/smpp" "github.com/fiorix/go-smpp/smpp/pdu/pdufield" "github.com/fiorix/go-smpp/smpp/pdu/pdutext" ) func main() { tx := &smpp.Transmitter{ Addr: "server:port", User: "userId", Passwd: "password", } // Create persistent connection, wait for the first status. conn := <-tx.Bind() if conn.Status() != smpp.Connected { log.Fatal(conn.Error()) } sm, err := tx.Submit(&smpp.ShortMessage{ Src: "MyCompany", SrcTON: pdufield.Alphanumeric, // 指定字母数字地址类型 SrcNPI: pdufield.ISDN, // 指定ISDN编码 Dst: "25*********", Text: pdutext.Raw("Sample sms"), Register: pdufield.NoDeliveryReceipt, }) if err != nil { log.Fatal(err) } log.Println("Message ID:", sm.RespID()) }
额外说明
- 若配置后仍显示Unknown address,需联系SMPP服务提供商确认:
- 是否支持字母数字签名作为发件地址
- 要求的TON和NPI具体值(部分运营商可能要求NPI为
pdufield.Unknown)
- 若使用手机号作为发件地址,需设置
SrcTON为pdufield.International,SrcNPI为pdufield.ISDN。
内容的提问来源于stack exchange,提问作者Jemale Akil
相关产品推荐
相关产品推荐

