chore: 并入 iotlcm-sms 历史到 sms/(原提交 1d38bc4)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:02 +08:00
34 changed files with 2776 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": "13800008000",
"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-qingdao",
"accessKeyId": "${ALIYUN_ACCESS_KEY_ID}",
"accessKeySecret": "${ALIYUN_ACCESS_KEY_SECRET}",
"signName": "示例企业",
"templateId": "SMS_305105966"
},
"params": {
"phoneNumber": "18600001858",
"msgContent": "{\"code\":\"482731\"}"
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"config": {
"serviceType": "2",
"sdkAppId": "1400929370",
"accessKeyId": "${TENCENTCLOUD_SECRET_ID}",
"accessKeySecret": "${TENCENTCLOUD_SECRET_KEY}",
"signName": "示例企业",
"templateId": "2234038"
},
"params": {
"phoneNumber": "+8618610281858",
"msgContent": "482731|5"
}
}