All Projects → echisan → wbp4j

echisan / wbp4j

Licence: other
Simple Java Api for 微博图床,使用简单的api即可完成上传图片

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to wbp4j

BenGorCookies
Cookie warning banner that requests user consent, European law compilant. Zero dependencies, fully customizable JavaScript library for IE9+
Stars: ✭ 12 (-75%)
Mutual labels:  cookie
phaser-super-storage
A cross platform storage plugin for Phaser
Stars: ✭ 49 (+2.08%)
Mutual labels:  cookie
cookiet
A small, simple JavaScript cookies library.
Stars: ✭ 13 (-72.92%)
Mutual labels:  cookie
http
Basic HTTP primitives which can be shared by servers and clients.
Stars: ✭ 75 (+56.25%)
Mutual labels:  cookie
cookies
Manage your cookies on client and server side (Angular Universal)
Stars: ✭ 40 (-16.67%)
Mutual labels:  cookie
concorde.js
A sexy pinnacle of engineering that’s nonetheless incredibly inefficient and expensive and goes out of business because it can’t find enough use. It also provides some tools to deal with the browser.
Stars: ✭ 17 (-64.58%)
Mutual labels:  cookie
burp-cookie-porter
一个可快速“搬运”cookie的Burp Suite插件
Stars: ✭ 22 (-54.17%)
Mutual labels:  cookie
compare-utils
Compares of Java Collections and Objects (of different classes) made easy
Stars: ✭ 15 (-68.75%)
Mutual labels:  java-api
beautifulscraper
Python web-scraping library that wraps urllib2 and BeautifulSoup
Stars: ✭ 40 (-16.67%)
Mutual labels:  cookie
wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-70.83%)
Mutual labels:  cookie
elm-storage
Unified interface for accessing and modifying LocalStorage, SessionStorage and Cookies
Stars: ✭ 13 (-72.92%)
Mutual labels:  cookie
macaroons-rs
Macaroons: bearer credentials with caveats for distributed authorization
Stars: ✭ 62 (+29.17%)
Mutual labels:  cookie
ImageOnMap
Repo for ImageOnMap, a bukkit plugin created to display any image using a map
Stars: ✭ 162 (+237.5%)
Mutual labels:  picture
cookies
Convenient way to use cookies with PSR-7
Stars: ✭ 17 (-64.58%)
Mutual labels:  cookie
Password Generator
🔄 Simple password generator class library in C# 6.0, use for generate your own password! 📗
Stars: ✭ 21 (-56.25%)
Mutual labels:  picture
backcookie
Small backdoor using cookie.
Stars: ✭ 49 (+2.08%)
Mutual labels:  cookie
runx
Provide X server on MS Windows with cookie authentication.
Stars: ✭ 67 (+39.58%)
Mutual labels:  cookie
weiboUploader-Watermark
新浪微博图床批量传图工具 上传-缩放-水印-生成链接一键搞定
Stars: ✭ 41 (-14.58%)
Mutual labels:  picture
PolishCookieConsent
Polish Cookie Consent is an extension, which automatically accepts privacy policy/GDPR on websites.
Stars: ✭ 17 (-64.58%)
Mutual labels:  cookie
LocalVideoImage-selector
A simple-used local video and image selector for Android, also support single-selection and multi-selection.
Stars: ✭ 25 (-47.92%)
Mutual labels:  picture

wbp4j

weibo picture api for java (中二一下)

使用Java实现的微博图床API,提供简单的api即可完成上传图片到微博图床,可方便集成到自己的项目当中。

如果有兴趣或奇怪的需求或者想看故事可以查看说明文档
如果出现任何问题欢迎提issue、欢迎提pr
如果这个项目帮助到你了欢迎star鼓励一下^^

特色

  • 使用方便简单
  • 获取简单,直接加入maven依赖即可
  • cookie缓存
  • cookie过期自动登录
  • 第三方依赖少,仅依赖fastjson,logback
  • 自由度高,一切均可自定义配置
  • 仍在维护

Maven

引入maven依赖即可

<dependency>
  <groupId>com.github.echisan</groupId>
  <artifactId>wbp4j</artifactId>
  <version>3.3</version>
</dependency>

用法

使用默认配置

这个方式只做演示,请不要每次调用上传接口都使用UploadRequestBuilder build一次 build()方法会初始化所有的CookieContext WbpHttpRequest LoginRequest Interceptor列表等等,但是这些东西只需初始化一次,之后便是对cookie的管理。

UploadRequest uploadRequest = UploadRequestBuilder.buildDefault("your username", "your password");
UploadResponse response = uploadRequest.upload(new File("go.png"));

建议写成单例,在有需要的时候拿到UploadRequest对象调用upload方法即可

public enum  UploadUtils {
    INSTANCE;

    private UploadRequest uploadRequest;

    UploadUtils() {
        uploadRequest = UploadRequestBuilder.buildDefault("yourUsername","yourPassword");
    }

    public UploadResponse upload(File file) throws IOException, UploadFailedException {
        return uploadRequest.upload(file);
    }
    
    public UploadRequest getUploadRequest(){
        return this.uploadRequest;
    }
}

自定义配置

支持自定义拦截器,具体查看文档

UploadRequest uploadRequest = UploadRequestBuilder.custom("your username", "your password")
                .setCacheFilename("myCache")
                .addInterceptor(new UploadInterceptor() {
                    @Override
                    public boolean processBefore(UploadAttributes uploadAttributes) {
                        System.out.println("hello world");
                        return true;
                    }
                    @Override
                    public void processAfter(UploadResponse uploadResponse) {
                    }
                }).build();

UploadResponse uploadResponse = uploadRequest.upload(new File(""));

返回结果

{
    "message": "上传图片成功",
    "imageInfo": {
        "pid": "7fa15162gy1g1e5o2vlmwj20dn07e0t7",
        "width": 491,
        "height": 266,
        "size": 27707,
        "large": "https://ws3.sinaimg.cn/large/7fa15162gy1g1e5o2vlmwj20dn07e0t7.jpg",
        "middle": "https://ws3.sinaimg.cn/mw690/7fa15162gy1g1e5o2vlmwj20dn07e0t7.jpg",
        "small": "https://ws3.sinaimg.cn/small/7fa15162gy1g1e5o2vlmwj20dn07e0t7.jpg"
    },
    "result": "SUCCESS"
}

使用

Spring中使用

@SpringBootApplication
public class DemoApplication {
    @Bean
    public UploadRequest uploadRequest() {
        return UploadRequestBuilder.buildDefault("your username", "your password");
    }
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

@RestController
@RequestMapping("/wbp4j")
class TestController {

    @Autowired
    private UploadRequest uploadRequest;

    @PostMapping
    public WbpUploadResponse uploadImage(@RequestPart("file") MultipartFile multipartFile) throws IOException, UploadFailedException {
        UploadResponse upload = uploadRequest.upload(multipartFile.getBytes());
        // 推荐先做一个判断
        // if (response.getResult().equals(UploadResponse.ResultStatus.SUCCESS)) {
        //    做自己的响应封装
        //}
        return (WbpUploadResponse) upload;
    }

}

注意:UploadRequest是一个线程安全的类,可直接注入到你想使用的类中去,不要每次调用上传api时都去调用UploadRequestBuilder.build()是没有任何意义的

更新日志

2019.04.23

修复了修改缓存文件名不生效的问题 .
增加了登陆失败返回的信息以及对unicode的解码 .

2019.03.30

优化了重试代码 .
修复了重试机制还是不生效的问题 .

2019.03.25

修复了重试机制不生效的问题 .

2019.03.24

修复了部署到服务器后无法登陆的问题 .
修复了返回的图片格式问题 .

2019.03.23

重构代码,代码结构更清晰稳定,减低各模块的耦合 .
修复缓存文件位置错误的问题 .
修复上传图片格式问题 .
支持了上传gif .

2018.11.08

重构了代码,减少第三方依赖,目前只依赖logging,fastjson .
将包上传至官方仓库使用更方便 .

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].