Skip to content

Commit 1fa0e14

Browse files
WalleVWalle
and
Walle
authored
Develop (#53)
* fix groupWelcomeTemplate to message * refact(wecom): server define event interface * refactor(wecom): message callback with request object * refactor(wecom) server post callback * refactor(wecom): callback interface and decryptMessage * refactor(wecom): switch callback event * refactor(wecom): switch callback message * feat(wecom): user callback notify * feat(wecom): add card invoice struct * refactor(payment): update refund struct * feat(wecom): add card invoice struct * feat(gomod): update go-libs * fix(socalite): update go-socalite version (#51) Co-authored-by: Walle <walle@artisan-cloud.com>
1 parent 87ccdca commit 1fa0e14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1637
-211
lines changed

go.mod

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ module github.com/ArtisanCloud/power-wechat
22

33
go 1.16
44

5-
//replace github.com/ArtisanCloud/power-wechat => ../power-wechat
6-
//replace github.com/ArtisanCloud/go-libs => ../go-libs
7-
//replace github.com/ArtisanCloud/go-socialite => ../go-socialite
8-
95
require (
10-
github.com/ArtisanCloud/go-libs v1.1.4
11-
github.com/ArtisanCloud/go-socialite v1.0.8
6+
github.com/ArtisanCloud/go-libs v1.1.5
7+
github.com/ArtisanCloud/go-socialite v1.0.9
128
github.com/gin-gonic/gin v1.7.2
139
github.com/go-playground/assert/v2 v2.0.1
1410
github.com/go-playground/validator/v10 v10.6.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/ArtisanCloud/go-libs v1.0.19/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
2-
github.com/ArtisanCloud/go-libs v1.1.4 h1:bnYGifU+xVqyqrAZIEjjPYcsOsMEs4S5wBaZuWRcRHs=
3-
github.com/ArtisanCloud/go-libs v1.1.4/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
4-
github.com/ArtisanCloud/go-socialite v1.0.8 h1:eugkAA9SvXxltUw5wBZP1RWBva80jAHO4MykWRevCPg=
5-
github.com/ArtisanCloud/go-socialite v1.0.8/go.mod h1:dtDCF49NdzsKEd+nKm6ytv5cVaAfM3O8Hl7fml4K+E4=
2+
github.com/ArtisanCloud/go-libs v1.1.5 h1:yESm+lNPD97JRwUKSeY0ZwNUe0mVtHgZhaHyy7lYKzY=
3+
github.com/ArtisanCloud/go-libs v1.1.5/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
4+
github.com/ArtisanCloud/go-socialite v1.0.9 h1:GEE0zjxMhmnXYG8j8ljvWzgX/jNtvvTQLflGnbLNDAc=
5+
github.com/ArtisanCloud/go-socialite v1.0.9/go.mod h1:dtDCF49NdzsKEd+nKm6ytv5cVaAfM3O8Hl7fml4K+E4=
66
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
77
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
88
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

src/kernel/baseClient.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/ArtisanCloud/go-libs/http/request"
77
"github.com/ArtisanCloud/go-libs/http/response"
88
"github.com/ArtisanCloud/go-libs/object"
9+
response2 "github.com/ArtisanCloud/power-wechat/src/kernel/response"
910
"github.com/ArtisanCloud/power-wechat/src/kernel/support"
1011
"github.com/google/uuid"
1112
http2 "net/http"
@@ -18,6 +19,8 @@ type BaseClient struct {
1819

1920
*support.ResponseCastable
2021

22+
ExternalRequest *http2.Request
23+
2124
App *ApplicationInterface
2225
Token *AccessToken
2326
}
@@ -137,13 +140,14 @@ func (client *BaseClient) Request(url string, method string, options *object.Has
137140
return response, err
138141
} else {
139142
// tbf
140-
config := *(*client.App).GetConfig()
141143
var rs http2.Response = http2.Response{
142144
StatusCode: response.GetStatusCode(),
143145
Header: response.GetHeader(),
144146
Body: response.GetBody(),
145147
}
146-
returnResponse, err := client.CastResponseToType(&rs, config.GetString("response_type", "array"))
148+
//config := *(*client.App).GetConfig()
149+
//returnResponse, err := client.CastResponseToType(&rs, config.GetString("response_type", "array"))
150+
returnResponse, err := client.CastResponseToType(&rs, response2.TYPE_RAW)
147151
return returnResponse, err
148152
}
149153
}

src/kernel/contract/eventHandlerInterface.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/kernel/contract/eventInterface.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package contract
2+
3+
4+
5+
type EventInterface interface {
6+
GetToUserName() string
7+
GetFromUserName() string
8+
GetCreateTime() string
9+
GetMsgType() string
10+
GetEvent() string
11+
GetChangeType() string
12+
}
13+
14+
15+
type EventHandlerInterface interface {
16+
Handle(header EventInterface, content interface{}) interface{}
17+
}

src/kernel/models/callback.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package models
2+
3+
import (
4+
"encoding/xml"
5+
"github.com/ArtisanCloud/power-wechat/src/kernel/contract"
6+
)
7+
8+
type Callback struct {
9+
XMLName xml.Name `xml:"xml"`
10+
Text string `xml:",chardata"`
11+
ToUserName string `xml:"ToUserName"`
12+
AgentID string `xml:"AgentID"`
13+
Encrypt string `xml:"Encrypt"`
14+
}
15+
16+
const (
17+
CALLBACK_MSG_TYPE_EVENT = "event"
18+
CALLBACK_MSG_TYPE_TEXT = "text"
19+
CALLBACK_MSG_TYPE_IMAGE = "image"
20+
CALLBACK_MSG_TYPE_VOICE = "voice"
21+
CALLBACK_MSG_TYPE_VIDEO = "video"
22+
CALLBACK_MSG_TYPE_LOCATION = "location"
23+
CALLBACK_MSG_TYPE_LINK = "link"
24+
)
25+
26+
type CallbackMessageHeader struct {
27+
contract.EventInterface
28+
XMLName xml.Name `xml:"xml"`
29+
Text string `xml:",chardata"`
30+
ToUserName string `xml:"ToUserName"`
31+
FromUserName string `xml:"FromUserName"`
32+
CreateTime string `xml:"CreateTime"`
33+
MsgType string `xml:"MsgType"`
34+
Event string `xml:"Event"`
35+
ChangeType string `xml:"ChangeType"`
36+
}
37+
38+
func (header CallbackMessageHeader) GetToUserName() string {
39+
return header.ToUserName
40+
}
41+
42+
func (header CallbackMessageHeader) GetFromUserName() string {
43+
return header.FromUserName
44+
}
45+
46+
func (header CallbackMessageHeader) GetCreateTime() string {
47+
return header.CreateTime
48+
}
49+
50+
func (header CallbackMessageHeader) GetMsgType() string {
51+
return header.MsgType
52+
}
53+
54+
func (header CallbackMessageHeader) GetEvent() string {
55+
return header.Event
56+
}
57+
58+
func (header CallbackMessageHeader) GetChangeType() string {
59+
return header.ChangeType
60+
}

src/kernel/response/wx.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package response
22

33
type ResponseWork struct {
4-
ErrCode int `json:"errcode,omitempty"`
4+
ErrCode int `json:"errcode"`
55
ErrMSG string `json:"errmsg,omitempty"`
66
}
77

88
type ResponsePayment struct {
9-
ReturnCode string `json:"return_code,omitempty"`
9+
ReturnCode string `json:"return_code"`
1010
ReturnMSG string `json:"return_msg,omitempty"`
1111

12-
ResultCode string `json:"result_code,omitempty"` // 是 String(16) SUCCESS/FAIL
12+
ResultCode string `json:"result_code"` // 是 String(16) SUCCESS/FAIL
1313
ErrCode string `json:"err_code,omitempty"` // 否 String(32) SYSTEMERROR--系统错误
1414
ErrMSG string `json:"errmsg,omitempty"`
1515
ErrCodeDes string `json:"err_code_des,omitempty"`
@@ -20,18 +20,23 @@ type ResponseMiniProgram struct {
2020
ErrCode int `json:"errcode"`
2121
ErrMSG string `json:"errmsg,omitempty"`
2222

23-
ResultCode string `json:"resultcode,omitempty"`
23+
ResultCode string `json:"resultcode"`
2424
ResultMSG string `json:"resultmsg,omitempty"`
2525
}
2626

2727
type ResponseOfficialAccount struct {
2828
ErrCode int `json:"errcode"`
2929
ErrMSG string `json:"errmsg,omitempty"`
3030

31-
ResultCode string `json:"resultcode,omitempty"`
31+
ResultCode string `json:"resultcode"`
3232
ResultMSG string `json:"resultmsg,omitempty"`
3333
}
3434

35+
const (
36+
TYPE_RAW = "raw"
37+
TYPE_MAP = "map"
38+
)
39+
3540
//
3641
//func (res *ResponseWork) GetBody() *http.ResponseWriter {
3742
// return nil

0 commit comments

Comments
 (0)