gpt4 book ai didi

java实现小i机器人api接口调用示例

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 27 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章java实现小i机器人api接口调用示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

代码如下

package com.weixin.util,

  。

import java.io.IOException; import java.util.Random; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.lang.StringUtils,

public class XiaoI {  private final static String APP_KEY = "*****";  private final static String APP_SECRET = "****",

 public String Tess(String key, String names) {   String realm = "xiaoi.com";   String method = "POST";   String uri = "/robot/ask.do";   byte[] b = new byte[20];   new Random().nextBytes(b);   String nonce = new String(Hex.encodeHex(b));   String HA1 = DigestUtils.shaHex(StringUtils.join(new String[] {     APP_KEY, realm, APP_SECRET }, ":"));   String HA2 = DigestUtils.shaHex(StringUtils.join(new String[] { method,     uri }, ":"));   String sign = DigestUtils.shaHex(StringUtils.join(new String[] { HA1,     nonce, HA2 }, ":")),

  String str = null,

  HttpClient hc = new HttpClient();   PostMethod pm = new PostMethod("http://nlp.xiaoi.com/robot/ask.do");   pm.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,     "utf-8");   pm.addRequestHeader("X-Auth", "app_key=\"7HHk65oE2Ngy\", nonce=\""     + nonce + "\", signature=\"" + sign + "\"");   pm.setParameter("platform", "weixin");   pm.setParameter("type", "0");   pm.setParameter("userId", names);   pm.setParameter("question", key);   int re_code;   try {    re_code = hc.executeMethod(pm);    if (re_code == 200) {     str = pm.getResponseBodyAsString();    }   } catch (HttpException e) {    // TODO Auto-generated catch block    e.printStackTrace();   } catch (IOException e) {    // TODO Auto-generated catch block    e.printStackTrace();   }   return str;  } } 。

  。

最后此篇关于java实现小i机器人api接口调用示例的文章就讲到这里了,如果你想了解更多关于java实现小i机器人api接口调用示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com