Exemplo n.º 1
0
func (rpc *SM) submit(req url.Values) (resp *ShortMessageResp, status int, err error) {
	sm := &smpp.ShortMessage{}
	var msg, enc, register string
	f := form{
		{"src", "number of sender", false, nil, &sm.Src},
		{"dst", "number of recipient", true, nil, &sm.Dst},
		{"text", "text message", true, nil, &msg},
		{"enc", "text encoding", false, []string{"latin1", "ucs2"}, &enc},
		{"register", "registered delivery", false, []string{"final", "failure"}, &register},
	}
	if err := f.Validate(req); err != nil {
		return nil, http.StatusBadRequest, err
	}
	switch enc {
	case "":
		sm.Text = pdutext.Raw(msg)
	case "latin1", "latin-1":
		sm.Text = pdutext.Latin1(msg)
	case "ucs2", "ucs-2":
		sm.Text = pdutext.UCS2(msg)
	}
	switch register {
	case "final":
		sm.Register = smpp.FinalDeliveryReceipt
	case "failure":
		sm.Register = smpp.FailureDeliveryReceipt
	}
	sm, err = rpc.tx.Submit(sm)
	if err == smpp.ErrNotConnected {
		return nil, http.StatusServiceUnavailable, err
	}
	if err != nil {
		return nil, http.StatusBadGateway, err
	}
	resp = &ShortMessageResp{MessageID: sm.RespID()}
	return resp, http.StatusOK, nil
}
Exemplo n.º 2
0
		log.Println("Connecting...")
		tx := newTransmitter(c)
		defer tx.Close()
		log.Println("Connected to", tx.Addr)
		sender := c.Args()[0]
		recipient := c.Args()[1]
		text := strings.Join(c.Args()[2:], " ")
		log.Printf("Command: send %q %q %q", sender, recipient, text)
		var register smpp.DeliverySetting
		if c.Bool("register") {
			register = smpp.FinalDeliveryReceipt
		}
		var codec pdutext.Codec
		switch c.String("encoding") {
		case "ucs2", "ucs-2":
			codec = pdutext.UCS2(text)
		case "latin1", "latin-1":
			codec = pdutext.Latin1(text)
		default:
			codec = pdutext.Raw(text)
		}
		sm, err := tx.Submit(&smpp.ShortMessage{
			Src:                  sender,
			Dst:                  recipient,
			Text:                 codec,
			Register:             register,
			ServiceType:          c.String("service-type"),
			SourceAddrTON:        uint8(c.Int("source-addr-ton")),
			SourceAddrNPI:        uint8(c.Int("source-addr-npi")),
			DestAddrTON:          uint8(c.Int("dest-addr-ton")),
			DestAddrNPI:          uint8(c.Int("dest-addr-npi")),