针对阿里云的产品进行的spring boot starter的封装,目前只封装了afs(人机验证,captcha)、sms(短信验证)、oss(对象存储)、sts(访问控制)四个模块,后续有需求我会进一步的添加,对于我来说sms与oss两个模块目前用的最多。所以这块也做了一些封装
当前工程版本:0.4.1
mvn intall
后,引入其依赖:
<dependency>
<groupId>com.kuding</groupId>
<artifactId>vinus-spring-boot-starter</artifactId>
<version>0.4.1</version>
</dependency>
在appplication.properties
或application.yml
文件中进行相关配置
加入captcha人机验证模块,则需要做如下配置:
vinus.enable-aliyun-captcha=true
aliyun.captcha.access-key-id=你自己的accessId
aliyun.captcha.secret=你自己的access-secret
aliyun.captcha.region-id=cn-hangzhou
aliyun.captcha.app-key=你自己的appKey
aliyun.captcha.sene=登录验证方式方式
vinus.enable-aliyun-sms=true
aliyun.sms.access-key-id=你自己的accessId
aliyun.sms.secret=你自己的access-secret
aliyun.sms.region-id=cn-hangzhou
vinus.enable-aliyun-oss=true
aliyun.oss.access-key-id=你自己的accessId
aliyun.oss.secret=你自己的access-secret
aliyun.oss.default-bucket=my-bucket
aliyun.oss.policy-timeout=30m
aliyun.oss.end-point=oss-cn-xxx.aliyuncs.com
对于应用也非常的简单,核心的类为XxxComonent。阿里云的afs(captcha)的核心类为AliCaptchaComponent、阿里云sms的核心类为SmsComponent、阿里云oss的核心类为OssComponent、阿里云Sts核心类为StsComponent;
对于captcha(afs)组件,核心方法为public boolean check(HttpServletRequest httpServletRequest, CaptchaContent capcha)
方法,通过httpservletrequest来进行处理请求的相关信息,CaptchaContent是用于验证的一些关键参数,目前只支持pcweb端的验证。对于人机验证的相关的文档请参看:https://help.aliyun.com/product/28308.html
对于sms组件,核心的方法为public void doSendSms(String phone, String smsSignature, String templateCode, Map<String, String> map)
方法,参数依次为:手机号、短信签名、短信模板code、和参数(map结构);对于短信签名一般都是固定的,对于templateCode的管理建议可以通过enum的方式进行管理
public enum SmsTemplate {
MODIFY_PWD("SMS_120270002"), CREATE_USER("SMS_172223677"), RESET_PWD("SMS_162524221"), INIT_SAAS("SMS_162546827");;
private final String template;
public String getTemplate() {
return template;
}
private SmsTemplate(String template) {
this.template = template;
}
}
OssPolicy
,用法也很简单: @PostMapping("/createExplainPicPolicy")
@ApiOperation("创建一个说明图片上传的临时策略")
public ResultModel<OssPolicy> createExplainPicPolicy() {
OssPolicy ossPolicy = ossComponent.createOssPolicy("文件目录", "my-bucket");
return ResponseStatusEnum.SUCCESS.createResultModel(ossPolicy);
}
第一个参数表示是哪个文件目录,第二个参数表示是哪个bucket
/**
* 将一个字符串上传到oss
*
* @param object
* @param contentType
* @param path
* @return
*/
public String putStringToOss(String object, ContentType contentType, String path)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。