netease320k / netease320k.github.io

网易云音乐320K检查小组任务公示栏
netease320k.github.io
GNU General Public License v3.0
4 stars 0 forks source link

私信相关 API #11

Open jixunmoe opened 8 years ago

jixunmoe commented 8 years ago

发送私信:

var enc = window.asrsea(JSON.stringify({"type":"text","msg":"测试信息 [大笑]","userIds":"[\"<目标用户ID>\"]","time":"-1","csrf_token":"<token>"}), "010001", "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7", "0CoJUm6Qyw8W8jud");
req.data = urlencode({
  params: enc.encText,
  encSecKey: enc.encSecKey
});
req.url = "http://music.163.com/weapi/msg/private/send";
req.post();

关于 asrsea 的 python 实现可以参考这里

def aesEncrypt(text, secKey):
    pad = 16 - len(text) % 16
    text = text + pad * chr(pad)
    encryptor = AES.new(secKey, 2, '0102030405060708')
    ciphertext = encryptor.encrypt(text)
    ciphertext = base64.b64encode(ciphertext)
    return ciphertext

def rsaEncrypt(text, pubKey, modulus):
    text = text[::-1]
    rs = int(text.encode('hex'), 16)**int(pubKey, 16) % int(modulus, 16)
    return format(rs, 'x').zfill(256)

def createSecretKey(size):
    return (''.join(map(lambda xx: (hex(ord(xx))[2:]), os.urandom(size))))[0:16]

# ...

    text = {} # 放入数据
    modulus = '00e0b50...' # 放入完整的
    nonce = '0CoJUm6Qyw8W8jud'
    pubKey = '010001'
    text = json.dumps(text) # json.stringify
    secKey = createSecretKey(16)
    encText = aesEncrypt(aesEncrypt(text, nonce), secKey)
    encSecKey = rsaEncrypt(secKey, pubKey, modulus)

注意:请求需要带上 Cookie。


抓取私信:

http://music.163.com/weapi/msg/private/users
=> {"uid":"<bot 用户 id>","getcounts":"true","offset":"0","total":"true","limit":"20","csrf_token":"<csrf_token>"}

抓取某个人的私信:

http://music.163.com/weapi/msg/private/history
=> {"getcounts":"true","userId":"<目标用户 id>","offset":"0","total":"true","limit":"20","csrf_token":"<csrf_token>"}
misaka00251 commented 8 years ago

感谢阁下!