Fix add item for roblox update
This commit is contained in:
parent
85aadb514b
commit
aa0b5d59fa
43
item.go
43
item.go
@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Item struct containing data on retrieved items
|
// Item struct containing data on retrieved items
|
||||||
@ -40,25 +41,43 @@ func (s *Session) HasItem(id int) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddItem add item by id to inventory
|
// AddItem add item by id to inventory
|
||||||
func (s *Session) AddItem(id int, seller int) error {
|
func (s *Session) AddItem(id int) error {
|
||||||
v := url.Values{}
|
product, err := s.GetProduct(id)
|
||||||
v.Set("rqtype", "purchase")
|
|
||||||
v.Set("productID", strconv.Itoa(id))
|
|
||||||
v.Set("expectedCurrency", "1")
|
|
||||||
v.Set("expectedPrice", "0")
|
|
||||||
v.Set("expectedSellerID", strconv.Itoa(seller))
|
|
||||||
v.Set("userAssetID", "")
|
|
||||||
resp, err := s.client.Post("https://www.roblox.com/api/item.ashx?"+v.Encode(), "application/json", bytes.NewBufferString(""))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload := struct {
|
||||||
|
ExpectedCurrency int `json:"expectedCurrency"`
|
||||||
|
ExpectedPrice int `json:"expectedPrice"`
|
||||||
|
ExpectedSellerID int `json:"expectedSellerId"`
|
||||||
|
}{
|
||||||
|
ExpectedCurrency: 1,
|
||||||
|
ExpectedPrice: 0,
|
||||||
|
ExpectedSellerID: product.Creator.ID,
|
||||||
|
}
|
||||||
|
// Gen json body
|
||||||
|
data, err := json.Marshal(&payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", fmt.Sprintf("https://economy.roblox.com/v1/purchases/products/%d", product.ProductID), bytes.NewBuffer(data))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
resp, err := s.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == 403 {
|
if resp.StatusCode == 403 {
|
||||||
req, err := http.NewRequest("POST", "https://www.roblox.com/api/item.ashx?"+v.Encode(), bytes.NewBufferString(""))
|
req, err := http.NewRequest("POST", fmt.Sprintf("https://economy.roblox.com/v1/purchases/products/%d", product.ProductID), bytes.NewBuffer(data))
|
||||||
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
|
||||||
|
|
||||||
resp, err := s.client.Do(req)
|
resp, err := s.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -87,7 +106,7 @@ func (s *Session) RemoveItem(id int) error {
|
|||||||
|
|
||||||
if resp.StatusCode == 403 {
|
if resp.StatusCode == 403 {
|
||||||
req, err := http.NewRequest("POST", "https://www.roblox.com/asset/delete-from-inventory", bytes.NewBufferString(v.Encode()))
|
req, err := http.NewRequest("POST", "https://www.roblox.com/asset/delete-from-inventory", bytes.NewBufferString(v.Encode()))
|
||||||
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
|
req.Header.Set("x-csrf-token", strings.Trim(resp.Header["X-Csrf-Token"][0], " "))
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
resp, err := s.client.Do(req)
|
resp, err := s.client.Do(req)
|
||||||
|
@ -24,6 +24,7 @@ func New(cookie string) (*Session, error) {
|
|||||||
// url.Parse("http://www.roblox.com") // http://api.roblox.com
|
// url.Parse("http://www.roblox.com") // http://api.roblox.com
|
||||||
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "www.roblox.com"}, rbxCookie)
|
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "www.roblox.com"}, rbxCookie)
|
||||||
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "api.roblox.com"}, rbxCookie)
|
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "api.roblox.com"}, rbxCookie)
|
||||||
|
cookieJar.SetCookies(&url.URL{Scheme: "https", Host: "economy.roblox.com"}, rbxCookie)
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Jar: cookieJar,
|
Jar: cookieJar,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user