public ZZXDictionary getSystemParams <T>(IZZXRequest <T> request) where T : ZZXResponse { string apiVersion = null; if (!string.IsNullOrEmpty(request.GetApiVersion())) { apiVersion = request.GetApiVersion(); } else { apiVersion = Version; } ZZXDictionary sysParams = new ZZXDictionary(); sysParams.Add(METHOD, request.GetApiName()); sysParams.Add(VERSION, apiVersion); sysParams.Add(ChANNELID, _channelId); sysParams.Add(SIGNTYPE, _singType); sysParams.Add(PARAMS, request.GetParams()); var d = sysParams.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value); //签名需要先排序下 中子星文档要求 // 添加签名参数 var build = WebUtils.BuildQuery(d, false, _charset); // 这个签名没问题 sysParams.Add(SIGN, RSAUtil.Sign(WebUtils.BuildQuery(d, false, _charset), _privateKey, _charset)); return(sysParams); }
public T Execute <T>(IZZXRequest <T> request) where T : ZZXResponse { if (string.IsNullOrEmpty(_charset)) { _charset = "UTF-8"; } ZZXDictionary sysParams = getSystemParams(request); string body; //这里要组装成对象 JObject jb = new JObject(); foreach (var key in sysParams.Keys) { //params 这个要转回问题 if (key == "params") { jb.Add(new JProperty(key, JsonConvert.DeserializeObject(sysParams[key].ToString()))); } else { jb.Add(new JProperty(key, sysParams[key])); } } var tt = JsonConvert.SerializeObject(jb); var encode = HttpUtility.UrlEncode(tt);//传递的时候进行url编码 body = _webUtils.DoPost(_serverUrl, encode, _charset); string bizResponse = body; T rsp = null; //再这里转换出来然后验签 ZZXDictionary dic = new ZZXDictionary(); JObject jObject = JsonConvert.DeserializeObject(bizResponse) as JObject; if (jObject != null) { //去掉 statuscode errmsg sign 三个键值对 排序组合成待签名字符串 if (jObject["sign"] != null) { var sign = jObject["sign"].ToString(); dic.Add("method", jObject["method"].ToString()); dic.Add("ver", jObject["ver"].ToString()); dic.Add("channelId", jObject["channelId"].ToString()); dic.Add("signType", jObject["signType"].ToString()); if (jObject["params"] != null) { dic.Add("params", JsonConvert.SerializeObject(jObject["params"])); } var d = dic.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value); var s = WebUtils.BuildQuery(d, false, _charset); RSAUtil.VerifySign(s, sign, _publicKey, _charset); } } rsp = JsonConvert.DeserializeObject <T>(bizResponse); return(rsp); }