微博图床Java API
这是个使用了微博图床接口的上传图片的api
首先添加一下仓库
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
再添加一下依赖
<dependency>
<groupId>com.github.echisan</groupId>
<artifactId>wbp4j</artifactId>
<version>0.0.1</version>
</dependency>
然后就ok啦
WbpLogin.login("username", "password");
ImageInfo imageInfo = new WbpUpload().upload("F:\\example.jpg");
WbpUpload wbpUpload = new WbpUploadBuilder().setDev(true).setAccount("username","password").build();
ImageInfo imageInfo = wbpUpload.upload("filename");
目前upload支持的参数 文件路径
, 文件对象
, 图片的Base64(需调用wbpUpload.uploadB64())
结果
ImageInfo{
pid='7fa15162gy1fsayytifkuj203903bglr',
width=117,
height=119,
size=7708,
large='https://wx4.sinaimg.cn/large/7fa15162gy1fsayytifkuj203903bglr.jpg',
middle='https://wx4.sinaimg.cn/mw690/7fa15162gy1fsayytifkuj203903bglr.jpg',
small='https://wx4.sinaimg.cn/thumbnail/7fa15162gy1fsayytifkuj203903bglr.jpg'
}
@Bean
public WbpUpload wbpUpload(){
return new WbpUploadBuilder().setDev(true)
.setAccount("username","password")
.build();
}
@RestController
public class HelloWbpController {
@Autowired
private WbpUpload wbpUpload;
@RequestMapping("/wbp")
public String helloWbp() throws IOException {
ImageInfo imageInfo = wbpUpload.upload("F:\\example.jpg");
return imageInfo.toString();
}
}