腾讯云 发送短信 (单模板发送)

腾讯云接口地址(内含 sdk,文档说明)

https://cloud.tencent.com/document/product/382/136

/*
     * AppID:1123423414
     * AppKey:cf21sdfqwe23423473291a873 
     * 公司签名ID:22362
     * 短信模板ID:54231
     * 短信模板内容:{1}为您的登录验证码,请于{2}分钟内填写。如非本人操作,请忽略本短信。
     */
    
    private static final int AppID = 1123423414;
    private static final String AppKey = "cf21sdfqwe23423473291a873 ";
    private static final String smsSign = "22362";
    private static final int templateId  = 54231;
    

 具体代码编写如下
    /**
     * 发送短信验证码
     * @param phone 手机号
     * @return 验证码
     */
    public static SmsSingleSenderResult send(String mobile,String verifyCode) {
        //第一个参数,验证码,第二个参数15分钟
        String[] params = {verifyCode,"15"};
        //调用腾讯云sdk,发送短信
        SmsSingleSender ssender = new SmsSingleSender(AppID , AppKey );
        SmsSingleSenderResult result = null;
        try {
            result = ssender.sendWithParam("86", mobile,SMSConfig.templateId, params, "", "", "");
        } catch (HTTPException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        return result;
    }

猜你喜欢

转载自blog.csdn.net/XX_13590469771/article/details/87875678
今日推荐