Files
markdown/blog/1.技术栈/986.Supabase 阿里云短信.md
2025-08-08 10:01:03 +08:00

80 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Supabase 阿里云短信
description: Supabase - 添加国内阿里云短信、微信扫码认证登录
date: 2025-07-15
img: https://lijue-me.oss-cn-chengdu.aliyuncs.com/20250701003525007.png
navigation:
icon: simple-icons:alibabacloud
---
###### 给 Supabase 添加一项新的功能
Supabase 自身的鉴权组件是社区开源项目 GoTrue ,由 GO 语言开发
Supabase 提供的短信验证都是国外的厂商,并不适应国内环境
##### 实现
单独把 Gotrue 仓库克隆下来,添加修改需要的功能
测试好后打包为 Docker推到私有库
修改 Supabase 的 Docker Compose 文件image 改为私有库镜像并拉取!
##### 并没有提交 PR直接放在仓库具体使用方法看仓库说明
###### [Github 仓库地址](https://github.com/estel-li/supabase_auth_aliyun_wechat)
---
### 🚀 新增功能
### 1. 阿里云短信服务 (Aliyun SMS)
- ✅ 完整的阿里云短信 API 集成
- ✅ 支持 HMAC-SHA1 签名验证
- ✅ 支持中文短信签名
- ✅ 支持 OTP 验证码发送
- ✅ 完整的错误处理和响应解析
### 2. 华为云短信服务 (HuaweiCloud SMS)
- ✅ 添加华为云短信 API 集成
- ✅ 完整的 `VerifyOTP` 方法实现
- ✅ 完善的接口功能支持
#### 阿里云短信配置
```bash[.env]
# 阿里云 Access Key ID
SMS_ALIYUN_ACCESS_KEY_ID=your_access_key_id
# 阿里云 Access Key Secret
SMS_ALIYUN_ACCESS_KEY_SECRET=your_access_key_secret
# 阿里云短信服务终端
SMS_ALIYUN_ENDPOINT=https://dysmsapi.aliyuncs.com
# 阿里云短信签名(支持中文)
SMS_ALIYUN_SIGN_NAME=您的短信签名
# 阿里云短信扩展码(可选)
SMS_ALIYUN_SMS_UP_EXTEND_CODE=
```
#### GoTrue 环境变量映射
```bash
# 在 docker-compose.yml 中映射到 GoTrue 容器
GOTRUE_SMS_ALIYUN_ACCESS_KEY_ID=${SMS_ALIYUN_ACCESS_KEY_ID}
GOTRUE_SMS_ALIYUN_ACCESS_KEY_SECRET=${SMS_ALIYUN_ACCESS_KEY_SECRET}
GOTRUE_SMS_ALIYUN_ENDPOINT=${SMS_ALIYUN_ENDPOINT}
GOTRUE_SMS_ALIYUN_SIGN_NAME=${SMS_ALIYUN_SIGN_NAME}
GOTRUE_SMS_ALIYUN_SMS_UP_EXTEND_CODE=${SMS_ALIYUN_SMS_UP_EXTEND_CODE}
```