-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbill.go
51 lines (40 loc) · 1017 Bytes
/
bill.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
package feidee
import (
//"encoding/json"
"fmt"
"net/url"
"strconv"
"time"
"io/ioutil"
)
// 周期账手动入账
func (cli *Client) BillEntry(id int, day time.Time, money float64) (string, error) {
data := url.Values{}
data.Set("opt", "entry")
data.Set("id", strconv.Itoa(id))
data.Set("date", day.Format("2006.1.2"))
data.Set("money", strconv.FormatFloat(money, 'f', -1, 32))
fmt.Printf("%#v", data)
resp, err := cli.PostForm(BaseUrl+"/bill/index.rmi", data)
if err != nil {
return "", fmt.Errorf("请求出错: %s", err)
}
defer resp.Body.Close()
//返回结果是{result:'false'}或者{result:money}
//不是合法的JSON格式
//var respInfo struct{
// Id int
// ErrorInfo string
// Result string
//}
//err = json.NewDecoder(resp.Body).Decode(&respInfo)
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("读取出错: %s", err)
}
str := string(b)
if str == "{result:'false'}" {
return "", fmt.Errorf("失败: %s", str)
}
return str, nil
}