fix(handshake): apply dynamic store.SetWAVersion and UserAgent to prevent 405 error
This commit is contained in:
1 parent
70ecc1746c
commit
91c1d0697f
1 file changed
+22
-11
@@ -376,19 +376,10 @@ func (w whatsmeowService) StartClient(cd *ClientData) {
|
|||||||
store.DeviceProps.RequireFullSync = proto.Bool(true)
|
store.DeviceProps.RequireFullSync = proto.Bool(true)
|
||||||
|
|
||||||
if w.config.WhatsappVersionMajor != 0 && w.config.WhatsappVersionMinor != 0 && w.config.WhatsappVersionPatch != 0 {
|
if w.config.WhatsappVersionMajor != 0 && w.config.WhatsappVersionMinor != 0 && w.config.WhatsappVersionPatch != 0 {
|
||||||
w.loggerWrapper.GetLogger(cd.Instance.Id).LogInfo("[%s] Setting whatsapp version to %d.%d.%d", cd.Instance.Id, w.config.WhatsappVersionMajor, w.config.WhatsappVersionMinor, w.config.WhatsappVersionPatch)
|
w.loggerWrapper.GetLogger(cd.Instance.Id).LogInfo("[%s] Setting whatsapp version from config to %d.%d.%d", cd.Instance.Id, w.config.WhatsappVersionMajor, w.config.WhatsappVersionMinor, w.config.WhatsappVersionPatch)
|
||||||
version.Major = w.config.WhatsappVersionMajor
|
version.Major = w.config.WhatsappVersionMajor
|
||||||
if err == nil {
|
|
||||||
store.DeviceProps.Version.Primary = proto.Uint32(uint32(version.Major))
|
|
||||||
}
|
|
||||||
version.Minor = w.config.WhatsappVersionMinor
|
version.Minor = w.config.WhatsappVersionMinor
|
||||||
if err == nil {
|
|
||||||
store.DeviceProps.Version.Secondary = proto.Uint32(uint32(version.Minor))
|
|
||||||
}
|
|
||||||
version.Patch = w.config.WhatsappVersionPatch
|
version.Patch = w.config.WhatsappVersionPatch
|
||||||
if err == nil {
|
|
||||||
store.DeviceProps.Version.Tertiary = proto.Uint32(uint32(version.Patch))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Try to fetch version from WhatsApp Web
|
// Try to fetch version from WhatsApp Web
|
||||||
webVersion, err := fetchWhatsAppWebVersion()
|
webVersion, err := fetchWhatsAppWebVersion()
|
||||||
@@ -397,11 +388,24 @@ func (w whatsmeowService) StartClient(cd *ClientData) {
|
|||||||
} else {
|
} else {
|
||||||
w.loggerWrapper.GetLogger(cd.Instance.Id).LogInfo("[%s] Setting whatsapp version from web to %d.%d.%d", cd.Instance.Id, webVersion.Major, webVersion.Minor, webVersion.Patch)
|
w.loggerWrapper.GetLogger(cd.Instance.Id).LogInfo("[%s] Setting whatsapp version from web to %d.%d.%d", cd.Instance.Id, webVersion.Major, webVersion.Minor, webVersion.Patch)
|
||||||
version = *webVersion
|
version = *webVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if version.Major != 0 && version.Minor != 0 && version.Patch != 0 {
|
||||||
store.DeviceProps.Version.Primary = proto.Uint32(uint32(version.Major))
|
store.DeviceProps.Version.Primary = proto.Uint32(uint32(version.Major))
|
||||||
store.DeviceProps.Version.Secondary = proto.Uint32(uint32(version.Minor))
|
store.DeviceProps.Version.Secondary = proto.Uint32(uint32(version.Minor))
|
||||||
store.DeviceProps.Version.Tertiary = proto.Uint32(uint32(version.Patch))
|
store.DeviceProps.Version.Tertiary = proto.Uint32(uint32(version.Patch))
|
||||||
|
waVer := store.WAVersionContainer{uint32(version.Major), uint32(version.Minor), uint32(version.Patch)}
|
||||||
|
store.SetWAVersion(waVer)
|
||||||
|
if store.BaseClientPayload != nil && store.BaseClientPayload.UserAgent != nil {
|
||||||
|
store.BaseClientPayload.UserAgent.AppVersion = &waProto.ClientPayload_UserAgent_AppVersion{
|
||||||
|
Primary: proto.Uint32(uint32(version.Major)),
|
||||||
|
Secondary: proto.Uint32(uint32(version.Minor)),
|
||||||
|
Tertiary: proto.Uint32(uint32(version.Patch)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.loggerWrapper.GetLogger(cd.Instance.Id).LogInfo("[%s] Applied WhatsApp handshake version %d.%d.%d", cd.Instance.Id, version.Major, version.Minor, version.Patch)
|
||||||
|
}
|
||||||
|
|
||||||
// 🔒 FIX: Sempre criar logger, mesmo que WaDebug esteja vazio
|
// 🔒 FIX: Sempre criar logger, mesmo que WaDebug esteja vazio
|
||||||
// Usar "INFO" como nível mínimo para garantir que logs importantes apareçam
|
// Usar "INFO" como nível mínimo para garantir que logs importantes apareçam
|
||||||
@@ -2618,7 +2622,14 @@ func fetchWhatsAppWebVersion() (*clientVersion, error) {
|
|||||||
return cachedWebVersion, nil
|
return cachedWebVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get("https://web.whatsapp.com/sw.js")
|
req, err := http.NewRequest("GET", "https://web.whatsapp.com/sw.js", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create request for WhatsApp Web version: %v", err)
|
||||||
|
}
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
httpClient := &http.Client{Timeout: 10 * time.Second}
|
||||||
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to fetch WhatsApp Web version: %v", err)
|
return nil, fmt.Errorf("failed to fetch WhatsApp Web version: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user