前言
前面实现了用户服务,现在我们集成一下阿里云的短信服务,因为用户在注册的时候是会发短信通知的。
一、开通阿里云短信服务

由于现在短信服务不支持'个人资质'的签名实名制报备,所以我们搞短信认证服务。
学习用可以小买 5 块的。
添加测试手机号,进行测试。文档给的很全。
二、集成到项目里
2.1 在 common 包下创建 common-message 包
2.2 添加 config 和 service 包
2.3 添加阿里云短信服务的配置在 config 里
AliSmsConfig:
package com.my.commonmessage.config;
import com.aliyun.dypnsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 阿里云短信服务配置参数
*/
@Configuration
@RefreshScope
public class AliSmsConfig {
/**
* accessKeyId
*/
@Value("${sms.aliyun.accessKeyId:}")
private String accessKeyId;
/**
* accessKeySecret
*/
@Value("${sms.aliyun.accessKeySecret:}")
private String accessKeySecret;
/**
* 服务器地址
*/
@Value("${sms.aliyun.endpoint:}")
private String endpoint;
/**
* 注册客户端
*
* @return 发送短信请求的客户端
* @throws Exception
*/
Client Exception {
com.aliyun.credentials. .aliyun.credentials.Client();
().setCredential(credential);
config.setEndpoint(endpoint);
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
(config);
}
}


