/// <summary> /// 提交查询发票的Json /// </summary> /// <param name="url"></param> /// <param name="content"></param> /// <returns></returns> public MsgResponse PostQueryJson(string url, string content) { MsgResponse rsp = null; try { string json = BuildRequestJSON(content); string jsonRsp = HttpHelper.Post(url, Encoding.UTF8.GetBytes(json)); rsp = JsonHelper.String2Object <MsgResponse>(jsonRsp); Dictionary <string, string> dic = JsonHelper.String2Object <Dictionary <string, string> >(jsonRsp); // 移除签名串 dic.Remove("sign"); // 根据响应返回的数据构建新的签名串 string contentResp = RSAHelper.GenerateSignContent(dic); // 验签结果 bool ret = RSAHelper.VerifyByJavaPublicKey(contentResp, rsp.sign, mPublicKey); if (!ret) { throw new Exception("接口返回的数据验签失败!"); } rsp.content = DESHelper.Decrypt(mPasswd, rsp.content); rsp.QueryContent = JsonHelper.String2Object <QueryContent>(rsp.content); return(rsp); } catch (Exception e) { if (rsp == null) { rsp = new MsgResponse(); } rsp.msg = e.Message; return(rsp); } }
/// <summary> /// 创建json /// </summary> /// <param name="content"></param> /// <returns></returns> string BuildRequestJSON(string content) { Dictionary <string, string> msg = new Dictionary <string, string>(); msg.Add("platformCode", mPlatformCode); msg.Add("signType", "RSA"); msg.Add("format", "JSON"); msg.Add("version", this.mVersion); try { msg.Add("content", DESHelper.Encrypt(mPasswd, content)); msg.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); msg.Add("serialNo", SerialNoHelper.GetSerialNo(mPrefix)); string sign = RSAHelper.GenerateSignContent(msg); msg.Add("sign", RSAHelper.SignByJavaPrivateKey(sign, mPrivateKey)); return(JsonHelper.Object2String <Dictionary <string, string> >(msg)); } catch (Exception e) { throw new Exception("生成完整JSON时出错:" + e.Message); } }