Yellow is something we can’t tolerate but can’t guard against, especially for tools and platforms to do content, so I spent 30 minutes to build a yellow platform to share with you.

Data preparation

Find N more resources can not solve the problem, so angry climb a Bub data, ready to verify the yellow authentication effect.

Account for

This article uses UAI-Censor provided by UCloud. Currently, uAI-Censor supports pictures, and violent terrorism and political involvement will be online successively. He offers 2,000 free calls per day, so that’s enough for both testing and niche tools.

1. Use the following link to register an account

urlify.cn/UNjURr

2. Create the UAI-Censor app

It is used when the application ID is obtained for authentication API call. After successful registration, enter the console, search for UAI, and click AI Content Audit

image

Click Create App, enter a custom app name, and click OK

image

Click OK to display a successful popup with your app ID highlighted for later use

image

3. Obtain the public key and private key and apply the ID

Student: Yes, but can’t everybody do it? All you need to do is register a public and private key so that only you can use it. Click on the following link https://console.ucloud.cn/uapi/apikey click show that can view public key private key

image

This is where everything is just right

4. The coding

We can call the API by hand and see what comes back before we code itAs you can see, after entering the public key, private key, and application ID, clicking verify returns a bunch of JSON. So the above test was passed. Wait, you don’t believe that? This is when the resources of a Hub come in handy.

So forbid, so I code it, but see forbid

image

UaicensorPublicKey and uaicensorPrivateKey are your own, so I won’t show them here, because I’m using SpringBoot, and RestTemplate is very simple to use.

 / * *

     * @param imageUrl

     * @returnA) pass B) pass C) forbid D) check

     * @throws Exception

* /


    public String check(String imageUrl) {

        String ucloudUrl = "http://api.uai.ucloud.cn/v1/image/scan";

        String appId = "uaicensor-rjmvogpx";

        String uaicensorPublicKey = null;

        String uaicensorPrivateKey = null;

        

        // Image absolute path

        RestTemplate rest = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();

        / * *

* Generate signature in alphabetical order

* /


        String timestamp = System.currentTimeMillis() + "";

        SortedMap<Object, Object> packageParams = new TreeMap<>();

        packageParams.put("PublicKey", uaicensorPublicKey);

        packageParams.put("ResourceId", appId);

        packageParams.put("Timestamp", timestamp);

        packageParams.put("Url", imageUrl);

        String signature = null;

        try {

            signature = UCloudUtil.createSign(packageParams, uaicensorPrivateKey);

        } catch (Exception e) {

            return null;

        }

        / * *

* parameters

* /


        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();

        param.add("Scenes"."porn");

        param.add("Method"."url");

        param.add("Url", imageUrl);

        / * *

* headers parameters

* /


        headers.setContentType(MediaType.parseMediaType("multipart/form-data; charset=UTF-8"));

        headers.set("PublicKey", uaicensorPublicKey);

        headers.set("Signature", signature);

        headers.set("ResourceId", appId);

        headers.set("Timestamp", timestamp);

        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(param, headers);

        ResponseEntity<String> responseEntity = rest.exchange(ucloudUrl, HttpMethod.POST, httpEntity, String.class);

        String body = responseEntity.getBody();

        JSONObject jsonObject = JSON.parseObject(body);

        if (jsonObject.getInteger("RetCode") = =0) {

            String res = jsonObject.getJSONObject("Result").getJSONObject("Porn").getString("Suggestion");

            return res;

        }

        return null;

    }

Copy the code

Is it very simple? So begin your journey of discovery?