|
@@ -1,9 +1,13 @@
|
|
1
|
+// 微信全网接入测试
|
|
2
|
+// https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&token=&lang=zh_CN
|
|
3
|
+
|
1
|
4
|
package controllers
|
2
|
5
|
|
3
|
6
|
import (
|
4
|
7
|
"bytes"
|
5
|
8
|
"encoding/base64"
|
6
|
9
|
"encoding/json"
|
|
10
|
+ "errors"
|
7
|
11
|
"net/http"
|
8
|
12
|
"strings"
|
9
|
13
|
"wechat-conf/models"
|
|
@@ -40,6 +44,10 @@ const (
|
40
|
44
|
WX_OFFICE_TEST_USERNAME = "gh_3c884a361561"
|
41
|
45
|
)
|
42
|
46
|
|
|
47
|
+const (
|
|
48
|
+ RESPONSE_CUSTOM_MESSAGE = "response-custom-message"
|
|
49
|
+)
|
|
50
|
+
|
43
|
51
|
var nilData = []byte("success")
|
44
|
52
|
|
45
|
53
|
// Constructor 初始化 Controller
|
|
@@ -220,6 +228,14 @@ func (c *WechatController) WxReceive() {
|
220
|
228
|
|
221
|
229
|
// 获取返回内容
|
222
|
230
|
replyMessage, err := c.getReplayMessage(receiveData, wechat)
|
|
231
|
+ if err != nil && err.Error() == RESPONSE_CUSTOM_MESSAGE {
|
|
232
|
+ // 微信测试用例会跑到这边
|
|
233
|
+ // 模拟粉丝发送消息, 并立即调用客户接口, 反馈固定的字串
|
|
234
|
+ go wechat.SendCustomText(receiveData["FromUserName"], wechat.GetAuthCode()+"_from_api")
|
|
235
|
+
|
|
236
|
+ c.ResponseRaw(nil)
|
|
237
|
+ }
|
|
238
|
+
|
223
|
239
|
if err != nil || replyMessage == nil || len(replyMessage) == 0 {
|
224
|
240
|
c.ResponseRaw(nilData)
|
225
|
241
|
}
|
|
@@ -294,7 +310,6 @@ func (c *WechatController) validReceiveData(receiveData []byte, aesKey string, w
|
294
|
310
|
// encryptReceiveMessage 加密需要发送的信息
|
295
|
311
|
func (c *WechatController) encryptMessage(message []byte, aesKey, token, appID string, wechat *component.WxClient) ([]byte, error) {
|
296
|
312
|
cipher, err := core.NewCipher(token, aesKey, appID)
|
297
|
|
- // cipher, err := core.NewCipher("pamtest", "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG", "wxb11529c136998cb6")
|
298
|
313
|
if err != nil {
|
299
|
314
|
utils.LogError("NewCipher 失败: " + err.Error())
|
300
|
315
|
return nil, err
|
|
@@ -337,6 +352,7 @@ func (c *WechatController) getReplayMessage(receviceData map[string]string, wech
|
337
|
352
|
// 发送 query_auth_code , 返回空, 并立即调用客服接口
|
338
|
353
|
} else if strings.Index(content, "QUERY_AUTH_CODE") > -1 {
|
339
|
354
|
replay = nil
|
|
355
|
+ return nil, errors.New(RESPONSE_CUSTOM_MESSAGE)
|
340
|
356
|
}
|
341
|
357
|
break
|
342
|
358
|
}
|
|
@@ -369,10 +385,12 @@ func (c *WechatController) getReplayMessage(receviceData map[string]string, wech
|
369
|
385
|
return
|
370
|
386
|
}
|
371
|
387
|
|
372
|
|
- replay = &model.TaAutoReply{
|
373
|
|
- MessageType: models.MESSAGE_TYPE_PARAGRAPH,
|
374
|
|
- MessageParagraph: replyText,
|
375
|
|
- IsUse: models.AUTOREPLY_IS_USE_ON,
|
|
388
|
+ if replyText != "" {
|
|
389
|
+ replay = &model.TaAutoReply{
|
|
390
|
+ MessageType: models.MESSAGE_TYPE_PARAGRAPH,
|
|
391
|
+ MessageParagraph: replyText,
|
|
392
|
+ IsUse: models.AUTOREPLY_IS_USE_ON,
|
|
393
|
+ }
|
376
|
394
|
}
|
377
|
395
|
}
|
378
|
396
|
break
|