api图片鉴黄

api图片鉴黄1.账号准备本文使用的是UCloud提供的UAI-Censor,目前他支持图片,暴恐、涉政会陆续上线。他提供了每日2000张免费调用额度,所以无论对于测试还是小众的工具足够了。1、使用如下链接注册账号https://urlify.cn/Bj2Y3y2、创建UAI-Censor应用3、获取公钥、私钥,应用IDhttps://console.ucloud.cn/uapi/apikey4、编码importcom.alibaba.fastjson.JSON;impor

1.账号准备

本文使用的是 UCloud 提供的 UAI-Censor,目前他支持图片,暴恐、涉政会陆续上线。他提供了每日2000张免费调用额度,所以无论对于测试还是小众的工具足够了。

1、使用如下链接注册账号

https://urlify.cn/Bj2Y3y

2、创建 UAI-Censor 应用

3、获取公钥、私钥,应用ID

https://console.ucloud.cn/uapi/apikey

4、编码

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.irobot.util.SignUtil;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.SortedMap;
import java.util.TreeMap;

@Service
public class CheckService {
    /**
     * @param publicKey
     * @param privateKey
     * @param imageUrl
     * @return pass-放行, forbid-封禁, check-人工审核
     * @throws Exception
     */
    public  String check(String publicKey, String privateKey, String imageUrl) {
        String ucloudUrl = "http://api.uai.ucloud.cn/v1/image/scan";
        String appId = "uaicensor-dxqfbffg";

        //图片绝对路径
        RestTemplate rest = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        /**
         * 生成signature,首字母排序
         */
        String timestamp = System.currentTimeMillis() + "";
        SortedMap<Object, Object> packageParams = new TreeMap<>();
        packageParams.put("PublicKey", publicKey);
        packageParams.put("ResourceId", appId);
        packageParams.put("Timestamp", timestamp);
        packageParams.put("Url", imageUrl);
        String signature;
        try {
            signature = SignUtil.createSign(packageParams, privateKey);
        } catch (Exception e) {
            return null;
        }
        /**
         * 参数
         */
        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
        param.add("Scenes", "porn");
        param.add("Method", "url");
        param.add("Url", imageUrl);
        /**
         * headers 参数
         */
        headers.setContentType(MediaType.parseMediaType("multipart/form-data; charset=UTF-8"));
        headers.set("PublicKey", publicKey);
        headers.set("Signature", signature);
        headers.set("ResourceId", appId);
        headers.set("Timestamp", timestamp);
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(param, headers);
        System.out.println(httpEntity.toString());
        ResponseEntity<String> responseEntity = rest.exchange(ucloudUrl, HttpMethod.POST, httpEntity, String.class);
        String body = responseEntity.getBody();
        System.out.println(body);
        JSONObject jsonObject = JSON.parseObject(body);
        if (jsonObject.getInteger("RetCode") == 0) {
            return jsonObject.getJSONObject("Result").getJSONObject("Porn").getString("Suggestion");
        }
        return null;
    }

}
<repositories>
        <repository>
            <id>developer-weapons-repository</id>
            <url>https://raw.githubusercontent.com/developer-weapons/repository/master</url>
        </repository>
    </repositories>

代码地址:https://mp.weixin.qq.com/s/YazEJYzVr8Tuly8123pnvg

https://mp.weixin.qq.com/s/5WWzvfbWy2L_bupKg1XZ2Q

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/37976.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注