{"id":19621596,"url":"https://github.com/pkg6/go-sms","last_synced_at":"2025-11-03T13:04:28.275Z","repository":{"id":196342467,"uuid":"642861938","full_name":"pkg6/go-sms","owner":"pkg6","description":"📲 一款满足你的多种发送需求的短信发送组件","archived":false,"fork":false,"pushed_at":"2024-03-19T08:00:59.000Z","size":51,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-05T06:11:14.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkg6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-19T14:07:05.000Z","updated_at":"2024-06-27T12:29:03.000Z","dependencies_parsed_at":"2023-09-24T16:41:18.432Z","dependency_job_id":"84fdd11d-551c-453f-af68-85d8781b3cc5","html_url":"https://github.com/pkg6/go-sms","commit_stats":null,"previous_names":["pkg6/go-sms"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fgo-sms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fgo-sms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fgo-sms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fgo-sms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkg6","download_url":"https://codeload.github.com/pkg6/go-sms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251246283,"owners_count":21558762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T11:23:41.014Z","updated_at":"2025-11-03T13:04:23.229Z","avatar_url":"https://github.com/pkg6.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eGo SMS\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e:calling: 一款满足你的多种发送需求的短信发送组件\u003c/p\u003e\n\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/pkg6/go-sms)](https://goreportcard.com/report/github.com/pkg6/go-sms)\n[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/pkg6/go-sms?tab=doc)\n[![Sourcegraph](https://sourcegraph.com/github.com/pkg6/go-sms/-/badge.svg)](https://sourcegraph.com/github.com/pkg6/go-sms?badge)\n[![Release](https://img.shields.io/github/release/pkg6/go-sms.svg?style=flat-square)](https://github.com/pkg6/go-sms/releases)\n\n\n## 特点\n\n1. 支持目前市面多家服务商\n1. 一套写法兼容所有平台\n1. 简单配置即可灵活增减服务商\n1. 内置多种服务商轮询策略、支持自定义轮询策略\n1. 统一的返回值格式，便于日志与监控\n1. 更多等你去发现与改进...\n\n## 平台支持\n\n### 目前支持\n\n- [阿里云](https://www.aliyun.com/)\n- [互亿无线](http://www.ihuyi.com)\n- [短信宝](http://www.smsbao.com/)\n- [聚合数据](https://www.juhe.cn)\n- [网易云信](https://yunxin.163.com/sms)\n- [微网通联](https://www.lmobile.cn/)\n- [twilio](https://www.twilio.com/)\n\n## 环境需求\n\n- Golang \u003e= 1.18\n\n\n## 安装\n\n```shell\n$ go get github.com/pkg6/go-sms\n```\n\n## 使用\n\n~~~\npackage main\n\nimport (\n\tgosms \"github.com/pkg6/go-sms\"\n\t\"github.com/pkg6/go-sms/gateways\"\n\t\"github.com/pkg6/go-sms/gateways/twilio\"\n)\n\nfunc main() {\n\tsms := gosms.NewParser(gateways.Gateways{Twilio: twilio.Twilio{AccountSID: \"ACd********\", AuthToken: \"***********\", TwilioPhoneNumber: \"+1********\"}})\n\t// 常规\n\tsms.Send(18888888888, gosms.MapStringAny{\n\t\t\"content\":  \"您的验证码是：****。请不要把验证码泄露给其他人。\",\n\t\t\"template\": \"SMS_001\",\n\t\t\"data\": gosms.MapStrings{\n\t\t\t\"code\": \"6379\",\n\t\t},\n\t}, nil)\n}\n~~~\n\n## 短信内容\n\n由于使用多网关发送，所以一条短信要支持多平台发送，每家的发送方式不一样，但是我们抽象定义了以下公用属性：\n\n- `content` 文字内容，使用在像云片类似的以文字内容发送的平台\n- `sign_name` 签名\n- `template` 模板 ID，使用在以模板ID来发送短信的平台\n- `data`  模板变量，使用在以模板ID来发送短信的平台\n\n所以，在使用过程中你可以根据所要使用的平台定义发送的内容。\n\n~~~\nsms.Send(18888888888, gosms.MapStringAny{\n    \"content\":  \"您的验证码是：****。请不要把验证码泄露给其他人。\",\n    \"template\": \"SMS_001\",\n    \"data\": gosms.MapStrings{\n        \"code\": \"6379\",\n    },\n}, nil)\n~~~\n\n你也可以使用闭包来返回对应的值：\n~~~\nsms.Send(18888888888, gosms.MapStringAny{\n    \"content\": func(gateway gosms.IGateway) string {\n        return \"您的验证码是：****。请不要把验证码泄露给其他人。\"\n    },\n    \"template\": func(gateway gosms.IGateway) string {\n        if gateway.GetName() == \"aliyun\" {\n            return \"TP2818\"\n        }\n        return \"SMS_001\"\n    },\n    \"data\": func(gateway gosms.IGateway) gosms.MapStrings {\n        return map[string]string{\n            \"code\": \"1234\",\n        }\n    },\n}, nil)\n~~~\n\n## 发送网关\n\n默认使用初始化中的网关发送，如果某一条短信你想要覆盖默认的设置。在 `send` 方法中使用第三个参数即可：\n\n```\nsms := gosms.NewGateways(twilio.GateWay(\"ACd********\", \"***********\", \"+1***********\"))\nsms.Send(18888888888, gosms.MapStringAny{\n    \"content\": \"您的验证码是：****。请不要把验证码泄露给其他人。\",\n}, nil)\n```\n\n## 自定义网关\n\n本拓展已经支持用户自定义网关，你可以很方便的配置即可当成与其它拓展一样的使用：\n\n~~~\nsms := gosms.NewGateways()\nsms.Extend(\"aliyun\", aliyun.GateWay(\"accessKeyId\", \"accessKeySecret\"))\nsms.Send(18888888888, gosms.MapStringAny{\n    \"content\": \"您的验证码是：****。请不要把验证码泄露给其他人。\",\n}, []string{\"aliyun\"})\n~~~\n\n\u003e 自定义网关实现接口\n\n~~~\n// IGateway 网关\ntype IGateway interface {\n\t// I 用于初始化默认值\n\tI() IGateway\n\t// GetName 网关名称\n\tGetName() string\n\t// Send 发送操作\n\tSend(to IPhoneNumber, message IMessage) (SMSResult, error)\n}\n~~~\n\n## 通过Sender函数去发送\n~~~\npackage main\n\nimport (\n\t\"fmt\"\n\tgosms \"github.com/pkg6/go-sms\"\n\t\"github.com/pkg6/go-sms/gateways/twilio\"\n)\n\nfunc main() {\n\tgateway := twilio.GateWay(\"ACd********\", \"********\", \"+1111111\")\n\tvar message = gosms.MessageContent(\"Hello from Twilio\")\n\tnumber := gosms.CHNPhoneNumber(18888888888)\n\tresult, err := gosms.Sender(number, message, gateway)\n\tif resp, ok := result.ClientResult.Response.(twilio.Response); ok {\n\t\tfmt.Println(resp)\n\t}\n\tfmt.Println(err)\n}\n~~~\n\n## 加入我们\n\n如果你认可我们的开源项目，有兴趣为 go-sms的发展做贡献，竭诚欢迎加入我们一起开发完善。无论是[报告错误](https://github.com/pkg6/go-sms/issues)或是\n[Pull Request](https://github.com/pkg6/go-sms/pulls) 开发，那怕是修改一个错别字也是对我们莫大的帮助。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fgo-sms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkg6%2Fgo-sms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fgo-sms/lists"}