ImageAsyncScanRequest使用时"msg":"[task.url] is not security" 求解答啊-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

ImageAsyncScanRequest使用时"msg":"[task.url] is not security" 求解答啊

2017-07-27 20:53:21 4873 1

/*

  • Licensed to the Apache Software Foundation (ASF) under one
  • or more contributor license agreements. See the NOTICE file
  • distributed with this work for additional information
  • regarding copyright ownership. The ASF licenses this file
  • to you under the Apache License, Version 2.0 (the
  • "License"); you may not use this file except in compliance
  • with the License. You may obtain a copy of the License at
    *
  • http://www.apache.org/licenses/LICENSE-2.0
    *
  • Unless required by applicable law or agreed to in writing,
  • software distributed under the License is distributed on an
  • "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  • KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations
  • under the License.
    */

package com.ssh.acm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20170112.ImageAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/**

  • Created by liuhai.lh on 2017/2/17.
  • 图片异步检测接口
  • @author liuhai.lh
  • @date 2017/02/17
    */

public class PicturetoWord {

public static void main(String[] args) throws Exception {
    //请替换成你自己的accessKeyId、accessKeySecret
    IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "LTAIzuajFMA4u8jD", "KCgSEAApd3jI9pC4xEGkq6mOh2YXc9");
    DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
    IAcsClient client = new DefaultAcsClient(profile);
    ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest();
    imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
    imageAsyncScanRequest.setContentType(FormatType.JSON);
    imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
    imageAsyncScanRequest.setEncoding("utf-8");
    imageAsyncScanRequest.setRegionId("cn-shanghai");
    List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
    Map<String, Object> task1 = new LinkedHashMap<String, Object>();
    task1.put("dataId", UUID.randomUUID().toString());
    task1.put("url", "https://localhost:8888/SSH/images/lixiang@163.com/111.jpg");
    task1.put("time", new Date());
    tasks.add(task1);
    JSONObject data = new JSONObject();
    /**
     * porn: 色情
     * terrorism: 暴恐
     * qrcode: 二维码
     * ad: 图片广告
     * ocr: 文字识别
     */
    data.put("scenes", Arrays.asList("ocr"));
    data.put("tasks", tasks);
    imageAsyncScanRequest.setContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
    /**
     * 请务必设置超时时间
     */
    imageAsyncScanRequest.setConnectTimeout(3000);
    imageAsyncScanRequest.setReadTimeout(6000);
    try {
        HttpResponse httpResponse = client.doAction(imageAsyncScanRequest);
        if(httpResponse.isSuccess()){
            JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getContent(), "UTF-8"));
            System.out.println(JSON.toJSONString(scrResponse, true));
            if (200 == scrResponse.getInteger("code")) {
                JSONArray taskResults = scrResponse.getJSONArray("data");
                for (Object taskResult : taskResults) {
                    if(200 == ((JSONObject)taskResult).getInteger("code")){
                        String taskId = ((JSONObject)taskResult).getString("taskId");
                        // 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest
                        System.out.println("args = [" + taskId + "]");
                    }else{
                        System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code"));
                    }
                }
            } else {
                System.out.println("detect not success. code:" + scrResponse.getInteger("code"));
            }
        }else{
            System.out.println("response not success. status:" + httpResponse.getStatus());
        }
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (ClientException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

取消 提交回答
全部回答(1)
  • khachapuri
    2020-03-18 00:10:05

    https://localhost:8888 这个地址是你本地的地址,如果是测试服务一般是 HTTP 协议,可以尝试将 https 改成http,或者换成图片实际的地址。

    0 0
相关问答

10

回答

【精品问答合集】Hbase热门问答

hbase小能手 2019-05-29 14:37:26 120862浏览量 回答数 10

145

回答

【新手入门】云服务器linux使用手册

fanyue88888 2012-11-26 17:14:18 157750浏览量 回答数 145

33

回答

Win Server 2003-2016 加密勒索事件必打补丁合集

妙正灰 2017-05-15 10:44:38 280435浏览量 回答数 33

38

回答

安全组详解,新手必看教程

我的中国 2017-11-30 15:23:46 259898浏览量 回答数 38

294

回答

Linux Bash严重漏洞修复紧急通知(已全部给出最终修复方案)

qilu 2014-09-25 13:26:50 434632浏览量 回答数 294

82

回答

OSS入门教程

belle.zhoux 2014-07-07 17:14:27 151516浏览量 回答数 82

249

回答

阿里云LNAMP(Linux + Nginx + Apache + MySQL + PHP)环境一键安装脚本

云代维 2014-02-14 15:26:06 305689浏览量 回答数 249

97

回答

Redhat/CentOS一键安装web环境全攻略

xiaofanqie 2011-08-11 14:51:38 123728浏览量 回答数 97

8

回答

mail.aliyun.com邮箱android手机客户端设置方法

jack_yang 2013-04-24 09:01:34 122593浏览量 回答数 8

13

回答

游戏云精彩帖汇总

nono20011908 2014-08-22 11:00:12 203994浏览量 回答数 13
+关注
0
文章
1
问答
问答排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载