Unofficial library for send SMS messages with China-ASEAN Information Harbor SMS API from applications written with Go language.
Install caih-sms-go by following command:
go get -u github.com/yusufthedragon/caih-sms-go
Then, you can import it using:
import caihsms "github.com/yusufthedragon/caih-sms-go"
Configure package with your token obtained from CAIH.
caihsms.Conf.SetToken("TOKEN")
Configure package with your channel key obtained from CAIH.
caihsms.Conf.SetChannelKey("CHANNEL_KEY")
// or chain it with setToken method
caihsms.Conf.SetToken("TOKEN").SetChannelKey("CHANNEL_KEY")
Send a single SMS request to specific number.
var request = caihsms.SendSMSRequest{
ToNumber: toNumber, // string
Message: message, // string
RequestID: requestId, // string
SendType: sendType, // string
From: from, // string, optional
}
var send, err = request.Send()
Usage example:
var test = caihsms.SendSMSRequest{
ToNumber: "6282147218942",
Message: "Test Message",
RequestID: "X00000001",
SendType: "S0001",
}
var send, err = test.Send()
Check the sending status of SMS message.
var request = caihsms.QueryStatusRequest{
ToNumber: toNumber, // string
MessageID: messageId, // string
}
var queryStatus, err = request.QueryStatus()
Usage example:
var request = caihsms.QueryStatusRequest{
ToNumber: "6282147218942",
MessageID: "1348644286813773824",
}
var queryStatus, err = request.QueryStatus()
Send SMS messages in batches.
var request = caihsms.BatchSendRequest{
BatchMessage: batchMessage, // []string
BatchToNumber: batchToNumber, // []string
RequestID: requestId, // string
}
var batchSend, err = request.BatchSend()
Usage example:
var request = caihsms.BatchSendRequest{
BatchMessage: []string{"6282147218942", "6282147218943", "6282147218944"},
BatchToNumber: []string{"Test Message 1", "Test Message 2", "Test Message 3"},
RequestID: "X00000002",
}
var batchSend, err = request.BatchSend()
Check the sending status of SMS messages in batches.
var request = caihsms.BatchQueryStatusRequest{
BatchMessageID: batchMessageId, // []string
BatchToNumber: batchToNumber, // []string
RequestID: requestId, // string
}
var batchQueryStatus, err = request.BatchQueryStatus()
Usage example:
var request = caihsms.BatchQueryStatusRequest{
BatchMessageID: []string{"910471603446566431", "910471603446566432", "910471603446566433"},
BatchToNumber: []string{"6282147218942", "6282147218943", "6282147218944"},
RequestID: "X00000002",
}
var batchQueryStatus, err = request.BatchQueryStatus()
Rename the .env.example
file to .env
and set the Token and Channel Key with the one you obtained from CAIH. After that, you can run the test by following command:
go test -v
For any requests, bugs, or comments, please open an issue or submit a pull request.