Skip to content

Commit d1b5875

Browse files
committed
support OpenService API
1 parent d7219bb commit d1b5875

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# MNS GO SDK
2+
1.0.2
3+
- support OpenService API
4+
25
1.0.1
36
- support setting timeout
47
- add request id to response

account_manager.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ali_mns
2+
3+
import "encoding/xml"
4+
5+
type AccountManager struct {
6+
cli MNSClient
7+
decoder MNSDecoder
8+
}
9+
10+
type OpenService struct {
11+
BaseResponse
12+
XMLName xml.Name `xml:"OpenService" json:"-"`
13+
OrderId string `xml:"OrderId" json:"order_id"`
14+
}
15+
16+
func NewAccountManager(client MNSClient) *AccountManager {
17+
return &AccountManager{
18+
cli: client,
19+
decoder: NewAliMNSDecoder(),
20+
}
21+
}
22+
23+
func (p *AccountManager) OpenService() (attr OpenService, err error) {
24+
_, err = send(p.cli, p.decoder, POST, nil, nil, "commonbuy/openservice", &attr)
25+
return
26+
}

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
)
3333

3434
const (
35-
ClientName = "mns-go-sdk/1.0.1(fasthttp)"
35+
ClientName = "mns-go-sdk/1.0.2(fasthttp)"
3636
DefaultTimeout int64 = 35
3737
)
3838

example/open_service_example.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
8+
ali_mns "github.com/aliyun/aliyun-mns-go-sdk"
9+
)
10+
11+
type appConf struct {
12+
Url string `json:"url"`
13+
AccessKeyId string `json:"access_key_id"`
14+
AccessKeySecret string `json:"access_key_secret"`
15+
}
16+
17+
func main() {
18+
conf := appConf{}
19+
20+
if bFile, e := ioutil.ReadFile("app.conf"); e != nil {
21+
panic(e)
22+
} else {
23+
if e := json.Unmarshal(bFile, &conf); e != nil {
24+
panic(e)
25+
}
26+
}
27+
28+
client := ali_mns.NewAliMNSClient(conf.Url,
29+
conf.AccessKeyId,
30+
conf.AccessKeySecret)
31+
32+
if resp, err := ali_mns.NewAccountManager(client).OpenService(); err != nil {
33+
fmt.Println(err)
34+
} else {
35+
fmt.Printf("reqId:%s, orderId:%s", resp.RequestId, resp.OrderId)
36+
}
37+
}

0 commit comments

Comments
 (0)