@@ -343,14 +343,17 @@ var serveEncrypt = function (that, req, res, next, _respond) {
343343 var timestamp = req . query . timestamp ;
344344 var nonce = req . query . nonce ;
345345
346+ // 判断是否已有前置cryptor
347+ var cryptor = req . cryptor || that . cryptor ;
348+
346349 if ( method === 'GET' ) {
347350 var echostr = req . query . echostr ;
348- if ( signature !== that . cryptor . getSignature ( timestamp , nonce , echostr ) ) {
351+ if ( signature !== cryptor . getSignature ( timestamp , nonce , echostr ) ) {
349352 res . writeHead ( 401 ) ;
350353 res . end ( 'Invalid signature' ) ;
351354 return ;
352355 }
353- var result = that . cryptor . decrypt ( echostr ) ;
356+ var result = cryptor . decrypt ( echostr ) ;
354357 // TODO 检查appId的正确性
355358 res . writeHead ( 200 ) ;
356359 res . end ( result . message ) ;
@@ -372,12 +375,12 @@ var serveEncrypt = function (that, req, res, next, _respond) {
372375 }
373376 var xml = formatMessage ( result . xml ) ;
374377 var encryptMessage = xml . Encrypt ;
375- if ( signature !== that . cryptor . getSignature ( timestamp , nonce , encryptMessage ) ) {
378+ if ( signature !== cryptor . getSignature ( timestamp , nonce , encryptMessage ) ) {
376379 res . writeHead ( 401 ) ;
377380 res . end ( 'Invalid signature' ) ;
378381 return ;
379382 }
380- var decrypted = that . cryptor . decrypt ( encryptMessage ) ;
383+ var decrypted = cryptor . decrypt ( encryptMessage ) ;
381384 var messageWrapXml = decrypted . message ;
382385 if ( messageWrapXml === '' ) {
383386 res . writeHead ( 401 ) ;
0 commit comments