-
Notifications
You must be signed in to change notification settings - Fork 171
/
scanned.go
58 lines (46 loc) · 1.38 KB
/
scanned.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
package notify
import (
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/notify/request"
"net/http"
"reflect"
)
type Scanned struct {
*Handler
alert string
}
func NewScannedNotify(app kernel.ApplicationPaymentInterface, request *http.Request) *Scanned {
scanned := &Scanned{
NewHandler(&app, request),
"",
}
scanned.Check = false
return scanned
}
func (comp *Scanned) Alert(message string) {
comp.alert = message
}
func (comp *Scanned) Handle(closure func(message *request.RequestNotify, fail func(message string), alert func(message string)) interface{}) (*http.Response, error) {
message, err := comp.GetMessage()
if err != nil {
return nil, err
}
result := closure(message, comp.Fail, comp.Alert)
resultCode := FAIL
if comp.alert == "" && comp.fail == "" {
resultCode = SUCCESS
}
attributes := &object.StringMap{
"result_code": resultCode,
"err_code_des": comp.alert,
}
if comp.alert == "" && reflect.TypeOf(result).Name() == "string" {
config := (*comp.App).GetConfig()
(*attributes)["appid"] = config.GetString("app_id", "")
(*attributes)["mch_id"] = config.GetString("mch_id", "")
(*attributes)["nonce_str"] = object.UniqueID("")
(*attributes)["prepay_id"] = result.(string)
}
return comp.RespondWith(attributes, true).ToResponse()
}