-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsclient.go
More file actions
93 lines (76 loc) · 1.82 KB
/
Copy pathwsclient.go
File metadata and controls
93 lines (76 loc) · 1.82 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package wsclient
import (
"encoding/xml"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
)
type Client struct {
*http.Client
}
func NewClient(tr *http.Transport) *Client {
var c *http.Client
if tr == nil {
c = http.DefaultClient
} else {
c = &http.Client{
Transport: tr,
}
}
return &Client{
Client: c,
}
}
const (
apiEndpoint = "http://211.88.20.132:8040/services/syncServiceStation?wsdl"
)
func (this *Client) Do(in interface{}) (body []byte, err error) {
payload, err := toPayload(in)
if err != nil {
return
}
req, err := http.NewRequest(http.MethodPost, apiEndpoint, payload)
if err != nil {
return
}
req.Header.Set("Content-Type", "text/xml;charset=UTF-8")
req.Header.Set("Accept", "application/soap+xml, application/dime, multipart/related, text/*")
req.Header.Set("User-Agent", "Axis/1.4")
req.Header.Set("Host", "211.88.20.132:8040")
req.Header.Set("SOAPAction", "http://www.cvicse.com/service/syncServiceStationOperation")
resp, err := this.Client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}
if resp.StatusCode/100 != 2 {
err = errors.New(string(body))
return
}
return
}
func toPayload(in interface{}) (reader io.Reader, err error) {
buf, err := xml.Marshal(in)
if err != nil {
return
}
reader = strings.NewReader(fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<syncServiceStationOperationRequest xmlns="http://www.cvicse.com/service/">
<in xmlns="">
%s
</in>
</syncServiceStationOperationRequest>
</soapenv:Body>
</soapenv:Envelope>
`, string(buf)))
return
}