qsms

package module
v0.0.0-...-c07453f Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 17 Imported by: 0

README

qsms

A golang implementation of @qcloudsms 's SMS API

Usage

    package main

    import (
        "github.com/mysqto/qsms"
        "log"
        "time"
    )

    func main() {
        // Get appID & appKey from the tencent cloud console
        appID := ""
        appKey := ""
        receiver := "+8618888888888"
        now := time.Now().Unix()
        client := qsms.NewClient(appID, appKey) // create a new SMS Client

        // sending a sms using the Client
        result, err := client.SendSMS("+8618888888888", "hello, world")
        if err != nil || result.Status != 0 {
            log.Printf("error sending sms : [err = %v, result = %v]", err, result)
        } else {
            // result.MessageID is server-side messageId, can be paired with result.LocalMessageID to identify single message
            log.Printf("sms send with : status = %s, messageID = %s", result.ErrMsg, result.MessageID)
        }

        // Pull the send result
        rptResult, err := client.MobileStatusPull(receiver, now-1*60*60, now)

        if err != nil {
            log.Printf("error pulling sms status: [err = %v, multiResult = %v]", err, result)
        } else {
            for _, report := range rptResult.Reports {
                // report.MessageID is same with mtResult.MessageID in a SMS
                log.Printf("sms deliver status : %v", report)
            }
        }
    }

see example for more detailed usage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	IDGenerator func() string
	// contains filtered or unexported fields
}

Client a Tencent cloud SMS client

func NewClient

func NewClient(appID, appKey string) *Client

NewClient create a Tencent cloud SMS client

func (*Client) MobileStatusPull

func (c *Client) MobileStatusPull(mobile string, startTime int64, endTime int64) (*MultiResult, error)

MobileStatusPull pull SMS messages status for single mobile.

func (*Client) SMSStatusPull

func (c *Client) SMSStatusPull() (*MultiResult, error)

SMSStatusPull Pull SMS message status, this routine is enterprise only, please contact Tencent to open this feature see

func (*Client) SendMarketSMS

func (c *Client) SendMarketSMS(mobile, content string) (*Result, error)

SendMarketSMS send single market SMS without template and sign, which is available for enterprise account

func (*Client) SendMarketSMSWithTemplate

func (c *Client) SendMarketSMSWithTemplate(mobile string, sign string, templateID string,
	parameters []string) (*Result, error)

SendMarketSMSWithTemplate send single market SMS with template and sign, which is default for personal account

func (*Client) SendMultipleMarketSMS

func (c *Client) SendMultipleMarketSMS(mobile []string,
	content string) (*MultiResult, error)

SendMultipleMarketSMS multiple receiver version of SendMarketSMS

func (*Client) SendMultipleMarketSMSWithTemplate

func (c *Client) SendMultipleMarketSMSWithTemplate(mobile []string,
	sign, templateID string,
	parameters []string) (*MultiResult, error)

SendMultipleMarketSMSWithTemplate multiple receiver version of SendMarketSMSWithTemplate

func (*Client) SendMultipleSMS

func (c *Client) SendMultipleSMS(mobile []string, content string) (*MultiResult, error)

SendMultipleSMS multiple receiver version of SendSMS

func (*Client) SendMultipleSMSWithTemplate

func (c *Client) SendMultipleSMSWithTemplate(mobile []string, sign, templateID string,
	parameters []string) (*MultiResult, error)

SendMultipleSMSWithTemplate multiple receiver version of SendSMSWithTemplate

func (*Client) SendSMS

func (c *Client) SendSMS(mobile, content string) (*Result, error)

SendSMS send single notification SMS without template and sign, which is available for enterprise account

func (*Client) SendSMSWithTemplate

func (c *Client) SendSMSWithTemplate(mobile string, sign string, templateID string,
	parameters []string) (*Result, error)

SendSMSWithTemplate send single notification SMS with template and sign, which is default for personal account

func (*Client) SendVoicePrompt

func (c *Client) SendVoicePrompt(mobile string, content string, duration int64) (*Result, error)

SendVoicePrompt send voice message

func (*Client) SendVoiceWithFile

func (c *Client) SendVoiceWithFile(mobile string, file string) (*Result, error)

SendVoiceWithFile send voice with file

func (*Client) SendVoiceWithTemplate

func (c *Client) SendVoiceWithTemplate(mobile string, templateID string,
	templateParams []string, duration int64) (*Result, error)

SendVoiceWithTemplate send voice with template and template parameters

type MultiResult

type MultiResult struct {
	Status         int          `json:"result"`
	ErrMsg         string       `json:"errMsg"`
	LocalMessageID string       `json:"ext,omitempty"`
	CallID         string       `json:"callid,omitempty"`
	ReportCount    int          `json:"count,omitempty"`
	MTResults      []SendResult `json:"detail,omitempty"`
	Reports        []Report     `json:"data,omitempty"`
	FileID         string       `json:"fid,omitempty"`
}

MultiResult result for multiple receivers

type Report

type Report struct {
	Status        string `json:"report_status,omitempty"`
	DeliverTime   string `json:"user_receive_time,omitempty"`
	CountryCode   string `json:"nationcode,omitempty"`
	Mobile        string `json:"mobile,omitempty"`
	MessageID     string `json:"sid,omitempty"`
	DeliverStatus string `json:"errmsg,omitempty"`
	Description   string `json:"description,omitempty"`
	PullType      int    `json:"pull_type,omitempty"`
}

Report represents the SMS Report message

type Result

type Result struct {
	Status         int    `json:"result"`
	ErrMsg         string `json:"errmsg"`
	LocalMessageID string `json:"ext"`
	MessageID      string `json:"sid,omitempty"`
	Fee            int    `json:"fee,omitempty"`
}

Result send result of single SMS

{
  "result": 0,
  "errmsg": "OK",
  "ext": "6b6a09e7-be31-48cd-8171-0057ccbe550d",
  "sid": "2018:-9173686749108840660",
  "fee": 1
}

type SendResult

type SendResult struct {
	Status      int    `json:"result"`
	ErrMsg      string `json:"errmsg"`
	CountryCode string `json:"nationcode,omitempty"`
	Mobile      string `json:"mobile,omitempty"`
	MessageID   string `json:"sid,omitempty"`
	Fee         int    `json:"fee,omitempty"`
}

SendResult result for single sms sending

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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