Learn this trick, my mother no longer worry about my ranking

Learn this trick, my mother no longer worry about my ranking

Tip: This article is for learning and reference only, and should not be used for illegal purposes~

foreword

According to legend, just a few days ago, Kimol-kun came across a song-guessing applet when he was wandering the Internet. This small program plays part of the song and then asks the user to guess its song name, which is probably like this:
insert image description here

As a brain-burning music lover, he fell deeper and deeper and brushed harder and harder. However, his ranking has never been up ! Just when he was feeling melancholy, a wonderful idea suddenly appeared. After learning it, mother no longer has to worry about his ranking!

1. Analysis of ideas

In order to find out what the song guessing process is like, first analyze the request and response by capturing packets. Open the applet in the PC version of WeChat, and then use Fiddler to capture packets. We will find that the process of guessing songs consists of two requests.
(ps. Of course, you can also directly grab the package on the mobile phone, but it will be relatively complicated for various reasons.)
One is to get the relevant information of the song (including the answer). right! You heard right, the returned data directly includes the answer to the song guessing, the request is as follows: This is a get request, including the token , user_id
insert image description here
, etc. used for login verification , and the returned result is the song-related information, the most important of which is is the answer (the part circled in red).

The other is to send a song guessing request , as follows:
insert image description here
This is also a get request, which also includes parameters such as token, the submitted answer answer and the sid of the song . The is_right field returned can be used to determine whether the guess is correct. (1 is correct, otherwise incorrect)

Then, the idea is clear: write a program through python, first get the answer to the song, and then submit the answer.

2. Get the answer

First define a class:

class guessStar():
    def __init__(self,token,userId):
        '''
        初始化函数
        '''
        self.token = token # 用户token
        self.userId = userId # 用户ID

Then, define a function to get the answer based on the packet capture request:

def get_answer(self):
    '''
    获取答案函数
    '''
    url = 'https://api.zuiqiangyingyu.net/index.php/api/guess_v2/Index'
    headers = {
    
    'Connection':'keep-alive',
               'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat',
               'content-type':'application/json',
               'Accept-Encoding':'gzip, deflate, br'}
    params = (('token',self.token), # 用户token,需要换成自己的
              ('user_id',self.userId), # 用户ID,需要换成自己的
              ('wechat_type','wechat_song'))
    res = requests.get(url,headers=headers,params=params) # 发送请求
    data = res.json() # 获取返回结果(json格式)
    music = data['d']['list'][0] # 音乐数据
    sid = music['id'] # 音乐ID
    answer = music['answer'] # 对应的答案
    return (sid,answer)

This request is very simple, you only need to simulate the url, parameters, request headers, etc. of the data packet.

3. Submit the answer

Similarly, define a function to submit an answer after packet capture analysis:

def guess(self,sid,answer):
    '''
    猜歌函数
    '''
    url= 'https://api.zuiqiangyingyu.net/index.php/api/guess_v2/Sub'
    headers = {
    
    'Connection':'keep-alive',
               'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat',
               'content-type':'application/json',
               'Accept-Encoding':'gzip, deflate, br'}
    params = (('token',self.token), # 用户token,需要换成自己的
              ('user_id',self.userId), # 用户ID,需要换成自己的
              ('sid',sid), # 音乐ID
              ('answer',answer), # 答案
              ('wechat_type','wechat_song'))
    res = requests.get(url,headers=headers,params=params)
    result = res.json()['d']['user']['is_right'] # 猜歌的结果
    return result

The function returns the is_right field, if it is 1 it means the answer is correct, otherwise it is wrong.

Fourth, guess

With the get_answer() and guess() functions, we can happily start automatic guessing and answering questions. Define the following functions:

def do_guess(self,num):
    '''
    进行猜歌(通过num指定次数)
    '''
    N = 0
    while True:
        sid,answer = self.get_answer()
        result = self.guess(sid,answer)
        if result == '1': # 如果猜对 
            N += 1
            print('第%s首歌回答正确!'%sid)
        else:
            print('第%s首歌回答错误!'%sid)
        if N >= num: # 如果达到指定次数
            break

The num parameter indicates the number of times to guess the song. Call it in the main function:

if __name__ == '__main__':
    star = guessStar('xxxx','xxx')
    star.do_guess(1001) # 开始猜歌

xxxx represent the token and user ID of the account respectively, and you need to replace them with your own. The so-called one thousand and one nights , so I also ran 1001 times, run it:
insert image description here
Before running, I am like this: After
insert image description here
running, I am like this: Yes
insert image description here
, my ranking is rising steadily! !
comfortable~~

write at the end

I think the real meaning of this article is not the code itself, but to provide you with broader ideas:

Python is not only the complicated theoretical knowledge in the classroom, but also provides convenience for our life;
Python is not only the boring day after day in the project, but also brings joy to our life;
Python is not only the tireless immersion in growth Study hard, but also add achievements to our life;

Whether it is Python, Java, C, or even photography and painting. whatever, they're all things we're interested in or skills that make a living. I think that only by truly loving them can they bear fruit and take root in our lives better!

I'm Kimol-kun, see you next time~
insert image description here

创作不易,大侠请留步… 动起可爱的双手,来个赞再走呗 (๑◕ܫ←๑)

Guess you like

Origin blog.csdn.net/kimol_justdo/article/details/110846843