Ejemplo n.º 1
0
 //执行平台请求,并获取平台响应
 public string RequestToServer(IDictionary <string, object> dictionary = null)
 {
     try
     {
         //去除空字典项,并检查字典合法性
         IDictionary <string, object> newDictionary = null;
         if (dictionary != null)
         {
             newDictionary = AopUtils.CleanupDictionary(dictionary);
         }
         // 添加协议级请求参数
         HttpRequestJson httpRequestJson = new HttpRequestJson
         {
             token = new PlatformToken
             {
                 apiID     = apiID,
                 userID    = userID,
                 timestamp = AopUtils.GetTimestamp(DateTime.Now).ToString()
             }
         };
         string httpJsonStr = JsonConvert.SerializeObject(httpRequestJson);
         if (newDictionary != null && newDictionary.Count > 0)
         {
             //构造业务参数json
             string dataJson = BuildBizJson(newDictionary);
             //数据加签RSA
             var    tokenStr = JsonConvert.SerializeObject(httpRequestJson.token);
             string sign     = Signature.RSASignCharSetXML(dataJson + tokenStr, privateKeyPem, charset, false);
             //数据加密AES
             string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset);
             httpRequestJson.data = dataEncrypt;
             httpRequestJson.sign = sign;
             httpJsonStr          = JsonConvert.SerializeObject(httpRequestJson);
         }
         string result = Excute(httpJsonStr);
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
 public string RequestToServer(object jsonObj = null)
 {
     try
     {
         // 添加协议级请求参数
         HttpRequestJson httpRequestJson = new HttpRequestJson
         {
             token = new PlatformToken
             {
                 apiID     = apiID,
                 userID    = userID,
                 timestamp = AopUtils.GetTimestamp(DateTime.Now).ToString()
             }
         };
         string httpJsonStr = JsonConvert.SerializeObject(httpRequestJson);
         if (jsonObj != null)
         {
             //构造业务参数json
             string dataJson = JsonConvert.SerializeObject(jsonObj);
             //数据加签RSA
             var    tokenStr = JsonConvert.SerializeObject(httpRequestJson.token);
             string sign     = Signature.RSASignCharSetXML(dataJson + tokenStr, privateKeyPem, charset, false);
             //数据加密AES
             string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset);
             httpRequestJson.data = dataEncrypt;
             httpRequestJson.sign = sign;
             httpJsonStr          = JsonConvert.SerializeObject(httpRequestJson);
         }
         string result = Excute(httpJsonStr);
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }