Skip to content

k.utils.sms

SMS sending (multi-provider)

Overview

k.utils.sms Select provider by site Console SMS Settings. Templates and signatures must be configured on the corresponding platform.

PropertyDescription
aliSMSAlibaba Cloud SMS
tencentTencent Cloud SMS
chinaMobileChina Mobile

aliSMS

MethodDescription
send(templateCode, phone, key, value)Single variable template
send(templateCode, phone, bindings)multivariable dictionary
sendInternational(...)International SMS
ParameterTypeRequiredDescription
templateCodestringYesAlibaba Cloud SMS template code
phonestringYesRecipient phone number; China domestic numbers can omit +86
keystringYesSingle template variable name
valuestringYesSingle template variable value
bindingsRecord<string, any>YesMulti-variable template parameter object

Returns: boolean; returns true on success, and throws when settings are missing or the provider reports an error.

Alibaba Cloud SMS reads the Ali SMS settings from the site console. Domestic China numbers can omit +86; the runtime adds it automatically.

ts
const ok = k.utils.sms.aliSMS.send(
    "SMS_123456789",
    "13800138000",
    "code",
    "493821"
)

return { sent: ok }

Pass an object for templates with multiple variables:

ts
const ok = k.utils.sms.aliSMS.send("SMS_ORDER_NOTICE", "13800138000", {
    orderNo: "SO20260702001",
    amount: "129.00"
})

Use the configured international signature for international SMS:

ts
k.utils.sms.aliSMS.sendInternational(
    "SMS_GLOBAL_CODE",
    "+14155550100",
    "code",
    "493821"
)

tencent

send(templateId, phone, parameters)parameters is the template parameter object.

ParameterTypeRequiredDescription
templateIdstringYesTencent Cloud SMS template Id
phonestringYesRecipient phone number; China domestic numbers can omit +86
parametersRecord<string, any>NoTemplate parameter object; values are passed in object enumeration order

Returns: boolean; returns true when the provider status is Ok.

ts
const ok = k.utils.sms.tencent.send("1850001", "13800138000", {
    code: "493821",
    minutes: "5"
})

return { sent: ok }

chinaMobile

send(phone, content) or send(phones[], content).

ParameterTypeRequiredDescription
phonestringYesSingle phone number
phonesstring[]YesMultiple phone numbers
contentstringYesSMS message body

Returns: boolean; returns true on success, and throws when the provider fails.

ts
k.utils.sms.chinaMobile.send("13800138000", "Your verification code is 493821.")

Send to multiple numbers:

ts
k.utils.sms.chinaMobile.send(
    ["13800138000", "13900139000"],
    "Your order has been shipped."
)