You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class WeworkCrypt 提供接收和推送给企业微信消息的加解密接口(UTF8编码的字符串)
verifyUrl 验证URL
decrypt 对密文进行解密
encrypt 对明文进行加密
encryptMsg 将企业微信回复用户的消息加密打包
decryptMsg 检验消息的真实性,并且获取解密后的明文
Getting started
constWeworkCrypt=require('wework-crypt');consttoken='QDG6eK';constcorpid='wx5823bf96d3bd56c7';constencodingAESKey='jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C';constweworkCrypt=newWeworkCrypt(token,encodingAESKey,corpid);// 校验URLconstmsgSignature='5c45ff5e21c57e6ad56bac8758b79b1d9ac89fd3';consttimestamp='1409659589';constnonce='263014780';constechostr='P9nAzCzyDtyTWESHep1vC5X9xho/qYX3Zpb4yKa9SKld1DsH3Iyt3tP3zNdtp+4RPcs8TgAE7OaBO+FZXvnaqQ==';weworkCrypt.verifyUrl(msgSignature,timestamp,nonce,echostr);// 解密消息constmsgSignature='477715d11cdb4164915debcba66cb864d751f3e6';consttimestamp='1409659813';constnonce='1372623149';constdata='<xml><ToUserName><![CDATA[wx5823bf96d3bd56c7]]></ToUserName><Encrypt><![CDATA[RypEvHKD8QQKFhvQ6QleEB4J58tiPdvo+rtK1I9qca6aM/wvqnLSV5zEPeusUiX5L5X/0lWfrf0QADHHhGd3QczcdCUpj911L3vg3W/sYYvuJTs3TUUkSUXxaccAS0qhxchrRYt66wiSpGLYL42aM6A8dTT+6k4aSknmPj48kzJs8qLjvd4Xgpue06DOdnLxAUHzM6+kDZ+HMZfJYuR+LtwGc2hgf5gsijff0ekUNXZiqATP7PF5mZxZ3Izoun1s4zG4LUMnvw2r+KqCKIw+3IQH03v+BCA9nMELNqbSf6tiWSrXJB3LAVGUcallcrw8V2t9EL4EhzJWrQUax5wLVMNS0+rUPA3k22Ncx4XXZS9o0MBH27Bo6BpNelZpS+/uh9KsNlY6bHCmJU9p8g7m3fVKn28H3KDYA5Pl/T8Z1ptDAVe0lXdQ2YoyyH2uyPIGHBZZIs2pDBS8R07+qN+E7Q==]]></Encrypt><AgentID><![CDATA[218]]></AgentID></xml>';awaitweworkCrypt.decryptMsg(msgSignature,timestamp,nonce,data);// 加密消息constmsgSignature='477715d11cdb4164915debcba66cb864d751f3e6';consttimestamp='1409659813';constnonce='1372623149';constdata='<xml><ToUserName><![CDATA[mycreate]]></ToUserName><FromUserName><![CDATA[wx5823bf96d3bd56c7]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[this is a test]]></Content><MsgId>1234567890123456</MsgId><AgentID>128</AgentID></xml>';awaitweworkCrypt.encryptMsg(msgSignature,timestamp,nonce,data);