{"id":22433652,"url":"https://github.com/gavinning/sms","last_synced_at":"2025-08-23T19:20:48.051Z","repository":{"id":57093691,"uuid":"403021488","full_name":"gavinning/sms","owner":"gavinning","description":"短信验证码，支持阿里云和腾讯云","archived":false,"fork":false,"pushed_at":"2021-09-08T09:32:30.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-11T07:27:08.625Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavinning.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-04T09:57:00.000Z","updated_at":"2022-08-15T11:52:47.000Z","dependencies_parsed_at":"2022-08-22T21:40:14.958Z","dependency_job_id":null,"html_url":"https://github.com/gavinning/sms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gavinning/sms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fsms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fsms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fsms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fsms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/sms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fsms/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271766307,"owners_count":24817540,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12-05T22:15:34.279Z","updated_at":"2025-08-23T19:20:48.004Z","avatar_url":"https://github.com/gavinning.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"SMS短信验证码\n---\n* 阿里云短信验证码发送和验证\n* 腾讯云短信验证码发送和验证\n\n### Install\n```sh\nnpm i @4a/sms\n# or\nyarn add @4a/sms\n```\n\n### Options\n```ts\ninterface Options {\n    mode: Mode\n    redis: Redis // ioredis\n    debug?: boolean\n    qqconfig?: QcloudConfig\n    aliconfig?: AliyunConfig\n}\n\nenum Mode {\n    aliyun = 'aliyun',\n    qcloud = 'qcloud',\n}\n\ninterface QcloudConfig {\n    AppId: string\n    accessKeyId: string\n    accessKeySecret: string\n    SignName: string\n    TemplateId: string\n    RegionId?: string // default = ap-guangzhou\n}\n\ninterface AliyunConfig {\n    accessKeyId: string\n    accessKeySecret: string\n    SignName: string\n    TemplateId: string\n    RegionId?: string // default = cn-hangzhou\n}\n\n```\n\n### Usage\n短信验证码会被存储在redis中\n* 默认有效期：6分钟\n* 默认存储Key：``app:sms:passcode:${tel}``\n```ts\nimport SMS from '@4a/sms'\n```\n```js\nconst { SMS } = require('@4a/sms')\nconst { aliyunConfig, qcloudConfig } = require('./config')\nconst Redis = require('ioredis')\nconst redis = new Redis()\n\nconst client = new SMS({\n    mode: 'aliyun',\n    redis,\n    debug: true,\n    qqconfig: qcloudConfig,\n    aliconfig: aliyunConfig,\n})\n\n// 创建一个短信验证码\n// 模拟发送，可在测试环境使用该api\nclient.create(tel)\n\n// 创建一个短信验证码\n// 真实发送，生产环境使用该api\nclient.send(tel)\n\n\n// 验证短信验证码是否合法\nclient.verify(tel, code)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fsms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fsms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fsms/lists"}