wps栏目上的运服务怎么没有了
621
2022-05-30
1.导入依赖包:
二、编写java工具类
package com.walkby.utils; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.IClientProfile; import com.walkby.config.SMSConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; /** * @author * 发送短信工具类 */ @Component @Slf4j public class SendSms { //产品名称:云通信短信API产品,开发者无需替换 static final String product = "Dysmsapi"; //产品域名,开发者无需替换 static final String domain = "dysmsapi.aliyuncs.com"; /** * 短信验证 * @param phone 手机号 * @param code 验证码 * @param templateCode 短信模版 * @return * @throws ClientException */ public static SendSmsResponse sendSms(String phone, String code,String templateCode) throws ClientException { //可自助调整超时时间 System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); //初始化acsClient,暂不支持region化 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", SMSConfig.KEY_ID,SMSConfig.KEY); DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); IAcsClient acsClient = new DefaultAcsClient(profile); //组装请求对象-具体描述见控制台-文档部分内容 SendSmsRequest request = new SendSmsRequest(); request.setMethod(MethodType.POST); request.setPhoneNumbers(phone); request.setSignName(SMSConfig.SIGN_NAME); request.setTemplateCode(templateCode); request.setTemplateParam("{\"code\":\"" + code + "\"}"); //选填-上行短信扩展码(无特殊需求用户请忽略此字段) //request.setSmsUpExtendCode("90997"); //hint 此处可能会抛出异常,注意catch SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); // log.info("发送短信状态:{}", sendSmsResponse.getCode()); log.info("发送短信消息:{}", sendSmsResponse.getMessage()); return sendSmsResponse; } }
Java
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。