chore: 初始开源发布

iotlcm-sms:独立短信 HTTP/gRPC 服务,支持阿里云与腾讯云。

- Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-sms
- 补 Apache-2.0 LICENSE,重写 README(特性/配置/接口/部署/目录/测试)
- 配置改为 config.example.yaml + SMS_* 环境变量注入,仓库不含真实凭证
- 清理内部标识(私有镜像仓库 / 公司名 / 客户签名 / 真实模板ID / 真实手机号)
- 统一 LF 行尾并加 .gitattributes
This commit is contained in:
MiFaZhan
2026-10-22 14:21:47 +08:00
commit 4fb1016977
31 changed files with 2351 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/encoding/protojson"
"git.5iot.com/iotlcm-public/iotlcm-sms/api/pb"
)
type requestFile struct {
Config json.RawMessage `json:"config"`
Params json.RawMessage `json:"params"`
}
func main() {
if len(os.Args) < 2 {
log.Fatalf("usage: go run ./examples/grpc_client <request.json> [host:port]")
}
address := "127.0.0.1:11200"
if len(os.Args) > 2 {
address = os.Args[2]
}
data, err := os.ReadFile(os.Args[1])
if err != nil {
log.Fatal(err)
}
var input requestFile
if err := json.Unmarshal(data, &input); err != nil {
log.Fatal(err)
}
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
response, err := pb.NewNoticeClient(conn).Send(ctx, &pb.SendReq{
Head: &pb.HeadReq{
RouterId: time.Now().UnixNano(),
TraceId: fmt.Sprintf("grpc-example-%d", time.Now().Unix()),
},
Config: input.Config,
Params: input.Params,
})
if err != nil {
log.Fatal(err)
}
output, err := protojson.MarshalOptions{Indent: " "}.Marshal(response)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
endpoint := "http://127.0.0.1:8080/api/v1/sms/send"
if len(os.Args) > 1 {
endpoint = os.Args[1]
}
// 阿里云 msgContent 是模板参数 JSON;请替换为测试账号、签名和模板。
body := []byte(`{
"config": {
"serviceType": "1",
"regionId": "cn-hangzhou",
"accessKeyId": "your-access-key-id",
"accessKeySecret": "your-access-key-secret",
"signName": "your-sign-name",
"templateId": "SMS_000000001"
},
"params": {
"phoneNumber": "138****8000",
"msgContent": "{\"code\":\"123456\"}"
}
}`)
response, err := http.Post(endpoint, "application/json", bytes.NewReader(body))
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
responseBody, err := io.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("HTTP %d\n%s", response.StatusCode, responseBody)
}
+14
View File
@@ -0,0 +1,14 @@
{
"config": {
"serviceType": "1",
"regionId": "cn-hangzhou",
"accessKeyId": "${ALIYUN_ACCESS_KEY_ID}",
"accessKeySecret": "${ALIYUN_ACCESS_KEY_SECRET}",
"signName": "示例签名",
"templateId": "SMS_000000000"
},
"params": {
"phoneNumber": "138****8000",
"msgContent": "{\"code\":\"123456\"}"
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"config": {
"serviceType": "2",
"sdkAppId": "1400000000",
"accessKeyId": "${TENCENTCLOUD_SECRET_ID}",
"accessKeySecret": "${TENCENTCLOUD_SECRET_KEY}",
"signName": "示例签名",
"templateId": "000000"
},
"params": {
"phoneNumber": "138****8000",
"msgContent": "123456|5"
}
}