telco_server/tools/sms/sohan_test.go
chenlin ef1a39a0a3 1、新增对外短信接口;
2、新增硕软相关接口;
2025-09-04 17:55:02 +08:00

85 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package sms
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
// ---------------- 模拟服务 ----------------
// mockServer 返回一个 httptest.Server用于模拟API响应
func mockServer(t *testing.T, path string, response interface{}) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("unexpected path: got %s, want %s", r.URL.Path, path)
}
_ = json.NewEncoder(w).Encode(response)
}))
}
// ---------------- 测试发送短信 ----------------
func TestSendSMS(t *testing.T) {
client := NewClient()
content := "【明慧科技】提醒您的go2ns租卡会员时长仅剩余一个月现在续费最高立减200元赶快进入小程序领取优惠吧"
returnUrl := "https://telecom.2016js.com/api/v1/sohan/notice"
body := BusinessBody{
Content: &content,
SendList: []SendList{
{
OutOrderID: "ORDER777",
PhoneNumber: "15019230751"},
},
ReturnURL: &returnUrl,
}
resp, err := client.SendSMS(body)
if err != nil {
t.Fatalf("SendSMS error: %v", err)
}
fmt.Printf("response: %+v", resp)
if resp.StatusCode != 1 {
t.Errorf("unexpected response: %+v", resp)
}
}
// ---------------- 测试查询余额 ----------------
func TestGetBalance(t *testing.T) {
client := NewClient()
resp, err := client.GetBalance()
if err != nil {
t.Fatalf("GetBalance error: %v", err)
}
fmt.Printf("response: %+v", resp)
if resp.StatusCode != 1 {
t.Errorf("unexpected response: %+v", resp)
}
}
// ---------------- 测试查询状态 ----------------
func TestQueryState(t *testing.T) {
client := NewClient()
resp, err := client.QueryState("ORDER123", "15019230751")
if err != nil {
t.Fatalf("QueryState error: %v", err)
}
fmt.Printf("response: %+v", resp)
if resp.StatusCode != 1 {
t.Errorf("unexpected sendStatus: %s", resp.Data.SendStatus)
}
}