zoukankan      html  css  js  c++  java
  • 小i机器人接口

    string realm = "xiaoi.com";
    string method = "POST";
    string uri = "/robot/ask.do";
    string key = "你的key";
    string secret = "你的secret ;
    byte[] b = new byte[40];
    new Random().NextBytes(b);
    char[] c = "abcdefghijklmnopqrstuvwxyz0123456789".ToArray();
    string nonce = "";
    Random r = new Random();
    for (int i = 0; i < 40; i++)
    {
    nonce += c[r.Next(0, c.Length - 1)];
    }
    string ha1 = Common.SHA.SHA1(key + ":" + realm + ":" + secret);
    string ha2 = Common.SHA.SHA1(method + ":" + uri);
    string sign = Common.SHA.SHA1(ha1.ToLower() + ":" + nonce + ":" + ha2.ToLower());
    HttpWebRequest httpRequest;
    httpRequest = (HttpWebRequest)WebRequest.Create("http://nlp.xiaoi.com/robot/ask.do");
    httpRequest.Headers["X-Auth"] = "app_key=" + '"' + key + '"' + ", nonce=" + '"' + nonce + '"' + ", signature=" + '"' + sign.ToLower() + '"';
    httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    returnStr = urlRequest.HttpPost(httpRequest, "question=" + HttpContext.Current.Server.UrlEncode(Content) + "&userId=&type=0", Encoding.UTF8);

    /// <summary>
    /// SHA1加密字符串
    /// </summary>
    /// <param name="source">源字符串</param>
    /// <returns>加密后的字符串</returns>
    public static string SHA1(string source)
    {
    byte[] value = Encoding.UTF8.GetBytes(source);
    SHA1 sha = new SHA1CryptoServiceProvider();
    byte[] result = sha.ComputeHash(value);

    string delimitedHexHash = BitConverter.ToString(result);
    string hexHash = delimitedHexHash.Replace("-", "");

    return hexHash;
    }

  • 相关阅读:
    献给 Python 开发人员的 25 个最佳 GitHub 代码库!
    6 drf-认证权限解析频率
    4: drf视图组件
    3 drf请求与响应
    十三:Django框架学习之auth模块
    十二:django中间件学习之拓展1
    git光速从入门到精通
    mac系统下的mysql安装(ver.8.0.20)
    python小练习——2048
    docker下overlay2占用空间过大,清理docker占用空间
  • 原文地址:https://www.cnblogs.com/Lance-Lan/p/3186857.html
Copyright © 2011-2022 走看看