Sample Code

以下将以GetDataSourceList接口为例,使用两种方式介绍如何通过SDK发起带有签名的请求。

  • 第一种方式(推荐)

    1. 实例化PwC.Api.Sdk中的RequestHelper对象

      //
      RequestHelper requestHelper = new RequestHelper(appKey, securityKey, domain);
      
    2. 通过第一步实例对象调用PostAsync,发起post请求,并获取请求结果

       //
       var response = 
        await requestHelper.PostAsync("/tenant/appCode/customapi/GetDataSourceList",
       JsonConvert.DeserializeObject<Dictionary<string, object>>("{\"State\":-1}"));
      
  • 第二种方式 - 分步

    1. 实例化PwC.Api.Sdk中的RequestHelper对象

      //
      RequestHelper requestHelper = new RequestHelper(appKey, securityKey, domain);
      
    2. 实例化ISigner

      //
      ISigner signer = new HmacSHA256();
      
    3. 获取时间戳

      //
      string timestamp = Common.GetDateTotalMilliseconds().ToString();
      
    4. 获取随机数

      //
      string nonce = Common.GetNonce();
      
    5. 获取签名原串

      //
      string sourceText = signer.GetStringToSign(requestData, appKey, securityKey, nonce, timestamp);
      
    6. 获取签名

      //
      string sign = signer.GetSign(sourceText);
      
    7. 使用PostAsync发起请求并获取结果

      //
      var response = 
      await requestHelper.PostAsync("/tenant/appCode/customapi/GetDataSourceList", 
      JsonConvert.DeserializeObject<Dictionary<string, object>>("{\"State\":-1}"), sign, nonce, timestamp);
      
© Digital Maker Product Team all right reserved,powered by Gitbook该文件修订时间: 2023-02-02 10:40:12

results matching ""

    No results matching ""