News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

原神抢码,米游社抢码-首发

posted on 2023-06-06 10:50     read(430)     comment(0)     like(10)     collect(4)


This article is for learning purposes only - Infringement please contact to delete_2023年3月14日08:17:06

Originally, I couldn’t beat the 12th floor of the abyss. I accidentally stumbled into a live broadcast room of dy. I saw the host rushing to get the number to help fight the abyss. He also claimed that the pain number was not satisfied with the banner of not giving away rough stones. I decided to scan the code and try it. In the live broadcast room, I used two mobile phones to scan the QR codes for each other. After scanning the QR codes all afternoon, I found that I couldn’t get the QR codes. After my mentality collapsed, I thought about writing a script to help me grab the QR codes (I am py Xiaobai), and finally After working in vain for a while, I finally decided to write a program with a learning attitude to help me with the code grabbing operation!

Principle explanation

  1. Take a screenshot of the screen area (used to obtain the QR code)

  1. Analyze the obtained QR code

  1. Intercept the parsed content into the ticket

  1. Finally sent to MiHoYo 's server

There are two steps in the code grabbing login

The first step is to grab code

The second step to log in

Haha sounds like nonsense, we will first scan the QR code to identify the owner, first determine who the owner of the QR code is, as long as the owner is confirmed, there is no problem even if you wait a few minutes before confirming the login.

  1. # 抢码开始
  2. def Request(ticket):
  3. conn = http.client.HTTPSConnection("api-sdk.mihoyo.com")
  4. payload = json.dumps({
  5. "app_id": 4,
  6. "device": "",
  7. "ticket": ticket
  8. })
  9. headers = {}
  10. conn.request("POST", "/hk4e_cn/combo/panda/qrcode/scan", payload, headers)
  11. res = conn.getresponse()
  12. data = res.read()
  13. data = json.loads(data.decode("utf-8"))
  14. retcode = data["retcode"]
  15. return retcode

Let's first identify the QR code. The parameter of the ticket is obtained by itself after the QR code is parsed.

  1. # 确认登陆
  2. def ConfirmRequest(ticket):
  3. conn = http.client.HTTPSConnection("api-takumi.miyoushe.com")
  4. payload = ''
  5. headers = {
  6. 'DS': '',
  7. 'cookie': '',
  8. 'x-rpc-client_type': '',
  9. 'x-rpc-app_version': '',
  10. 'x-rpc-sys_version': '',
  11. 'x-rpc-channel': '',
  12. 'x-rpc-device_id': '',
  13. 'x-rpc-device_fp': '',
  14. 'x-rpc-device_name': '',
  15. 'x-rpc-device_model': '',
  16. 'Referer': ' https://app.mihoyo.co'
  17. }
  18. conn.request("GET", "/auth/api/getGameToken?uid=0000000",
  19. payload, headers)
  20. res = conn.getresponse()
  21. data = res.read()
  22. # print(data.decode("utf-8"))
  23. data = json.loads(data.decode("utf-8"))
  24. token = data["data"]["game_token"]
  25. conn = http.client.HTTPSConnection("api-sdk.mihoyo.com")
  26. payload = json.dumps({
  27. "app_id": 4,
  28. "device": "",
  29. "payload": {
  30. "proto": "Account",
  31. "raw": f"{{\"uid\":\"0000000\",\"token\":\"{token}\"}}"
  32. },
  33. "ticket": ticket
  34. })
  35. headers = {
  36. 'DS': '',
  37. 'cookie': '',
  38. 'x-rpc-client_type': '',
  39. 'x-rpc-app_version': '',
  40. 'x-rpc-sys_version': '',
  41. 'x-rpc-channel': 'xiaomi',
  42. 'x-rpc-device_id': '',
  43. 'x-rpc-device_fp': '',
  44. 'x-rpc-device_name': '',
  45. 'x-rpc-device_model': '',
  46. 'Referer': ' https://app.mihoyo.com',
  47. 'Content-Type': 'application/json'
  48. }
  49. conn.request("POST", "/hk4e_cn/combo/panda/qrcode/confirm",
  50. payload, headers)
  51. res = conn.getresponse()

Then confirm the QR code to confirm the login in the game

After starting, a 300x300 pixel box will be displayed in the middle of the screen, put in the QR code and scan the code to log in directly

Because I learned by myself, I won’t make a finished product and optimize it

Okay, enough nonsense here. Here we only provide the idea parameters, which can be obtained by grabbing the packet when scanning the QR code at Miyou Club . Read it yourself if you need it.

  1. import cv2
  2. from pyzbar.pyzbar import decode
  3. import pyzbar.pyzbar as pyzbar
  4. import numpy as np
  5. from PIL import ImageGrab
  6. import time
  7. import tkinter as tk
  8. import threading
  9. import re
  10. import http.client
  11. import json
  12. # 显示框框 启动线程
  13. def my_function():
  14. import juxing
  15. my_thread = threading.Thread(target=my_function)
  16. my_thread.start()
  17. # 获取坐标
  18. root = tk.Tk()
  19. win_width = 300
  20. win_height = 300
  21. screen_width = root.winfo_screenwidth()
  22. screen_height = root.winfo_screenheight()
  23. x_pos = (screen_width // 2) - (win_width // 2)
  24. y_pos = (screen_height // 2) - (win_height // 2)
  25. # 设置扫描区域左上角的坐标和宽高
  26. left, top, width, height = x_pos, y_pos, win_width, win_height
  27. right = left + width
  28. bottom = top + height
  29. # 创建窗口并设置窗口名称
  30. cv2.namedWindow("QR Code Scanner", cv2.WINDOW_NORMAL)
  31. cv2.resizeWindow("QR Code Scanner", win_width, win_height)
  32. # 抢码开始
  33. def Request(ticket):
  34. conn = http.client.HTTPSConnection("api-sdk.mihoyo.com")
  35. payload = json.dumps({
  36. "app_id": 4,
  37. "device": "",
  38. "ticket": ticket
  39. })
  40. headers = {}
  41. conn.request("POST", "/hk4e_cn/combo/panda/qrcode/scan", payload, headers)
  42. res = conn.getresponse()
  43. data = res.read()
  44. data = json.loads(data.decode("utf-8"))
  45. retcode = data["retcode"]
  46. return retcode
  47. # 确认登陆
  48. def ConfirmRequest(ticket):
  49. conn = http.client.HTTPSConnection("api-takumi.miyoushe.com")
  50. payload = ''
  51. headers = {
  52. 'DS': '',
  53. 'cookie': '',
  54. 'x-rpc-client_type': '2',
  55. 'x-rpc-app_version': '2.46.1',
  56. 'x-rpc-sys_version': '9',
  57. 'x-rpc-channel': '',
  58. 'x-rpc-device_id': '',
  59. 'x-rpc-device_fp': '',
  60. 'x-rpc-device_name': '',
  61. 'x-rpc-device_model': '',
  62. 'Referer': ' https://app.mihoyo.co'
  63. }
  64. conn.request("GET", "/auth/api/getGameToken?uid=0000000",
  65. payload, headers)
  66. res = conn.getresponse()
  67. data = res.read()
  68. # print(data.decode("utf-8"))
  69. data = json.loads(data.decode("utf-8"))
  70. token = data["data"]["game_token"]
  71. conn = http.client.HTTPSConnection("api-sdk.mihoyo.com")
  72. payload = json.dumps({
  73. "app_id": 4,
  74. "device": "",
  75. "payload": {
  76. "proto": "Account",
  77. "raw": f"{{\"uid\":\"0000000\",\"token\":\"{token}\"}}"
  78. },
  79. "ticket": ticket
  80. })
  81. headers = {
  82. 'DS': '',
  83. 'cookie': '',
  84. 'x-rpc-client_type': '2',
  85. 'x-rpc-app_version': '2.46.1',
  86. 'x-rpc-sys_version': '9',
  87. 'x-rpc-channel': ' xiaomi',
  88. 'x-rpc-device_id': '',
  89. 'x-rpc-device_fp': '',
  90. 'x-rpc-device_name': '',
  91. 'x-rpc-device_model': '',
  92. 'Referer': ' https://app.mihoyo.com',
  93. 'Content-Type': 'application/json'
  94. }
  95. conn.request("POST", "/hk4e_cn/combo/panda/qrcode/confirm",
  96. payload, headers)
  97. res = conn.getresponse()
  98. # data = res.read()
  99. # print(data.decode("utf-8"))
  100. while True:
  101. # 截取指定区域的屏幕截图
  102. screenshot = cv2.cvtColor(
  103. np.array(ImageGrab.grab(bbox=(left, top, right, bottom))),
  104. cv2.COLOR_BGR2RGB
  105. )
  106. # 将截图转换为灰度图像
  107. gray = cv2.cvtColor(screenshot, cv2.COLOR_RGB2GRAY)
  108. # 尝试使用pyzbar库识别二维码
  109. codes = decode(gray, symbols=[pyzbar.ZBarSymbol.QRCODE])
  110. # 如果找到了二维码,输出其内容
  111. if codes:
  112. print(codes[0].data.decode())
  113. pattern = r"ticket=([a-f0-9]+)"
  114. match = re.search(pattern, codes[0].data.decode())
  115. # 正则请求地址
  116. if match:
  117. start_time = time.time()
  118. # 进入抢码
  119. retcode = Request(match.group(1))
  120. end_time = time.time()
  121. if retcode == 0:
  122. # 计算代码执行时间
  123. elapsed_time = end_time - start_time
  124. # 输出执行时间
  125. print("抢码成功耗时 %.3f 秒" % elapsed_time)
  126. # 确认登陆
  127. ConfirmRequest(match.group(1))
  128. time.sleep(1)
  129. # 等待一段时间再继续扫描
  130. time.sleep(0.05)
  131. # 在窗口中显示截图
  132. cv2.imshow("QR Code Scanner", screenshot)
  133. # 检查是否按下了键盘上的任意键
  134. if cv2.waitKey(1) != -1:
  135.     break
  136. # 关闭窗口
  137. cv2.destroyAllWindows()

Below is the code for the display box part

  1. import tkinter as tk
  2. # 创建一个Tkinter窗口
  3. root = tk.Tk()
  4. # 隐藏窗口标题栏和边框
  5. root.overrideredirect(True)
  6. # 将窗口置顶
  7. root.wm_attributes("-topmost", True)
  8. # 设置窗口大小和位置
  9. win_width = 300
  10. win_height = 300
  11. screen_width = root.winfo_screenwidth()
  12. screen_height = root.winfo_screenheight()
  13. x_pos = (screen_width // 2) - (win_width // 2)
  14. y_pos = (screen_height // 2) - (win_height // 2)
  15. root.geometry('{}x{}+{}+{}'.format(win_width, win_height, x_pos, y_pos))
  16. # 将窗口背景设为透明
  17. root.attributes('-transparentcolor', 'white')
  18. # 将窗口的画布设为透明
  19. canvas = tk.Canvas(root, bg='white', highlightthickness=0)
  20. canvas.pack(fill='both', expand=True)
  21. # 绘制一个绿色空心正方形
  22. canvas.create_rectangle(5, 5, win_width-5, win_height-5, outline='red', width=2)
  23. # 进入循环让窗口保持打开状态
  24. root.mainloop()



Category of website: technical article > Blog

Author:Sweethess

link:http://www.pythonblackhole.com/blog/article/80057/3eeaf4c80d8c57dff0e7/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

10 0
collect article
collected

Comment content: (supports up to 255 characters)