V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
spug
V2EX  ›  推广

个人开发者如何发送短信?这个方案太香了!

  •  
  •   spug · 44 天前 · 960 次点击
    这是一个创建于 44 天前的主题,其中的信息可能已经有所发展或是发生改变。

    还在为无法发送短信验证码而烦恼?今天分享一个超实用的解决方案,个人开发者也能用!

    最近国内很多平台暂停了针对个人用户的短信发送,这给个人开发者带来了不少困扰。不过别担心,我发现了一个超实用的解决方案——Spug 推送平台,它能很好地满足我们发送短信等需求。

    为什么选择这个方案?

    1. 无需企业认证:个人开发者直接可用
    2. 新用户福利:注册即送测试短信
    3. 价格实惠:0.05 元/条,按量计费
    4. 接口简单:几行代码就能搞定
    5. 支持丰富:短信、电话、微信、企业微信、飞书、钉钉、邮件等

    三步搞定短信发送

    第一步:注册账户

    打开push.spug.cc,使用微信扫码直接登录,无需繁琐的认证流程。

    第二步:创建模板

    1. 点击"消息模板" → "新建"
    2. 输入模版名称
    3. 选择推送通道
    4. 选择短信模板
    5. 选择推送对象
    6. 保存模板

    第三步:发送短信

    复制模版 ID ,通过 API 调用即可发送短信。

    发送短信验证码代码示例(多种语言)

    Python 版(推荐)

    import requests
    
    def send_sms(template_id, code, phone):
        url = f"https://push.spug.cc/send/{template_id}"
        params = {
            "code": code,
            "targets": phone
        }
        response = requests.get(url, params=params)
        return response.json()
    
    # 使用示例
    result = send_sms("abc", "6677", "151xxxx0875")
    print(result)
    

    Go 版

    package main
    
    import (
        "fmt"
        "net/http"
        "io/ioutil"
    )
    
    func sendSMS(templateID, code, phone string) (string, error) {
        url := fmt.Sprintf("https://push.spug.cc/send/%s?code=%s&targets=%s", 
            templateID, code, phone)
        
        resp, err := http.Get(url)
        if err != nil {
            return "", err
        }
        defer resp.Body.Close()
        
        body, err := ioutil.ReadAll(resp.Body)
        if err != nil {
            return "", err
        }
        
        return string(body), nil
    }
    
    func main() {
        result, err := sendSMS("abc", "6677", "151xxxx0875")
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
        fmt.Println(result)
    }
    

    Java 版

    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    public class SMSSender {
        public static String sendSMS(String templateId, String code, String phone) throws Exception {
            String url = String.format("https://push.spug.cc/send/%s?code=%s&targets=%s",
                templateId, code, phone);
            
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setRequestMethod("GET");
            
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();
            
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            
            return response.toString();
        }
    
        public static void main(String[] args) {
            try {
                String result = sendSMS("abc", "6677", "151xxxx0875");
                System.out.println(result);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    使用技巧

    1. 参数说明

      • code:验证码内容
      • targets:接收短信的手机号
      • 使用targets参数会覆盖模板配置的手机号
    2. 最佳实践

      • 选择合适的短信模版
      • 验证手机号格式
      • 管理验证码有效期
      • 添加错误处理
      • 确保账户余额充足
    Mandyer
        1
    Mandyer  
       44 天前
    0.05 元/条可算不上价格实惠
    934831065ldc
        2
    934831065ldc  
       44 天前
    不会被卡吗?
    934831065ldc
        3
    934831065ldc  
       44 天前
    我现在用阿里云的,报备了快一个月了,还没有成功? 你这不会?
    spug
        4
    spug  
    OP
       44 天前
    @934831065ldc 你来试一试,我们这目前报备挺快,成功率也挺高
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2711 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:04 · PVG 22:04 · LAX 07:04 · JFK 10:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.