|
@@ -11,6 +11,8 @@ import (
|
11
|
11
|
"wechat-conf/service/wechat"
|
12
|
12
|
"wechat-conf/utils"
|
13
|
13
|
|
|
14
|
+ "github.com/astaxie/beego"
|
|
15
|
+
|
14
|
16
|
"github.com/kinisky564477/wechat/component"
|
15
|
17
|
|
16
|
18
|
"github.com/zjxpcyc/wechat/core"
|
|
@@ -40,40 +42,54 @@ const (
|
40
|
42
|
|
41
|
43
|
// ComponentPush 第三方平台推送
|
42
|
44
|
func (c *WechatController) ComponentPush() {
|
|
45
|
+ utils.LogError("推送开始")
|
43
|
46
|
r := c.Ctx.Request
|
44
|
47
|
defer r.Body.Close()
|
45
|
48
|
con, _ := ioutil.ReadAll(r.Body)
|
|
49
|
+ beego.Error(string(con))
|
|
50
|
+ // 解析xml
|
|
51
|
+ xp := &core.XMLParse{}
|
|
52
|
+ resMsg, err := xp.Parse(string(con))
|
|
53
|
+ if err != nil {
|
|
54
|
+ utils.LogError("xml解析失败:", err)
|
|
55
|
+ c.ResponseRaw([]byte("success"))
|
|
56
|
+ }
|
|
57
|
+ utils.LogError("解析xml成功:", resMsg)
|
|
58
|
+ encrypt := resMsg["Encrypt"]
|
|
59
|
+ beego.Error(encrypt)
|
46
|
60
|
conf, err := c.wechatServ.GetComponentInfo()
|
47
|
61
|
if err != nil || conf == nil || conf.Appid == "" {
|
48
|
62
|
utils.LogError("读取微信配置文件失败")
|
49
|
|
- c.ResponseRaw([]byte(""))
|
|
63
|
+ c.ResponseRaw([]byte("success"))
|
50
|
64
|
}
|
|
65
|
+ beego.Error(conf.Aeskey)
|
51
|
66
|
EncodingAESKey := conf.Aeskey
|
52
|
67
|
|
53
|
68
|
AESKey, err := base64.StdEncoding.DecodeString(EncodingAESKey + "=")
|
54
|
69
|
if err != nil {
|
55
|
70
|
utils.LogError("DecodeString失败:", err)
|
56
|
|
- c.ResponseRaw([]byte(""))
|
|
71
|
+ c.ResponseRaw([]byte("success"))
|
57
|
72
|
}
|
58
|
|
- xp := &core.XMLParse{}
|
59
|
|
- // 解析xml
|
60
|
|
- val, err := xp.Parse(string(con))
|
|
73
|
+ beego.Error(AESKey)
|
|
74
|
+ EncryptVal, err := base64.StdEncoding.DecodeString(encrypt)
|
61
|
75
|
if err != nil {
|
62
|
|
- utils.LogError("xml解析失败:", err)
|
63
|
|
- c.ResponseRaw([]byte(""))
|
|
76
|
+ utils.LogError("密文解析失败:", err)
|
|
77
|
+ c.ResponseRaw([]byte("success"))
|
64
|
78
|
}
|
65
|
|
-
|
66
|
|
- msgbyte, err := utils.AesDecrypt([]byte(val["Encrypt"]), AESKey)
|
|
79
|
+ msgbyte, err := utils.AesDecrypt(EncryptVal, AESKey)
|
67
|
80
|
if err != nil {
|
68
|
81
|
utils.LogError("解密失败:", err)
|
69
|
|
- c.ResponseRaw([]byte(""))
|
|
82
|
+ c.ResponseRaw([]byte("success"))
|
70
|
83
|
}
|
|
84
|
+ beego.Error("解密数据:", string(msgbyte))
|
|
85
|
+ beego.Error("解密成功")
|
|
86
|
+ // 解析xml
|
71
|
87
|
msg, err := xp.Parse(string(msgbyte))
|
72
|
88
|
if err != nil {
|
73
|
|
- utils.LogError("msgxml解析失败:", err)
|
74
|
|
- c.ResponseRaw([]byte(""))
|
|
89
|
+ utils.LogError("xml解析失败:", err)
|
|
90
|
+ c.ResponseRaw([]byte("success"))
|
75
|
91
|
}
|
76
|
|
- utils.LogError("接收微信推送消息:", msg)
|
|
92
|
+ beego.Error("解析xml成功:", msg)
|
77
|
93
|
switch msg["InfoType"] {
|
78
|
94
|
case INFOTYPE_TICKET:
|
79
|
95
|
// 更新ticket
|
|
@@ -102,9 +118,8 @@ func (c *WechatController) ComponentPush() {
|
102
|
118
|
err := c.wechatServ.SaveWechatConf(conf)
|
103
|
119
|
if err != nil {
|
104
|
120
|
utils.LogError("保存微信授权信息失败:", err)
|
105
|
|
- c.ResponseRaw([]byte(""))
|
|
121
|
+ c.ResponseRaw([]byte("success"))
|
106
|
122
|
}
|
107
|
|
- c.ResponseRaw([]byte("success"))
|
108
|
123
|
break
|
109
|
124
|
case INFOTYPE_UPDATEAUTHORIZED:
|
110
|
125
|
// 授权更新
|
|
@@ -113,6 +128,7 @@ func (c *WechatController) ComponentPush() {
|
113
|
128
|
// 取消授权
|
114
|
129
|
break
|
115
|
130
|
}
|
|
131
|
+ c.ResponseRaw([]byte("success"))
|
116
|
132
|
}
|
117
|
133
|
|
118
|
134
|
// WechatInfo 微信接入
|