gosms

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

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 12 Imported by: 0

README

# gosms 使用go 实现常用的sms服务SDK(非官方),目前只实现腾讯云短信功能

已实现功能:

  1. 单发短信
  2. 统一国家码群发短信
  3. 各自国家码群发短信
  4. 拉取单个号码短信下发状态
  5. 拉取短信下发状态(需要腾讯云开通)
  6. 拉取单个号码短信回复
  7. 拉取短信回复(需要腾讯云开通)
  8. 发送语音验证码
  9. 发送语音通知
  • 其中5、7、8、9没有测试条件所以暂未测试,如果又问题请联系我,谢谢!

使用方法

方法很简单,直接上代码

1. 单发短信

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 发送短信
	res, err := sender.SingleSend(
		"短信签名",     // 短信签名,此处应填写审核通过的签名内容,非签名 ID,如果使用默认签名,该字段填 ""
		86,            // 国家号
		"13800000000", // 手机号
		10000,         // 短信正文ID
		"123456",      // 参数1
		"5",           // 参数2,后面可添加多个参数
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}
}

2. 统一国家码群发短信

所有号码都是同一国家码时可以使用此方法

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 统一国家码群发短信
	res, err := sender.MultiSend(
		"短信签名", // 短信签名,此处应填写审核通过的签名内容,非签名 ID,如果使用默认签名,该字段填 ""
		86, // 国家号
		[]string{
			"13800000000", // 手机号
			"13800000000", // 手机号
			"13800000000", // 手机号
		},
		10000,    // 短信正文ID
		"123456", // 参数1
		"5",      // 参数2,后面可添加多个参数
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}
}

3. 各自国家码群发短信

群发时号码国家码不同时使用此方法

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 各自国家码群发短信
	res, err := sender.MultiSendEachCC(
		"短信签名", // 短信签名,此处应填写审核通过的签名内容,非签名 ID,如果使用默认签名,该字段填 ""
		[]Telphone{
			Telphone{
				Phone: "13800000000", // 手机号
				CC:    86,            // 国家号
			},
			Telphone{
				Phone: "13800000000", // 手机号
				CC:    86,            // 国家号
			},
		},
		10000,    // 短信正文ID
		"123456", // 参数1
		"5",      // 参数2,后面可添加多个参数
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}
}

4. 拉取单个号码短信下发状态

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 拉取下发状态
	res, err := sender.PullSingleStatus(
		86,                    // 国家码
		"13800000000",         // 号码
		"2019-04-01 00:00:00", // 开始日期,注意格式
		"2019-04-03 00:00:00", // 结束日期,注意格式
		100,                   // 拉取最大条数,最大拉取100条
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}

5. 拉取短信下发状态

  • 此功能需要联系腾讯云开通
package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 拉取下发状态 此功能需要联系 qcloud sms helper 开通。
	res, err := sender.PullStatus(100) // 最大拉取100条
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}

6. 拉取单个号码短信回复

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 拉取短信回复
	res, err := sender.PullSingleReply(
		86,                    // 国家码
		"13800000000",         // 号码
		"2019-04-01 00:00:00", // 开始日期,注意格式
		"2019-04-03 00:00:00", // 结束日期,注意格式
		100,                   // 拉取最大条数,最大拉取100条
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}

7. 拉取短信回复

  • 此功能需要联系腾讯云开通
package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 拉取短信回复 此功能需要联系 qcloud sms helper 开通。
	res, err := sender.PullReply(100) // 最大拉取100条
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}

8. 发送语音验证码

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 发送语音验证码
	res, err := sender.VoiceSendCaptcha(
		"13800000000", // 手机号
		2,             // 播报次数,最多3次
		"123456",      // 要播报的验证码,仅支持数字(string类型)
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}
}

9. 发送语音通知

package main

import (
	"fmt"

	"github.com/11m09d/gosms"
)

func main() {
	// 创建Sender
	sender := &gosms.QSender{
		AppID:  "1234567890",                       // appid
		AppKey: "12345678901234567890123456789000", // appkey
	}

	// 发送语音通知
	res, err := sender.VoiceSendPrompt(
		"13800000000", // 手机号
		2,             // 播报次数,最多3次
		"语音内容文本", // 要播报的语音文本类容
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(res)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QMultiResult

type QMultiResult struct {
	Result int                  `json:"result"`
	ErrMsg string               `json:"errmsg"`
	Ext    string               `json:"ext"`
	Detail []qMultiResultDetail `json:"detail"`
	Sid    string               `json:"sid"`
}

QMultiResult 群发回复

type QPullReplyResult

type QPullReplyResult struct {
	Count  int             `json:"count"`
	Data   []QReplyMessage `json:"data"`
	ErrMsg string          `json:"errmsg"`
	Result int             `json:"result"`
}

QPullReplyResult 拉取短信状态结果

type QPullStatusResult

type QPullStatusResult struct {
	Count  int           `json:"count"`
	Data   []QSendStatus `json:"data"`
	ErrMsg string        `json:"errmsg"`
	Result int           `json:"result"`
}

QPullStatusResult 拉取短信状态结果

type QReplyMessage

type QReplyMessage struct {
	Extend     string `json:"extend"`
	Mobile     string `json:"mobile"`
	Nationcode string `json:"nationcode"`
	Sign       string `json:"sign"`
	Text       string `json:"text"`
	Time       int64  `json:"time"`
}

QReplyMessage 回复消息

type QSendStatus

type QSendStatus struct {
	UserReceiveTime string `json:"user_receive_time"`
	Nationcode      string `json:"nationcode"`
	Mobile          string `json:"mobile"`
	ReportStatus    string `json:"report_status"`
	Errmsg          string `json:"errmsg"`
	Description     string `json:"description"`
	Sid             string `json:"sid"`
}

QSendStatus 短信状态

type QSender

type QSender struct {
	AppID  string
	AppKey string
}

QSender 发送模型

func (*QSender) MultiSend

func (s *QSender) MultiSend(sign string, countryCode int, mobiles []string, tplID int, params ...string) (*QMultiResult, error)

MultiSend 统一国家码群发短信

func (*QSender) MultiSendEachCC

func (s *QSender) MultiSendEachCC(sign string, telphones []Telphone, tplID int, params ...string) (*QMultiResult, error)

MultiSendEachCC 各自国家码群发短信

func (*QSender) PullReply

func (s *QSender) PullReply(max int) (*QPullReplyResult, error)

PullReply 拉取短信回复

func (*QSender) PullSingleReply

func (s *QSender) PullSingleReply(countryCode int, moblie string, beginTimeStr string, endTimeStr string, max int) (*QPullReplyResult, error)

PullSingleReply 拉取单个号码短信回复

func (*QSender) PullSingleStatus

func (s *QSender) PullSingleStatus(countryCode int, moblie string, beginTimeStr string, endTimeStr string, max int) (*QPullStatusResult, error)

PullSingleStatus 拉取单个号码短信下发状态

func (*QSender) PullStatus

func (s *QSender) PullStatus(max int) (*QPullStatusResult, error)

PullStatus 拉取短信下发状态

func (*QSender) SingleSend

func (s *QSender) SingleSend(sign string, countryCode int, mobile string, tplID int, params ...string) (*QSingleResult, error)

SingleSend 发送单条短信

func (*QSender) VoiceSendCaptcha

func (s *QSender) VoiceSendCaptcha(mobile string, playTimes int, code string) (*QVoiceResult, error)

VoiceSendCaptcha 发送语音验证码 给国内用户发语音验证码(仅支持数字)

func (*QSender) VoiceSendPrompt

func (s *QSender) VoiceSendPrompt(mobile string, playTimes int, promptfile string) (*QVoiceResult, error)

VoiceSendPrompt 发送语音通知 给国内用户发语音通知(支持中文、英文字母、数字及组合,内容长度不超过100字)

func (*QSender) VoiceSendTpl

func (s *QSender) VoiceSendTpl(mobile string, playTimes int, params []string, tplID int) (*QVoiceResult, error)

VoiceSendTpl 发送语音模板通知 给国内用户发语音通知(支持中文、英文字母、数字及组合,内容长度不超过100字)

type QSingleResult

type QSingleResult struct {
	Result int    `json:"result"`
	ErrMsg string `json:"errmsg"`
	Ext    string `json:"ext"`
	Fee    int    `json:"fee"`
	Sid    string `json:"sid"`
}

QSingleResult 单发回复

type QVoiceResult

type QVoiceResult struct {
	Result int    `json:"result"`
	ErrMsg string `json:"errmsg"`
	CallID string `json:"callid"`
	Ext    string `json:"ext"`
}

QVoiceResult 语音验证码和通知返回

type Telphone

type Telphone struct {
	Phone string // 手机号码
	CC    int    // 国家码
}

Telphone 手机号模型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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