吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1395|回复: 1
收起左侧

[Java 转载] 各位大兄弟,小弟自己写的对接X讯短信服务,有需要的直接可用

[复制链接]
优秀的自恋狂 发表于 2020-7-23 10:26
[Java] 纯文本查看 复制代码
package example.service;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import example.Systems.Contros;
import org.springframework.stereotype.Service;

@Service
public class IndexService {

    private static String code;

    public String upDuanXin(String number){
        // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
        Credential cred = new Credential(Contros.secretId,Contros.secretKey);
        // 实例化要请求产品(以cvm为例)的client对象
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setSignMethod(ClientProfile.SIGN_TC3_256);
        SmsClient smsClient = new SmsClient(cred, "ap-chongqing");
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        //appId
        sendSmsRequest.setSmsSdkAppid(Contros.appId);
        //发送短信的目标手机号,可填多个。
        String[] phones={"+86"+number+""};
        sendSmsRequest.setPhoneNumberSet(phones);
        //模版id
        sendSmsRequest.setTemplateID(Contros.templateId);
        //生成随机6位数验证码
        code = vcode();
        System.out.println("验证码:"+code);
        //模版参数,从前往后对应的是模版的{1}、{2}等
        String [] templateParam={code};
        sendSmsRequest.setTemplateParamSet(templateParam);
        //签名内容
        sendSmsRequest.setSign(Contros.Signed);
        try {
            SendSmsResponse sendSmsResponse= smsClient.SendSms(sendSmsRequest); //发送短信
            System.out.println("字符窜为:"+SendSmsResponse.toJsonString(sendSmsResponse));
            return SendSmsResponse.toJsonString(sendSmsResponse);
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 生成6位随机数验证码
     * @return
     */
    public static String vcode(){
        String vcode = "";
        for (int i = 0; i < 6; i++) {
            vcode = vcode + (int)(Math.random() * 9);
        }
        return vcode;
    }

}
[Java] 纯文本查看 复制代码
public class Contros {

    //secretId
    public static final String secretId = ""填写自己的";

    //secretKey
    public static final String secretKey = "填写自己的";

    //appId
    public static final String appId = ""填写自己的";

    //模板ID
    public static final String templateId = ""填写自己的";

    //签名内容
    public static final String Signed = "填写自己的";

}

免费评分

参与人数 2吾爱币 +4 热心值 +2 收起 理由
clown_z + 1 + 1 谢谢@Thanks!
wushaominkk + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

正义钢炮 发表于 2020-7-23 13:42
似乎失效了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-3 18:42

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表