from __future__ import absolute_import, unicode_literals
from flask import Flask, request, abort
from wechatpy.enterprise.crypto import WeChatCrypto
from wechatpy.exceptions import InvalidSignatureException


TOKEN = '123456'
EncodingAESKey = ''
CorpId = ''

app = Flask(__name__)


@app.route('/wechat', methods=['GET', 'POST'])
def wechat():
    signature = request.args.get('msg_signature', '')
    timestamp = request.args.get('timestamp', '')
    nonce = request.args.get('nonce', '')
    echo_str = request.args.get('echostr', '')

    crypto = WeChatCrypto(TOKEN, EncodingAESKey, CorpId)
    try:
        echo_str = crypto.check_signature(
            signature,
            timestamp,
            nonce,
            echo_str
        )
    except InvalidSignatureException:
        abort(403)
    if request.method == 'GET':
        return echo_str
    else:
        print('test')
        return ''


if __name__ == '__main__':
    app.run('127.0.0.1', 5001, debug=True)

@@ -200,16 +200,82 @@
 ception%0A
+from wechatpy.enterprise.exceptions import InvalidCorpIdException%0A
 %0A%0ATOKEN 
@@ -552,55 +552,8 @@
  '')
-%0A    echo_str = request.args.get('echostr', '')
 %0A%0A  
@@ -607,16 +607,103 @@
 CorpId)%0A
+    if request.method == 'GET':%0A        echo_str = request.args.get('echostr', '')%0A    
     try:
@@ -703,16 +703,20 @@
    try:%0A
+    
         
@@ -750,16 +750,20 @@
 nature(%0A
+    
         
@@ -785,24 +785,28 @@
             
+    
 timestamp,%0A 
@@ -812,24 +812,28 @@
             
+    
 nonce,%0A     
@@ -831,32 +831,36 @@
 ce,%0A            
+  
+  
 echo_str%0A       
@@ -860,22 +860,30 @@
         
-)%0A
+    )%0A   
     
+ 
 except I
@@ -916,16 +916,20 @@
         
+    
 abort(40
@@ -935,40 +935,8 @@
 03)%0A
-    if request.method == 'GET':%0A
     
@@ -977,39 +977,176 @@
     
-print('test')%0A        return ''
+try:%0A            msg = crypto.decrypt_message(request.data)%0A        except (InvalidSignatureException, InvalidCorpIdException):%0A            abort(403)%0A        print msg
 %0A%0A%0Ai

Update echo-enterprise example