luosimao

package module
v0.0.0-...-8fa62bc Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

luosimao

国内的luosimao短信接口类库,实现了短信的发送和语音验证码的发送。

通过go get获取类库
go get github.com/gogap/luosimao
示例代码

请将您自己的API密码和手机号填到下面对应的变量。

package main

import (
    "encoding/json"
    "fmt"

    "github.com/gogap/luosimao"
)

var voiceAuth luosimao.Authorization
var smsAuth luosimao.Authorization

func main() {
    voiceAuth = luosimao.Authorization{UserName: "api", Password: ""}
    smsAuth = luosimao.Authorization{UserName: "api", Password: ""}

    send_voice("13400000000", 123)
    send_sms("13400000000", "您的验证码是:1234 【公司签名】")
    voice_status()
    sms_status()
}

func send_voice(mobile string, code int32) {
    sender := luosimao.NewVoiceSender(voiceAuth, luosimao.JSON)
    resp, err := sender.Send(luosimao.VoiceRequest{Mobile: mobile, Code: code}, 1000)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
        fmt.Println(resp.ErrorDescription())
    }
}

func voice_status() {
    sender := luosimao.NewVoiceSender(voiceAuth, luosimao.JSON)
    resp, err := sender.Status(1000)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
        fmt.Println(resp.ErrorDescription())
    }
}

func send_sms(mobile, message string) {
    sender := luosimao.NewSMSSender(smsAuth, luosimao.JSON)
    resp, err := sender.Send(luosimao.SMSRequest{Mobile: mobile, Message: message}, 1000)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
        fmt.Println(resp.ErrorDescription())
    }
}

func sms_status() {
    sender := luosimao.NewSMSSender(smsAuth, luosimao.JSON)
    resp, err := sender.Status(1000)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        b, _ := json.Marshal(resp)
        fmt.Println(string(b))
        fmt.Println(resp.ErrorDescription())
    }
}

Documentation

Index

Constants

View Source
const (
	SMSServerURL   = "https://sms-api.luosimao.com/v1/"
	VoiceServerURL = "https://voice-api.luosimao.com/v1/"
)

Variables

This section is empty.

Functions

func GetErrorDescription

func GetErrorDescription(errCode ErrorCode) string

Types

type Authorization

type Authorization struct {
	UserName string
	Password string
}

func (*Authorization) BasicAuthorization

func (p *Authorization) BasicAuthorization() string

type BatchSMSRequest

type BatchSMSRequest struct {
	Mobiles  string `json:"mobile_list"`
	Message  string `json:"message,string"`
	Time     string `json:"time, string"`
	CallBack string `json:"cb,omitempty"`
}

type ErrorCode

type ErrorCode int32
const (
	SMS_ERROR_OK                     ErrorCode = 0
	SMS_ERROR_VALIDATE_ERROR         ErrorCode = -10
	SMS_ERROR_BALANCE_NOT_ENOUGH     ErrorCode = -20
	SMS_ERROR_EMPTY_MESSAGE          ErrorCode = -30
	SMS_ERROR_CONTENT_SENSITIVE_WORD ErrorCode = -31
	SMS_ERROR_NO_SIGNATURE           ErrorCode = -32
	SMS_ERROR_WRONG_MOBILE_NUMBER    ErrorCode = -40
	SMS_ERROR_IP_NOT_IN_WHITE_LIST   ErrorCode = -50
)

type ProtocalType

type ProtocalType int32
const (
	JSON ProtocalType = 1
	XML  ProtocalType = 2
)

type Response

type Response struct {
	XMLName xml.Name  `json:"-" xml:"response"`
	Error   ErrorCode `json:"error" xml:"error"`
	Message string    `json:"message" xml:"msg"`
}

func (*Response) ErrorDescription

func (p *Response) ErrorDescription() string

type SMSRequest

type SMSRequest struct {
	Mobile   string `json:"mobile"`
	Message  string `json:"message,string"`
	CallBack string `json:"cb,omitempty"`
}

type SMSSender

type SMSSender struct {
	Proxy string
	// contains filtered or unexported fields
}

func NewSMSSender

func NewSMSSender(auth Authorization, proto ProtocalType) *SMSSender

func (*SMSSender) BatchSend

func (p *SMSSender) BatchSend(req BatchSMSRequest, timeout int64) (response Response, err error)

func (*SMSSender) Send

func (p *SMSSender) Send(req SMSRequest, timeout int64) (response Response, err error)

func (*SMSSender) Status

func (p *SMSSender) Status(timeout int64) (status Status, err error)

type Status

type Status struct {
	XMLName xml.Name  `json:"-" xml:"response"`
	Error   ErrorCode `json:"error" xml:"error"`
	Deposit int64     `json:"deposit,string" xml:"deposit"`
}

func (*Status) ErrorDescription

func (p *Status) ErrorDescription() string

type VoiceRequest

type VoiceRequest struct {
	Mobile string `json:"mobile"`
	Code   int32  `json:"code,string"`
}

type VoiceSender

type VoiceSender struct {
	Proxy string
	// contains filtered or unexported fields
}

func NewVoiceSender

func NewVoiceSender(auth Authorization, proto ProtocalType) *VoiceSender

func (*VoiceSender) Send

func (p *VoiceSender) Send(req VoiceRequest, timeout int64) (response Response, err error)

func (*VoiceSender) Status

func (p *VoiceSender) Status(timeout int64) (status Status, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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