sms

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 5 Imported by: 0

README

sms

Installation

go get github.com/go-packagist/sms

Usage

package main

import (
	"github.com/davecgh/go-spew/spew"
	"github.com/go-packagist/sms"
	"github.com/go-packagist/sms/gateway"
	"github.com/go-packagist/sms/gateway/log"
	"github.com/go-packagist/sms/gateway/mitake"
)

func main() {
	Example1()
	Example2()
}

func Example1() {
	cfg := &sms.Config{
		Default: "log",
		Gateways: map[string]gateway.Config{
			"mitake": &mitake.Config{
				ApiUrl: "http://sms.mitake.com.tw/path",
				Username: "test",
				Password: "test",
			},
			"log": &log.Config{},
		},
	}

	s := sms.New(cfg)
	resp1, _ := s.Gateway("mitake").Send("13312341234", "Hello World")
	spew.Dump(resp1.IsSuccessful())

	resp2, _ := s.Gateway("log").Send("13312341234", "Hello World")
	spew.Dump(resp2.IsSuccessful())
}

func Example2() {
	l := log.New(&log.Config{})
	l.Send("13312341234", "hello")
	l.Send(gateway.NewPhone("13312341234", ""), gateway.NewMessage("hello "))

	m := mitake.New(&mitake.Config{
		ApiUrl: "http://sms.mitake.com.tw/path",
		Username: "test",
		Password: "test",
	})
	m.Send("13312341234", func(message *gateway.Message) *gateway.Message {
		return message.SetContent("hello")
	})
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Default  string
	Gateways map[string]gateway.Config
}

type Sms

type Sms struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *Sms

func (*Sms) Gateway

func (s *Sms) Gateway(names ...string) gateway.Gateway

Gateway choose a gateway to send sms.

func (*Sms) Send

func (s *Sms) Send(phone, message interface{}) (*gateway.Response, error)

Send a sms. Example: example/sms/sms.go

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL