public void ResponseToServer(HttpResponse resp, object jsonObj = null) { try { ReturnToServer returnToServer = new ReturnToServer(); string httpJsonStr = JsonConvert.SerializeObject(returnToServer); if (jsonObj != null) { //构造业务参数json string dataJson = JsonConvert.SerializeObject(jsonObj); //数据加签RSA string sign = Signature.RSASignCharSetXML(dataJson, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); returnToServer.data = dataEncrypt; returnToServer.sign = sign; httpJsonStr = JsonConvert.SerializeObject(returnToServer); } //写入响应流 webUtils.WriteResponse(resp, httpJsonStr, Encoding.GetEncoding(charset)); } catch (Exception ex) { throw new AopException("响应失败,请检查业务参数"); } }
//响应平台请求 public void ResponseToServer(HttpResponse resp, IDictionary <string, object> dictionary = null) { try { //去除空字典项,并检查字典合法性 IDictionary <string, object> newDictionary = null; if (dictionary != null) { newDictionary = AopUtils.CleanupDictionary(dictionary); } ReturnToServer returnToServer = new ReturnToServer(); string httpJsonStr = JsonConvert.SerializeObject(returnToServer); if (newDictionary != null && newDictionary.Count > 0) { //构造业务参数json string dataJson = BuildBizJson(newDictionary); //数据加签RSA string sign = Signature.RSASignCharSetXML(dataJson, privateKeyPem, charset, false); //数据加密AES string dataEncrypt = Encrypt.AesEncrypt(encyptKey, dataJson, charset); returnToServer.data = dataEncrypt; returnToServer.sign = sign; httpJsonStr = JsonConvert.SerializeObject(returnToServer); } //写入响应流 webUtils.WriteResponse(resp, httpJsonStr, Encoding.GetEncoding(charset)); } catch (Exception ex) { throw new AopException("响应失败,请检查业务参数"); } }