コード例 #1
0
ファイル: YopClient.cs プロジェクト: yp-creative/yop-net-sdk
        /// <summary>
        /// 发起get请求,以YopResponse对象返回
        /// </summary>
        /// <param name="methodOrUri"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static YopResponse get(string methodOrUri, YopRequest request)
        {
            string content = getForString(methodOrUri, request);
            //YopResponse response = YopMarshallerUtils.unmarshal(content,
            //        request.getFormat(), YopResponse.class);
            //  handleResult(request, response, content);
            YopResponse response = null;

            if (request.getFormat() == FormatType.json)
            {
                response = (YopResponse)JsonConvert.DeserializeObject(content, typeof(YopResponse));
            }
            else
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(content);
                string  jsonText = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
                JObject jo       = JObject.Parse(jsonText);
                string  strValue = jo["response"].ToString();
                response = (YopResponse)JsonConvert.DeserializeObject(strValue, typeof(YopResponse));
            }

            handleResult(request, response, content);
            return(response);
        }
コード例 #2
0
ファイル: YopClient.cs プロジェクト: yp-creative/yop-net-sdk
        protected static void handleResult(YopRequest request, YopResponse response, string content)
        {
            response.format = request.getFormat();
            string ziped = string.Empty;

            if (response.isSuccess())
            {
                string strResult = getBizResult(content, request.getFormat());
                ziped = strResult.Replace("\t\n", "");
                // 先解密,极端情况可能业务正常,但返回前处理(如加密)出错,所以要判断是否有error
                if (StringUtils.isNotBlank(strResult) && response.error == null)
                {
                    if (request.isEncrypt())
                    {
                        string decryptResult = decrypt(request, strResult.Trim());
                        response.stringResult = decryptResult;
                        response.result       = decryptResult;
                        ziped = decryptResult.Replace("\t\n", "");
                    }
                    else
                    {
                        response.stringResult = strResult;
                    }
                }
            }

            // 再验签
            if (request.isSignRet() && StringUtils.isNotBlank(response.sign))
            {
                string signStr = response.state + ziped + response.ts;
                response.validSign = YopSignUtils.isValidResult(signStr,
                                                                request.getSecretKey(), request.getSignAlg(),
                                                                response.sign);
            }
            else
            {
                response.validSign = true;
            }
        }