zoukankan      html  css  js  c++  java
  • 阿里软件接口开发一

    首先必须在阿里软件中注册,然后获得相应的app_id,后进行测试

    测试代码如下:

     protected void Page_Load(object sender, EventArgs e)
    {
    HttpRequest request
    = HttpContext.Current.Request;
    //在软件应用中心跳转到ISV应用时的URL参数中取得,user_id、app_instance_id和token
    string aepUserId = request.Params["user_id"];
    string aepInstanceId = request.Params["app_instance_id"];
    string appId = request.Params["app_id"]; //软件注册时获得
    string token = request.Params["token"]; //每次点击生成不一样的token,并只有10秒钟有效
    string code = "58b43970b12711ddb3e6cfd602199686";//软件注册时获得
    System.DateTime timestamp = System.DateTime.Now;//时间获得当前系统时间

    //sip_sign签名字段的生成,将CERT CODE和所有接口要传的参数进行组合,再将组装好的字符串进行md5加密后转成16进制后得到一个32位的密文
    string sipsign = code + "appId" + appId + "appInstanceId" + aepInstanceId + "sip_apinamealisoft.validateUser" + "sip_appkey" + appId + "sip_timestamp" + timestamp + "token" + token + "userId" + aepUserId;

    MD5CryptoServiceProvider md5
    = new MD5CryptoServiceProvider();
    sipsign
    = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(sipsign))).Replace("-", "");
    //sip_sign生成END

    //系统级参数拼装,包括sip_appkey、sip_apiname、sip_timestamp和sip_sign,sip_apiname是接口名这里举validateUser为例
    string SIPdate = "sip_appkey=" + appId + "&sip_apiname=alisoft.validateUser&sip_timestamp=" + timestamp + "&sip_sign=" + sipsign;
    //接口级参数拼装
    string apidate = "&userId=" + aepUserId + "&appId=" + appId + "&appInstanceId=" + aepInstanceId + "&token=" + token;

    ASCIIEncoding encoding
    = new ASCIIEncoding();
    byte[] postdata = encoding.GetBytes(SIPdate + apidate);//所有要传参数拼装
    // Prepare web request
    //目前阿里软件的服务集成平台(SIP)的接口测试地址是:http://sipdev.alisoft.com/sip/rest,生产环境地址是:http://sip.alisoft.com/sip/rest,
    //这里使用测试接口先,到正式上线时需要做切换
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://sipdev.alisoft.com/sip/rest");
    myRequest.Method
    = "POST";
    myRequest.ContentType
    = "application/x-www-form-urlencoded";
    myRequest.ContentLength
    = postdata.Length;
    Stream newStream
    = myRequest.GetRequestStream();
    // Send the data.
    newStream.Write(postdata, 0, postdata.Length);
    newStream.Close();
    // Get response
    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    StreamReader reader
    = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
    string content = reader.ReadToEnd();

    //解析接口返回值,这里选用XML格式的解析,接口默认返回是XML格式
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(content);
    XmlNode xn
    = xmlDoc.SelectSingleNode("String");
    XmlElement xe
    = (XmlElement)xn;
    string result = xe.InnerText;
    if ("1".Equals(result))
    {
    //如果是使用者。。。。
    windowalert("使用者");
    }
    else if ("0".Equals(result))
    {
    //如果是订阅者。。。。
    windowalert("订阅者");
    }
    }

    private void windowalert(string str)
    {
    HttpResponse Response
    = HttpContext.Current.Response;
    Response.Write(
    "<script>alert('" + str + "');window.close(true);</script>");
    }
    
    
    如上所以述返回的xml格式一般为:
    正常返回格式
    XML数据格式
    <?xml version="1.0" encoding="utf-8" ?>
    <String>0</String>
    返回值 返回值描述 返回值说明
    1 应用的订购者 订购者就是订购该服务的人
    0 应用的使用者 使用者就是使用该服务的人,只有被订阅者授权(邀请)以后才可以使用该服务
    -1 尚未订购该应用 表示尚未订购该应用的用户
    -2 非法用户 表示非法用户(没有正常登录软件互联平台,或者URL已过期失效)
    正常情况下如果在阿里旺旺中点击使用软件时返回的是1
    转载请注明出处[http://samlin.cnblogs.com/

    欢迎关注本人公众号:

    作者赞赏
  • 相关阅读:
    Newtonsoft.Json 处理多态类型的反序列化
    33条C#和.NET经典面试题目及答案
    转:原码,反码,补码详解
    使用OpenXML操作Office文档
    WPF的Binding学习笔记(二)
    WPF的Binding学习笔记(一)
    M6: 使用摄像头(CameraCaptureUI)
    M5: 使用StorageFile
    NYOJ144_小珂的苦恼_C++
    搜索水题四连发_C++
  • 原文地址:https://www.cnblogs.com/samlin/p/1332800.html
Copyright © 2011-2022 走看看