Ruby 微信开发中消息加解密的实现

bmmz · 2016年08月08日 · 最后由 ruby_sky 回复于 2016年08月08日 · 3238 次阅读

微信消息有加密模式。格式如下

new_msg=
<xml> 
    <ToUserName><![CDATA[toUser]]</ToUserName>
       <Encrypt><![CDATA[msg_encrypt]]</Encrypt>
</xml>

其中,msg_encrypt = Base64_Encode( AES_Encrypt[ random(16B) + msg_len(4B) + msg + $AppId] )

AES 加密的 buf 由 16 个字节的随机字符串、4 个字节的 msg_len(网络字节序)、msg 和$AppId 组成,其中 msg_len 为 msg 的长度,$AppId 为公众帐号的 AppId

AESKey =Base64_Decode(EncodingAESKey + “=”),32 个字节 其中 AES_Encrypt 这个函数在 ruby 中有没有现成的实现函数。请各位开发过微信相关功能的不吝赐教。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号