七牛三方图片鉴黄

项目需要做图片鉴黄,而且目前图片没有存放在七牛,所以选择了调用七牛三方的接口
阿塔科技图片鉴黄服务,文档地址,选择方式二
https://developer.qiniu.com/dora/manual/1295/image-as-a-yellow-services-stage#pulp2-title
文档写的比较差,走了不少弯路.

开通需要先发工单请求开通
下面上干货

maven 配置

<dependencies>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.3.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.qiniu</groupId>
            <artifactId>happy-dns-java</artifactId>
            <version>0.1.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.qiniu</groupId>
            <artifactId>qiniu-java-sdk</artifactId>
            <version>7.2.0</version>
        </dependency>

    </dependencies>

java核心代码

因为涉及到 qiniu/mac qbox/mac 鉴权,需要自己再组织一下原有sdk 的方法


import com.qiniu.http.Client;
import com.qiniu.http.Response;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.StringUtils;


        String accessKey = "---ak---";
        String secretKey = "---sk---";
        Auth auth = Auth.create(accessKey, secretKey);
        Client client = new Client();
        String url = "http://pulp.ataraxia.ai/pulp";
        #官方文档图片参数写的很恶心~~~顺便鄙视一下
        String body = "image=替换成图片1url&&image=替换成图片2url";
        byte[] bodyByte = StringUtils.utf8Bytes(body);
        String mimeType = "application/x-www-form-urlencoded";
        StringMap headers = auth.authorization(url, bodyByte, mimeType);

        headers.put("Content-Type", mimeType);
        try {
            Response rep = client.post(url, bodyByte, headers, mimeType);
            System.out.println(rep.bodyString());

        } catch (Exception e) {
            e.printStackTrace();
        }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 技术演化的方向是什么?第一,生产的成本越来越低;第二,做事的效率越来越高 一 【让程序员头痛的问题】 1 . 海量...
    XiWeidong阅读 19,492评论 2 53
  • 一、总目录 1,资源主页 资源主页:用于添加七牛各个产品模块,包含有:对象存储、自定义数据处理V2、多媒体处理、融...
    森林死了一只熊阅读 6,859评论 0 4
  • 参考-吕昌博客我们可以直接进入官网的php手册我发现看composer里面的qiniu/qiniu组建是没有用的 ...
    云龙789阅读 11,368评论 0 2
  • qiniu-imgup简介 qiniu-imgup是一个七牛云图片上传工具,目标是简化MarkDown写作中的贴图...
    bluexiii阅读 6,143评论 0 5
  • 午餐时,和好丽友们噼里啪啦地说着老师处事如何不厚道,我们的某才华横溢的姐们如何被不公对待,自以为是公平与正义的化身...
    Ruby阅读 3,449评论 0 2