UCloud SMS (USMS) driver for smsutils.
This module implements the model.Driver / model.Client interfaces of the core
smsutils library on top of the UCloud ucloud-sdk-go USMS service.
Driver name: ucloud
go get go.gh.ink/smsutils/ucloud/v3Blank-import this package so it registers itself, then configure it via the core client.
import (
"go.gh.ink/smsutils/v3/client"
"go.gh.ink/smsutils/v3/model"
_ "go.gh.ink/smsutils/ucloud/v3"
)
clients, err := client.NewClient(model.Config{
Credentials: model.C{
"ucloud": {
"publicKey": "<your-public-key>",
"privateKey": "<your-private-key>",
"projectId": "<your-project-id>",
},
},
})
if err != nil {
panic(err)
}
// "sender" is the SigContent; "UTA..." is the USMS TemplateId.
err = clients["ucloud"].SendMessage("+8617601205205", "<sign-content>", "UTA12345", model.Vars{
{Key: "code", Value: "1234"},
})The existing client.NewClient and SendMessage APIs remain available. With the
updated local core and this driver, use the same configuration with the new factory:
// Additional imports: "context", "time".
clients, err := client.NewClientCtx(config, model.ClientOptions{Timeout: 5 * time.Second})
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(context.Background(), 3 * time.Second)
defer cancel()
err = clients["ucloud"].SendMessageCtx(ctx, dest, sender, template, vars)config has the credential layout shown above. ClientOptions.Transport optionally
injects a concurrency-safe HTTP transport. Context cancellation reaches the HTTP request;
a timeout does not prove the provider did not accept the SMS, so avoid blind retries.
Nil variable entries and malformed provider responses are rejected.
These additions require the updated core source. Existing dependency versions are
intentionally unchanged until release. For local testing, create a Go workspace containing
this module and the sibling smsutils/v3 core module; see the core repository's
CONTEXT.md (local path: ../smsutils/CONTEXT.md) for the complete six-module
commands and API contracts.
| Key | Constant | Required | Description |
|---|---|---|---|
publicKey |
PublicKey |
Yes | UCloud API public key |
privateKey |
PrivateKey |
Yes | UCloud API private key |
projectId |
ProjectId |
Yes | UCloud project ID |
Missing any of these yields errors.ErrDriverCredentialInvalid.
- The destination is normalized via
utils.ProcessNumberForChinese, then reformatted into UCloud's(countryCode)nationalNumberform (e.g.(86)17601205205). templatemaps to the USMSTemplateId;sendermaps toSigContent.varsare passed positionally asTemplateParams(in the order supplied), so the order ofmodel.Varsmust match the placeholders in your template. TheKeyfields are ignored.- A USMS
RetCodeerror is mapped toerrors.ErrDriverSendFailed, decorated with the provider code, message, request UUID and raw response. Other SDK server errors are returned as-is. - The SDK log level is set to
Fatalto suppress noisy output.
- Go 1.25.0+
go.gh.ink/smsutils/v3- UCloud SDK:
github.com/ucloud/ucloud-sdk-go