@@ -61,20 +61,21 @@ class JsonParse:
6161
6262 # json消息模板
6363 AES_TEXT_RESPONSE_TEMPLATE = '''{
64- "Encrypt ": "%(msg_encrypt)s",
65- "MsgSignature ": "%(msg_signaturet)s",
66- "TimeStamp ": %(timestamp)s,
67- "Nonce ": "%(nonce)s"
68- }'''
64+ "encrypt ": "%(msg_encrypt)s",
65+ "msgsignature ": "%(msg_signaturet)s",
66+ "timestamp ": %(timestamp)s,
67+ "nonce ": "%(nonce)s"
68+ }'''
6969
7070 def extract (self , jsontext ):
7171 """提取出json数据包中的加密消息
7272 @param jsontext: 待提取的json字符串
7373 @return: 提取出的加密消息字符串
7474 """
75+ print jsontext
7576 try :
7677 json_dict = json .loads (jsontext )
77- return ierror .WXBizMsgCrypt_OK , json_dict ['Encrypt ' ]
78+ return ierror .WXBizMsgCrypt_OK , json_dict ['encrypt ' ]
7879 except Exception ,e :
7980 print e
8081 return ierror .WXBizMsgCrypt_ParseXml_Error , None
@@ -87,11 +88,11 @@ def generate(self, encrypt, signature, timestamp, nonce):
8788 @return: 生成的json字符串
8889 """
8990 resp_dict = {
90- 'msg_encrypt' : encrypt ,
91- 'msg_signaturet' : signature ,
92- 'timestamp' : timestamp ,
93- 'nonce' : nonce ,
94- }
91+ 'msg_encrypt' : encrypt ,
92+ 'msg_signaturet' : signature ,
93+ 'timestamp' : timestamp ,
94+ 'nonce' : nonce ,
95+ }
9596 resp_json = self .AES_TEXT_RESPONSE_TEMPLATE % resp_dict
9697 return resp_json
9798
@@ -207,13 +208,13 @@ def __init__(self,sToken,sEncodingAESKey,sReceiveId):
207208 self .m_sToken = sToken
208209 self .m_sReceiveId = sReceiveId
209210
210- #验证URL
211+ #验证URL
211212 #@param sMsgSignature: 签名串,对应URL参数的msg_signature
212213 #@param sTimeStamp: 时间戳,对应URL参数的timestamp
213214 #@param sNonce: 随机串,对应URL参数的nonce
214215 #@param sEchoStr: 随机串,对应URL参数的echostr
215216 #@param sReplyEchoStr: 解密之后的echostr,当return返回0时有效
216- #@return:成功0,失败返回对应的错误码
217+ #@return:成功0,失败返回对应的错误码
217218
218219 def VerifyURL (self , sMsgSignature , sTimeStamp , sNonce , sEchoStr ):
219220 sha1 = SHA1 ()
@@ -225,7 +226,7 @@ def VerifyURL(self, sMsgSignature, sTimeStamp, sNonce, sEchoStr):
225226 pc = Prpcrypt (self .key )
226227 ret ,sReplyEchoStr = pc .decrypt (sEchoStr ,self .m_sReceiveId )
227228 return ret ,sReplyEchoStr
228-
229+
229230 def EncryptMsg (self , sReplyMsg , sNonce , timestamp = None ):
230231 #将企业回复用户的消息加密打包
231232 #@param sReplyMsg: 企业号待回复用户的消息,json格式的字符串
@@ -271,5 +272,3 @@ def DecryptMsg(self, sPostData, sMsgSignature, sTimeStamp, sNonce):
271272 pc = Prpcrypt (self .key )
272273 ret ,json_content = pc .decrypt (encrypt ,self .m_sReceiveId )
273274 return ret ,json_content
274-
275-
0 commit comments