Last active
August 18, 2019 08:59
-
-
Save imchao9/73aa1a8931cb310617117b2586eca292 to your computer and use it in GitHub Desktop.
七牛 ImageCensor 内容审查API Java调用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.lj.qiniu.ai; | |
import com.qiniu.common.QiniuException; | |
import com.qiniu.common.Zone; | |
import com.qiniu.http.Client; | |
import com.qiniu.http.Response; | |
import com.qiniu.storage.Configuration; | |
import com.qiniu.util.Auth; | |
import com.qiniu.util.StringMap; | |
import me.lj.qiniu.config.Config; | |
/** | |
* https://developer.qiniu.com/censor/api/5588/image-censor | |
*/ | |
public class ImageCensor { | |
public static void main(String[] args) throws QiniuException { | |
String ACCESS_KEY = Config.ACCESS_KEY; | |
String SECRET_KEY = Config.SECRET_KEY; | |
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY); | |
String url = "http://ai.qiniuapi.com/v3/image/censor"; | |
String host = "ai.qiniuapi.com"; | |
String body = "{ \"data\": { \"uri\": \"https://mars-assets.qnssl.com/resource/gogopher.jpg\" }, \"params\": { \"scenes\": [ \"pulp\", \"terror\", \"politician\" ] } }"; | |
String contentType = "application/json"; | |
String method = "POST"; | |
String qiniuToken = "Qiniu " + auth.signRequestV2(url, method, body.getBytes(), contentType); | |
System.out.println(url); | |
System.out.println(body); | |
System.out.println(qiniuToken); | |
StringMap header = new StringMap(); | |
header.put("Host", host); | |
header.put("Authorization", qiniuToken); | |
header.put("Content-Type", contentType); | |
Configuration c = new Configuration(Zone.zone1()); | |
Client client = new Client(c); | |
Response response = client.post(url, body.getBytes(), header, contentType); | |
System.out.println("Response: " + response.bodyString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment