Binance chat room red envelope search script

Original link: https://www.liesauer.net/blog/post/binance-red-envelope-scavenger.html

## request header

1. `bncuuid`

2. `csrftoken`

3. `device-info`

4. `fvideo-id`

5. `useragent`

## Cookies

1. `lang` (fixed to `zh-CN`)

2. `d1og` `r2o1` `f30l` `p20t`

## Chat room interface

There are two ways to connect to a chat room to obtain chat information, each with its own advantages and disadvantages. This article uses the method of `Web API`.

### Websockets

advantage:

1. Do not require a large number of requests and avoid frequent restrictions.

shortcoming:

1. A long connection is required, which is not suitable for most scripting environments.

2. When the connection is good, one or two messages will be lost occasionally (unknown reason).

3. The content needs to be decoded, and the decoding module has to be extracted by reverse JS.

### Web API

advantage:

1. Obtaining data is simple and convenient, without encoding and encryption.

shortcoming:

1. The request limit may be triggered, and the request frequency needs to be strictly controlled.

Request method: `POST`

Request address:

`https://www.binance.com/bapi/futures/v1/private/future/chatroom/get-user-dialog-list`

Request Data: None

return content:

![20230805214104.png](https://ift.tt/Ad9C8PQ)

We only need to pay attention to the `channelId` in it.

## Chat room information interface

Request method: `POST`

Request address:

`https://www.binance.com/bapi/futures/v1/private/future/chatroom/get-chat-msg-page`

Request data:

“`json

{

“channelId”: Channel ID,

“sequence”: null,

“size”: number of messages

}

“`

return content:

![20230805214737.png](https://ift.tt/FPUahm1)

## Filter red envelope information

`msgType` is `SEND_RED_ENVELOPE`, which is the message of sending red envelopes

`msgType` is `GRAB_RED_ENVELOPE`, which is the information for receiving red envelopes

Just ignore all other information

The `msgPayload` of `SEND_RED_ENVELOPE` is as follows:

“`json

{

“note”: “1”,

“amount”: “0.05000000”,

“grabCode”: “Red Envelope Code”,

“expireTime”: “1690766128593”,

“orderId”: “”,

“currency”: “COS”,

“received”: false,

“totalCount”: 1

}

“`

The `msgPayload` of `GRAB_RED_ENVELOPE` is as follows:

“`json

{

“grabCode”: “Red Envelope Code”,

“ownerChatUid”: “”,

“orderId”: “”,

“ownerNickname”: “”,

“sendRedEnvelopeSeq”: “”

}

“`

You only need to pay attention to `grabCode`.

## Query the red packet status

Request method: `POST`

Request address:

`https://www.binance.com/bapi/pay/v1/private/binance-pay/gift-box/code/query`

Request data:

“`json

{

“grabCode”: “Red Envelope Code”,

“channel”: “DEFAULT”

}

“`

return content:

![20230805220238.png](https://ift.tt/47CuVhP)

Red packet status:

`success` is `false`, the red envelope cannot be claimed (such as expired, received, etc.), see `message` for specific information

`data.grabbed` is `true`, which means it has been picked up

Otherwise it is available

## Receive red envelope

Request method: `POST`

Request address:

`https://www.binance.com/bapi/pay/v1/private/binance-pay/gift-box/code/grabV2`

Request data:

“`json

{

“grabCode”: “Red Envelope Code”,

“channel”: “DEFAULT”,

“scene”: null

}

“`

return content:

![20230805221110.png](https://ift.tt/yZKB5ku)

## Practical demo

![20230805221656.png](https://ift.tt/AU6vNMQ)

This article is transferred from: https://www.liesauer.net/blog/post/binance-red-envelope-scavenger.html
This site is only for collection, and the copyright belongs to the original author.