StarRocks VARIANT 类型实战指南:在 Iceberg 与 Paimon 数据湖上查询半结构化数据
2026/9/17 9:31:14
大家好,我是小悟。
华为云消息&短信服务(MSG&SMS)为企业提供了稳定、合规的全球短信发送能力。它主要有以下特点:
以下是使用华为云官方Java SDK进行集成的详细步骤。
第一步:开通服务与前期准备
第二步:控制台配置(关键步骤)
这是发送短信的前提,所有配置均需审核。
app_id和app_key。第三步:SpringBoot项目集成与代码实现
添加Maven依赖
在pom.xml中添加官方SDK依赖。
<dependency> <groupId>com.huaweicloud.sdk</groupId> <artifactId>huaweicloud-sdk-smsapi</artifactId> <!-- 请前往华为云官网SDK中心查询并使用最新版本 --> <version>{latest-version}</version> </dependency>配置AK/SK和应用信息
在application.yml中配置你的密钥和应用信息。
huaweicloud: sms: ak: your-access-key # 替换为你的AK sk: your-secret-key # 替换为你的SK project-id: your-project-id # 在“我的凭证-项目列表”中查找 sender: 10690xxxxxxxx # 通道号,在创建的应用详情中查看 signature: 华为云测试 # 已审核通过的签名名称 template-id: xxxxxxxx # 已审核通过的模板ID region: cn-north-4 # 短信服务区域,如华北-北京四创建配置类读取属性
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import lombok.Data; @Component @ConfigurationProperties(prefix = "huaweicloud.sms") @Data public class SmsConfig { private String ak; private String sk; private String projectId; private String sender; private String signature; private String templateId; private String region; }编写短信发送服务类
这是最核心的业务类,用于组装和发送请求。
import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.sms.v2.SmsClient; import com.huaweicloud.sdk.sms.v2.model.*; import com.huaweicloud.sdk.sms.v2.region.SmsRegion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.List; @Service public class HuaweiSmsService { @Autowired private SmsConfig smsConfig; public Boolean sendSingleMessage(String mobile, List<String> templateParams) { // 1. 构建认证信息 BasicCredentials auth = new BasicCredentials() .withAk(smsConfig.getAk()) .withSk(smsConfig.getSk()) .withProjectId(smsConfig.getProjectId()); // 2. 初始化客户端 (注意Region枚举可能随SDK版本变化) SmsClient client = SmsClient.newBuilder() .withCredential(auth) .withRegion(SmsRegion.valueOf(smsConfig.getRegion().toUpperCase().replace("-", "_"))) .build(); // 3. 构造发送请求 SendSmsRequest request = new SendSmsRequest() .withFrom(smsConfig.getSender()) // 发送号码(通道号) .withTo(Arrays.asList(mobile)) // 接收方号码列表 .withTemplateId(smsConfig.getTemplateId()) // 模板ID .withTemplateParas(templateParams) // 模板变量值列表 .withSignature(smsConfig.getSignature()); // 签名名称 // 4. 发送请求并处理响应 try { SendSmsResponse response = client.sendSms(request); // 根据SDK版本,成功判断可能是 response.getHttpStatusCode() == 200 或解析body中的code System.out.println("Request ID: " + response.getRequestId()); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }在Controller或业务层调用
@RestController @RequestMapping("/api/sms") public class SmsController { @Autowired private HuaweiSmsService smsService; @PostMapping("/send-verification") public String sendVerificationCode(@RequestParam String phone) { // 生成随机验证码 String code = String.valueOf((int)((Math.random() * 9 + 1) * 100000)); // 组装模板参数,顺序需与模板中变量定义一致 List<String> params = Arrays.asList(code, "5"); boolean isSuccess = smsService.sendSingleMessage(phone, params); if(isSuccess) { return "短信发送成功,验证码:" + code; // 生产环境不应返回验证码 } else { return "短信发送失败"; } } }将以上步骤串联起来,整个接入流程和注意事项如下:
总结与核心建议
E200028表示模板变量错误)或状态回执错误码。根据这些代码在官方文档中排查,是最高效的调试方法。谢谢你看我的文章,既然看到这里了,如果觉得不错,随手点个赞、转发、在看三连吧,感谢感谢。那我们,下次再见。
您的一键三连,是我更新的最大动力,谢谢
山水有相逢,来日皆可期,谢谢阅读,我们再会
我手中的金箍棒,上能通天,下能探海