(记录)万象优图图片分析


import java.io.BufferedReader;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import com.qcloud.image.sign.Credentials;
import com.qcloud.image.sign.Sign;

public class IsCard {
static int appId = ********;//      YOUR_APPID
static String secretId = "********";      
static String secretKey = "********";
static String bucketName = "********";
public static void main(String[] args) {
doJsonPost();




}
  public static String doJsonPost() {
       String result = "";
       BufferedReader reader = null;
       String respContent = null;
       String urlimg = "********";      //图片地址
       Credentials cred = new Credentials(appId, secretId, secretKey);
       try {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost("http://recognition.image.myqcloud.com/ocr/general"); 
        String sign = Sign.appSign(cred,"**",300);//签名
        post.addHeader("Authorization",sign);
        String json1 = "{\"app_id\":\""+appId+"\",\"bucket\":\""+bucketName+"\",\"url\":\""+urlimg+"\"}";   //参数格式要正确
         StringEntity entity = new StringEntity(json1.toString(),"utf-8");
         entity.setContentType("application/json;charset=UTF-8");
         post.setEntity(entity);
         System.out.println(json1.toString());
         String Json = json1.toString();
           if (Json != null) {
               byte[] writebytes = Json.getBytes();
               // 设置文件长度
               System.out.println(1);
           }
           HttpResponse resp = client.execute(post);
           if(resp.getStatusLine().getStatusCode() == 200) {
           HttpEntity he = resp.getEntity();
           respContent = EntityUtils.toString(he,"UTF-8");
           System.out.println(respContent);
           }else{
            Header[] heads = resp.getAllHeaders();
            StringBuffer sb = new StringBuffer();
    for (Header header : heads) {
    sb.append("<p>")
    .append(header.getName())
    .append(" : ")
    .append(header.getValue())
    .append("</p>");
    }
    System.out.println(sb.toString());
            System.out.println(resp.getStatusLine().getStatusCode());
            HttpEntity he = resp.getEntity();
           respContent = EntityUtils.toString(he,"UTF-8");
          System.out.println(respContent);
           }
       } catch (Exception e) {
           e.printStackTrace();
       } 
       
       return result;
   }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值