-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.go
122 lines (103 loc) · 2.31 KB
/
test.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"encoding/json"
"fmt"
"github.com/cliod/wx-go/ma"
"github.com/cliod/wx-go/mp"
"github.com/cliod/wx-go/pay"
"math/rand"
"strconv"
"time"
)
func maTest(c Config) {
service := ma.NewWxMaServiceBy(c.AppId, c.Secret)
qc := service.GetWxMaQrcodeService()
bytes, err := qc.CreateQrcode("/pages/index")
if err == nil {
err = qc.(*ma.WxMaQrCodeServiceImpl).BytesToFile("tmp.jpg", bytes)
if err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println(err.Error())
}
uc := service.GetWxMaUserService()
res, err := uc.GetSessionInfo("<js_code>")
if err == nil {
r, err := json.Marshal(res)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(r))
}
} else {
fmt.Println(err.Error())
}
}
func mpTest(c Config) {
service := mp.NewWxMpServiceBy(c.AppId, c.Secret)
da, err := service.CreateJsapiSignature("https://www.baidu.com")
if err == nil {
r, err := json.Marshal(da)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(r))
}
} else {
fmt.Println(err.Error())
}
qc := service.GetWxMpQrcodeService()
bytes, err := qc.QrcodeCreateTmpTicket(mp.QrScene, "/pages/index", 0, 30)
if err == nil {
r, err := json.Marshal(bytes)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(r))
}
} else {
fmt.Println(err.Error())
}
uc := service.GetWxMpUserService()
res, err := uc.GetUserInfo(c.Openid)
if err == nil {
r, err := json.Marshal(res)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(r))
}
} else {
fmt.Println(err.Error())
}
}
func payTest(c Config) {
conf := pay.NewWxPayV2Config(c.AppId, c.MchId, c.MchKey, "https://www.baidu.com/notify", "")
//conf.UseSandboxEnv = true
service := pay.NewWxPayService(conf)
s := strconv.Itoa(time.Now().Nanosecond()) + strconv.Itoa(rand.Intn(999999))
fmt.Println(s)
res, err := service.UnifyPay(&pay.WxPayUnifiedOrderRequest{
TotalFee: 100,
Openid: c.Openid,
OutTradeNo: s,
Body: "测试数据",
})
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(res))
}
d, err := service.CloseOrderBy(s)
if err != nil {
fmt.Println(err.Error())
} else {
res, err = json.Marshal(d)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(res))
}
}
}