-
Notifications
You must be signed in to change notification settings - Fork 0
/
parental.go
61 lines (52 loc) · 1.93 KB
/
parental.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package api
import (
"encoding/json"
"fmt"
"github.com/shangate/steam-web/status"
"github.com/shangate/steam-web/utils"
"strings"
)
const (
STEAM_PARENTAL_UNLOCK_WEBAPI = STEAM_COMMUNITY_WEB_BASE + "/parental/ajaxunlock"
)
const (
STEAM_PARENTAL_REQUEST_ERROR = iota + 600000
)
type parentalResponse struct {
Success bool `json:"success"`
EResult int `json:"eresult"`
}
func IsNeedParentalLock(session SteamCommunitySession) (bool, *status.Exception) {
headers := getDefaultMobileHeader()
if session.Cookies == nil {
session.Cookies = getSteamAuthCookies(session)
}
_, _, _, responseData, _, httpError := utils.HttpWebRequest("GET", STEAM_STORE_WEB_BASE, headers, nil, session.Cookies, nil, false, false)
if httpError != nil {
return false, status.NewError(STEAM_PARENTAL_REQUEST_ERROR, fmt.Sprintf("unlock parental lock error %s", httpError.Error()))
}
return strings.Contains(string(responseData), "家庭监护") || strings.Contains(string(responseData), "Family View"), nil
}
func UnlockParentalLock(session *SteamCommunitySession, code string) (bool, *status.Exception) {
headers := getDefaultMobileHeader()
if session.Cookies == nil {
session.Cookies = getSteamAuthCookies(*session)
}
query := map[string][]string{
"pin": {code},
"sessionid": {session.SessionId},
}
_, _, _, responseData, responseCookies, httpError := utils.HttpWebRequest("POST", STEAM_PARENTAL_UNLOCK_WEBAPI, headers, query, session.Cookies, nil, false, false)
if httpError != nil {
return false, status.NewError(STEAM_PARENTAL_REQUEST_ERROR, fmt.Sprintf("unlock parental lock error %s", httpError.Error()))
}
var response parentalResponse
e := json.Unmarshal(responseData, &response)
if e != nil {
return false, status.NewError(STEAM_PARENTAL_REQUEST_ERROR, fmt.Sprintf("unlock parental lock error %s", e.Error()))
}
if response.Success {
session.Cookies = append(session.Cookies, responseCookies...)
}
return response.Success, nil
}