当前位置:   article > 正文

腾讯ai人工智能(智障)-java版可直接运行_腾讯ai生成海报 java

腾讯ai生成海报 java
  1. import cn.hutool.core.util.RandomUtil;
  2. import cn.hutool.http.HttpRequest;
  3. import org.springframework.util.DigestUtils;
  4. import java.net.URLEncoder;
  5. import java.util.*;
  6. class Test1 {
  7. final static String APP_ID = "";//腾讯云AI的 的appid
  8. final static String APP_KEY = "";//腾讯云AI的 APP_KEY
  9. public static void main(String[] args) {
  10. Map<String,Object> map = new HashMap();
  11. map.put("app_id",APP_ID);
  12. map.put("time_stamp",String.valueOf(new Date().getTime()/1000));
  13. map.put("nonce_str", RandomUtil.simpleUUID());
  14. map.put("session",RandomUtil.randomNumbers(5));
  15. map.put("question","你是人工智障吗");
  16. String siges = formatUrlParam(map, "utf-8", false)+"&app_key="+APP_KEY;
  17. map.put("sign", DigestUtils.md5DigestAsHex(siges.getBytes()).toUpperCase());
  18. HttpRequest result2 = HttpRequest.post("https://api.ai.qq.com/fcgi-bin/nlp/nlp_textchat");
  19. result2.form(map);
  20. System.out.println(result2.execute().body());
  21. }
  22. //拼接url
  23. public static String formatUrlParam(Map<String, Object> param, String encode, boolean isLower) {
  24. String params = "";
  25. Map<String, Object> map = param;
  26. try {
  27. List<Map.Entry<String, String>> itmes = new ArrayList(map.entrySet());
  28. //对所有传入的参数按照字段名从小到大排序
  29. //Collections.sort(items); 默认正序
  30. //可通过实现Comparator接口的compare方法来完成自定义排序
  31. Collections.sort(itmes, new Comparator<Map.Entry<String, String>>() {
  32. @Override
  33. public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
  34. // TODO Auto-generated method stub
  35. return (o1.getKey().toString().compareTo(o2.getKey()));
  36. }
  37. });
  38. //构造URL 键值对的形式
  39. StringBuffer sb = new StringBuffer();
  40. for (Map.Entry<String, String> item : itmes) {
  41. if (item.getKey() != null && item.getKey()!="") {
  42. String key = item.getKey();
  43. String val = item.getValue();
  44. val = URLEncoder.encode(val, encode);
  45. if (isLower) {
  46. sb.append(key.toLowerCase() + "=" + val);
  47. } else {
  48. sb.append(key + "=" + val);
  49. }
  50. sb.append("&");
  51. }
  52. }
  53. params = sb.toString();
  54. if (!params.isEmpty()) {
  55. params = params.substring(0, params.length() - 1);
  56. }
  57. } catch (Exception e) {
  58. return "";
  59. }
  60. return params;
  61. }
  62. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/776070
推荐阅读
相关标签
  

闽ICP备14008679号