private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            //  第一个字母+长度+>
            var signDataStartIndex = indexOfRootNode + rootNode.Length + 1;

            var xmlStartNode       = "<" + AlipayConstants.ENCRYPT_NODE_NAME + ">";
            var xmlEndNode         = "</" + AlipayConstants.ENCRYPT_NODE_NAME + ">";
            var indexOfEncryptNode = body.IndexOf(xmlEndNode);

            if (indexOfEncryptNode < 0)
            {
                var item = new EncryptParseItem()
                {
                    encryptContent = null,
                    startIndex     = 0,
                    endIndex       = 0
                };
                return(item);
            }

            var startIndex = signDataStartIndex + xmlStartNode.Length;
            var bizLen     = indexOfEncryptNode - startIndex;

            var encryptBizContent = body.Substring(startIndex, bizLen);

            var item2 = new EncryptParseItem()
            {
                encryptContent = encryptBizContent,
                startIndex     = signDataStartIndex,
                endIndex       = indexOfEncryptNode + xmlEndNode.Length
            };

            return(item2);
        }
Exemple #2
0
        private static EncryptParseItem ParseEncryptItem(string body, string rootNode, int indexOfRootNode)
        {
            var signDataStartIndex = indexOfRootNode + rootNode.Length + 2;
            var indexOfSign        = body.IndexOf("\"" + AlipayConstants.SIGN + "\"");

            var signDataEndIndex = indexOfSign - 1;

            if (signDataEndIndex < 0)
            {
                signDataEndIndex = body.Length - 1;
            }

            var length = signDataEndIndex - signDataStartIndex;

            var encyptContent = body.Substring(signDataStartIndex + 1, length - 2);

            var item = new EncryptParseItem()
            {
                encryptContent = encyptContent,
                startIndex     = signDataStartIndex,
                endIndex       = signDataEndIndex
            };

            return(item);
        }
        private static EncryptParseItem ParseEncryptData(IAlipayRequest <T> request, string body)
        {
            var rootNode      = request.GetApiName().Replace(".", "_") + AlipayConstants.RESPONSE_SUFFIX;
            var errorRootNode = AlipayConstants.ERROR_RESPONSE;

            var indexOfRootNode  = body.IndexOf(rootNode);
            var indexOfErrorRoot = body.IndexOf(errorRootNode);

            EncryptParseItem result = null;

            if (indexOfRootNode > 0)
            {
                result = ParseEncryptItem(body, rootNode, indexOfRootNode);
            }
            else if (indexOfErrorRoot > 0)
            {
                result = ParseEncryptItem(body, errorRootNode, indexOfErrorRoot);
            }

            return(result);
        }