forked from go-http/feidee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
50 lines (44 loc) · 1.14 KB
/
account.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
package feidee
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"strconv"
"strings"
)
type AccountInfo struct {
Id int64
Name string
// 账户当前余额
Money float64
Currency string
}
//刷新账户余额
func (cli *Client) SyncAccountInfoList() error {
resp, err := cli.Get(BaseUrl + "/account/account.do")
if err != nil {
return fmt.Errorf("请求出错: %s", err)
}
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return fmt.Errorf("读取出错: %s", err)
}
for _, account := range cli.Accounts {
idStr := fmt.Sprintf("#acc-money-%d", account.Id)
selection := doc.Find(idStr)
moneySelection := selection.Find(".child-r1-money")
money, err := strconv.ParseFloat(strings.ReplaceAll(moneySelection.Text(), ",", ""), 64)
if err != nil {
return fmt.Errorf("读取账户余额出错: %s", err)
}
currencySelection := selection.Find(".child-r1-currency")
accountId := int64(account.Id)
cli.AccountInfoMap[accountId] = AccountInfo{
Id: int64(account.Id),
Name: account.Name,
Money: money,
Currency: currencySelection.Text(),
}
}
return nil
}