阿里云货架商品识别与管理Java SDK

1. 准备工作

在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问访问密钥(AppKey)。

<a name="
2. 将 SDK添加到项目中” class=”reference-link”>
2. 将 SDK添加到项目中

1)pom.xml

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>3.5.1</version>
  5. </dependency>

2、CreateTask

  1. import com.aliyuncs.CommonRequest;
  2. import com.aliyuncs.CommonResponse;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.http.MethodType;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. public class Demo1 {
  8. //DefaultProfile.getProfile的参数分别是地域,access_key_id, access_key_secret
  9. public static DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LT********", "CB********");
  10. // public static DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", "");
  11. public static DefaultAcsClient client = new DefaultAcsClient(profile);
  12. public static void main(String[] args) throws ClientException {
  13. CommonRequest request = new CommonRequest();
  14. request.setMethod(MethodType.POST);
  15. request.setDomain("retailir.cn-hangzhou.aliyuncs.com");
  16. request.setVersion("2019-09-06");
  17. request.setAction("CreateTask");
  18. request.putBodyParameter("Appkey", "71********");
  19. request.putBodyParameter("TaskName", "demotest1");
  20. request.putBodyParameter("ImageLeftTop", "https://img2.ladyww.cn/cloudads/2023/01/31/3xu15cas1ce.png");
  21. CommonResponse response = null;
  22. try {
  23. response = client.getCommonResponse(request);
  24. } catch (ClientException e) {
  25. e.printStackTrace();
  26. }
  27. System.out.println(response.getData());
  28. }
  29. }

3、GetTask

  1. import com.aliyuncs.CommonRequest;
  2. import com.aliyuncs.CommonResponse;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.http.MethodType;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. public class Demo2 {
  8. //DefaultProfile.getProfile的参数分别是地域,access_key_id, access_key_secret
  9. public static DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LT********", "CB********");
  10. public static DefaultAcsClient client = new DefaultAcsClient(profile);
  11. public static void main(String[] args) throws ClientException {
  12. CommonRequest request = new CommonRequest();
  13. request.setMethod(MethodType.POST);
  14. request.setDomain("retailir.cn-hangzhou.aliyuncs.com");
  15. request.setVersion("2019-09-06");
  16. request.setAction("GetTask");
  17. request.putBodyParameter("Appkey", "71********");
  18. request.putBodyParameter("JobId", "cb89d9cd4ae043bc835797708e4ce92a");
  19. CommonResponse response = null;
  20. try {
  21. response = client.getCommonResponse(request);
  22. } catch (ClientException e) {
  23. e.printStackTrace();
  24. }
  25. System.out.println(response.getData());
  26. }
  27. }

原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/33465.html

发表评论

登录后才能评论