예제 #1
0
 //接收平台请求
 public string ReceiveFromServer(HttpRequest httpRequest)
 {
     try
     {
         string      receiveData = webUtils.GetRequestAsString(httpRequest, Encoding.GetEncoding(charset));
         ReceiveJson receiveJson = JsonConvert.DeserializeObject <ReceiveJson>(receiveData);
         //数据解密
         string dataDecrypt = Encrypt.AesDencrypt(encyptKey, receiveJson.data, charset);
         //数据验签
         bool checkSignResult = Signature.RSASignCheck(dataDecrypt, receiveJson.sign,
                                                       platformPublicKey, charset);
         if (checkSignResult)
         {
             return(dataDecrypt);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
예제 #2
0
        private string Excute(string httpJsonStr)
        {
            //发送平台请求
            string httpResponseJson = webUtils.DoPost(serverUrl, httpJsonStr, charset);
            //平台响应数据解密AES
            var respJsonObj = JsonConvert.DeserializeObject <HttpResponseJson>(httpResponseJson);

            if (respJsonObj.status == "200")   //请求成功
            {
                //平台响应数据解密
                string dataDecrypt = Encrypt.AesDencrypt(encyptKey, respJsonObj.data.data, charset);
                //平台响应数据验签
                bool checkSignResult = Signature.RSASignCheck(dataDecrypt, respJsonObj.data.sign,
                                                              platformPublicKey, charset);
                if (checkSignResult)  //验签成功
                {
                    return(dataDecrypt);
                }
                else   //验签失败
                {
                    ReturnToClient re = new ReturnToClient
                    {
                        status  = "500",
                        message = "数据不合法",
                    };
                    return(JsonConvert.SerializeObject(re));
                }
            }
            else   //请求失败
            {
                ReturnToClient re = new ReturnToClient
                {
                    status  = respJsonObj.status,
                    message = respJsonObj.message
                };
                return(JsonConvert.SerializeObject(re));
            }
        }