您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页腾讯云SDK发送短信

腾讯云SDK发送短信

来源:化拓教育网

腾讯云接口发送短信

(1)创建签名

(2)创建模板

(3)确认套餐包

发送的额度

(4)创建应用

查看应用设置:调用腾讯云接口时需要验证APPID。APPKEY是密码。

(5)引入sdk(软件开发工具包)

<dependency>
    <groupId>com.github.qcloudsms</groupId>
    <artifactId>qcloudsms</artifactId>
    <version>1.0.6</version>
</dependency>

(6)创建实体类

/**
 * 需要参数、收短信的手机号
 */
@Data
public class Sms {
    String phonenum;
    String xxx;
}

(7)发送短信

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.qcby.xmdemo.model.Sms;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sms")
public class SmsController {
    /**
     * appID appkey申请的应用相关信息
     * templeID模板id sigin签名
     * @param sms
     */
    @PostMapping("/send")
    public void sms(@RequestBody Sms sms){
        int appID=1400928529;
        String appkey="";
        int templeID=45662222;
        String sigin="";
        try {
            //获取定义的短信参数
            String[] param={sms.getPhonenum(),sms.getXxx()};
            SmsSingleSender smsSingleSender=new SmsSingleSender(appID,appkey);
            SmsSingleSenderResult result=smsSingleSender.sendWithParam("86",sms.getPhonenum(),templeID,param,
                    sigin,"","");
            //参数:中国区号,手机号,模板id,参数列表,签名
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务