生成签名
<p class="shortdesc"></p>
<p class="p"><strong class="ph b">使用范围</strong></p>
<p class="p">JS SDK、Android SDK、IOS SDK、Python SDK等自身未实现签名算法的SDK以及API方式接入。</p>
<p class="p"><strong class="ph b">依赖</strong></p>
<p class="p"><a class="xref" href="/ssr/help/storage/obs/OBS_SDK_.Java_SDK_" target="_blank">JAVA SDK下载</a></p>
<p class="p"><strong class="ph b">代码示例</strong></p>
<pre class="pre codeblock"><code>初始化service
RadosgwService radosgwService = RadosgwServiceFactory.getFromConfigObject(new ObsClientConfig() {
public String getUserAgent() {
return "系统英文名称";
}
public String getObsUrl() {
return "一般为OBS域名,只用于生成签名时可自定义填写";
}
public String getObsAccessKey() {
return "有访问权限的AK";
}
public String getObsSecret() {
return "有访问权限的SK";
}
public boolean isRepresentPathInKey() {
return false;
}
});</code></pre>
<pre class="pre codeblock"><code>Controller层
@PostMapping(value = "/getSign")
public String getMobileSign(@RequestBody @Validated SignatureParamBean bean) throws Exception {
AuthSignData signData = new AuthSignData();
signData.setRequestPath(bean.getUri());
signData.setRequestMethod(bean.getMethod());
signData.setContentType(bean.getContentType());
signData.getSignData().put("Date", StringUtils.isEmpty(bean.getDate()) ? bean.getExpires() : bean.getDate());
String signature = radosgwService.getSign(signData);
log.debug("sign params:{}", new Gson().toJson(bean));
return "AWS " + ak + ':' + signature;
}</code></pre>
<pre class="pre codeblock"><code>SignatureParamBean类
public class SignatureParamBean {
@NotBlank(message = "uri can not be blank")
private String uri;
private String contentType;
/**
* date和expires必填其一
*/
private String date;
private String expires;
@NotBlank(message = "method can not be blank")
private String method;
//TODO getter、setter方法
}
</code></pre>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!