//sends a message to a list of receivers.
//a receiver is a string containing an international telephone number
//without a leading + or 0. to send a sms to a german (+49) number
//you'd use "49172xxxxxx".
//the message strings max len is 160 chars
sends a message to a list of receivers.
a receiver is a string containing an international telephone number
without a leading + or 0. to send a sms to a german (+49) number
you'd use "49172xxxxxx".
the message strings max len is 160 chars
// sends a message to a list of receivers . // a receiver is a string containing an international telephone number // without a leading + or 0 . to send a sms to a german ( + 49 ) number // you ' d use " 49172xxxxxx " . // the message strings max len is 160 chars
func (sms *BulkSMSSMSSender) Send(receivers []string, message string) error {
	if sms.RoutingGroup < 1 || sms.RoutingGroup > 3 {
		return errors.New("Routing Group must be 1, 2 or 3!")
	}
	rtgrp := strconv.Itoa(sms.RoutingGroup)
	endpoint_url := "http://bulksms.vsms.net:5567/eapi/submission/send_sms/2/2.0"
	rcvrs := strings.Join(receivers, ",")
	data := url.Values{
		"username":      []string{sms.Username},
		"password":      []string{sms.Password},
		"message":       []string{message},
		"msisdn":        []string{rcvrs},
		"routing_group": []string{rtgrp},
	}
	if len(sms.SenderId) > 0 {
		data.Set("sender", sms.SenderId)
	}
	if sms.Testmode == -1 {
		data["test_always_fail"] = []string{"1"}
	}
	if sms.Testmode == 1 {
		data["test_always_succeed"] = []string{"1"}
	}
	c := &http.Client{}
	resp, err := c.PostForm(endpoint_url, data)
	if err != nil {
		return err
	}
	respbytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	resp.Body.Close()
	respstr := string(respbytes[0:])
	respitems := strings.Split(respstr, "|")
	respcode, err := strconv.ParseInt(respitems[0], 10, 64)
	if err != nil {
		return err
	}
	if respcode != 0 {
		return errors.New(fmt.Sprintf("err code %d: %s", respcode, respitems[1]))
	}
	return nil
}
func ( sms * BulkSMSSMSSender ) Send ( receivers [ ] string , message string ) error { if sms . RoutingGroup < 1 || sms . RoutingGroup > 3 { return errors . New ( " " ) } rtgrp := strconv . Itoa ( sms . RoutingGroup ) endpoint_url := " " rcvrs := strings . Join ( receivers , " " ) data := url . Values { " " : [ ] string { sms . Username } , " " : [ ] string { sms . Password } , " " : [ ] string { message } , " " : [ ] string { rcvrs } , " " : [ ] string { rtgrp } , } if len ( sms . SenderId ) > 0 { data . Set ( " " , sms . SenderId ) } if sms . Testmode == - 1 { data [ " " ] = [ ] string { " " } } if sms . Testmode == 1 { data [ " " ] = [ ] string { " " } } c := & http . Client { } resp , err := c . PostForm ( endpoint_url , data ) if err != nil { return err } respbytes , err := ioutil . ReadAll ( resp . Body ) if err != nil { return err } resp . Body . Close ( ) respstr := string ( respbytes [ 0 : ] ) respitems := strings . Split ( respstr , " " ) respcode , err := strconv . ParseInt ( respitems [ 0 ] , 10 , 64 ) if err != nil { return err } if respcode != 0 { return errors . New ( fmt . Sprintf ( " " , respcode , respitems [ 1 ] ) ) } return nil }
sends a message to a list of receivers.
sends a message to a list of receivers .