diff --git a/callback_json_python3/WXBizJsonMsgCrypt.py b/callback_json_python3/WXBizJsonMsgCrypt.py index a954283..c9725b0 100644 --- a/callback_json_python3/WXBizJsonMsgCrypt.py +++ b/callback_json_python3/WXBizJsonMsgCrypt.py @@ -190,7 +190,9 @@ def decrypt(self,text,receiveid): except Exception as e: print(e) return ierror.WXBizMsgCrypt_IllegalBuffer,None - if from_receiveid != receiveid: + + # 兼容企业内部智能机器人,企业内部智能机器人解析出来的from_receiveid是'',参考官网:https://developer.work.weixin.qq.com/document/path/101033 + if from_receiveid and from_receiveid != receiveid: print("receiveid not match", receiveid, from_receiveid) return ierror.WXBizMsgCrypt_ValidateCorpid_Error,None return 0,json_content @@ -230,7 +232,8 @@ def VerifyURL(self, sMsgSignature, sTimeStamp, sNonce, sEchoStr): return ierror.WXBizMsgCrypt_ValidateSignature_Error, None pc = Prpcrypt(self.key) ret,sReplyEchoStr = pc.decrypt(sEchoStr,self.m_sReceiveId) - return ret,sReplyEchoStr + # 转成int类型,企信的消息要求是int类型的,解析出来的字符串返回会报错:echostr校验失败,请您检查是否正确解密并输出明文echostr + return ret,int(sReplyEchoStr) def EncryptMsg(self, sReplyMsg, sNonce, timestamp = None): #将企业回复用户的消息加密打包