client_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package mengwang
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "go-common/app/job/main/sms/conf"
  8. "go-common/app/service/main/sms/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. mw *Client
  13. sl = &model.ModelSend{Mobile: "", Content: "卍 测试短信,验证码为5467当日有效 https://search.bilibili.com/all?keyword=你好"} // 17621660828
  14. isl = &model.ModelSend{Country: "852", Mobile: "", Content: "卍 您的账号正在哔哩哔哩2017动画角色人气大赏活动中进行领票操作,验证码为5467当日有效"} // 00852 69529378 梦网的香港测试号
  15. )
  16. func init() {
  17. dir, _ := filepath.Abs("../../cmd/sms-job-test.toml")
  18. flag.Set("conf", dir)
  19. conf.Init()
  20. mw = NewClient(conf.Conf)
  21. }
  22. func TestSendSms(t *testing.T) {
  23. Convey("mengwang send sms", t, func() {
  24. msgid, err := mw.SendSms(context.TODO(), sl)
  25. So(err, ShouldBeNil)
  26. t.Logf("msgid(%s)", msgid)
  27. })
  28. }
  29. func TestSendActSms(t *testing.T) {
  30. Convey("mengwang send act sms", t, func() {
  31. msgid, err := mw.SendActSms(context.TODO(), sl)
  32. So(err, ShouldBeNil)
  33. t.Logf("msgid(%s)", msgid)
  34. })
  35. }
  36. func TestSendBatchSms(t *testing.T) {
  37. Convey("mengwang send batch sms", t, func() {
  38. msl := sl
  39. msl.Mobile = "" // 17621660828,17621660828
  40. msgid, err := mw.SendActSms(context.TODO(), msl)
  41. So(err, ShouldBeNil)
  42. t.Logf("msgid(%s)", msgid)
  43. })
  44. }
  45. func TestSendInternationalSms(t *testing.T) {
  46. Convey("mengwang send international sms", t, func() {
  47. msgid, err := mw.SendInternationalSms(context.TODO(), isl)
  48. So(err, ShouldBeNil)
  49. t.Logf("msgid(%s)", msgid)
  50. })
  51. }
  52. func TestCallback(t *testing.T) {
  53. Convey("mengwang callback", t, func() {
  54. // callbacks, err := mw.Callback(context.Background(), conf.Conf.Pconf.MengWangSmsUser, conf.Conf.Pconf.MengWangSmsPwd, conf.Conf.Pconf.MengWangSmsCallbackURL, 5)
  55. // So(err, ShouldBeNil)
  56. // t.Logf("callbacks(%d)", len(callbacks))
  57. // for _, v := range callbacks {
  58. // t.Logf("callback(%+v)", v)
  59. // }
  60. })
  61. }