Explorar el Código

added scancode-Info and scan-Pics-info for event scan and upload pics.

master
Patrick Peng Sun hace 8 años
padre
commit
bf1d20b0c4
Se han modificado 3 ficheros con 72 adiciones y 11 borrados
  1. +20
    -8
      inMsg.go
  2. +30
    -1
      sample_data/kf_event.txt
  3. +22
    -2
      serveCommand.go

+ 20
- 8
inMsg.go Ver fichero

@@ -72,14 +72,26 @@ type LinkMsg struct {

//EventMsg all type of event
type EventMsg struct {
Event string //subscribe, unsubscribe, SCAN, LOCATION, CLICK, VIEW
EventKey string //for CLICK, VIEW, SCAN, subscribe
Ticket string //for SCAN, subscribe
Latitude float64 //for LOCATION
Longitude float64 //for LOCATION
Precision float64 //for LOCATION
KfAccount string //for kf_close_session kf_create_session
CloseType string // kf_close_session
Event string //subscribe, unsubscribe, SCAN, LOCATION, CLICK, VIEW
EventKey string //for CLICK, VIEW, SCAN, subscribe
Ticket string //for SCAN, subscribe
Latitude float64 //for LOCATION
Longitude float64 //for LOCATION
Precision float64 //for LOCATION
KfAccount string //for kf_close_session kf_create_session
CloseType string //for kf_close_session
ScanCodeInfo struct {
ScanType string //for scancode_push scancode_waitmsg
ScanResult string
}
SendPicsInfo struct { //for pic_photo_or_album pic_weixin pic_sysphoto
Count int
PicList struct {
Item []struct {
PicMd5Sum string
} `xml:"item"`
}
}
}

//ReadCommonHeader parse xml of common field of wechat post message

+ 30
- 1
sample_data/kf_event.txt Ver fichero

@@ -14,4 +14,33 @@
<Event><![CDATA[kf_close_session]]></Event>
<KfAccount><![CDATA[kf2001@gh_f09231355c68]]></KfAccount>
<CloseType><![CDATA[KF]]></CloseType>
</xml>
</xml>


<xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName>
<FromUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></FromUserName>
<CreateTime>1495907830</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[scancode_waitmsg]]></Event>
<EventKey><![CDATA[EVENT_CHECKIN]]></EventKey>
<ScanCodeInfo><ScanType><![CDATA[qrcode]]></ScanType>
<ScanResult><![CDATA[http://weixin.qq.com/r/8nUZATzEPmFBrXhi9yDg]]></ScanResult>
</ScanCodeInfo>
</xml>


<xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName>
<FromUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></FromUserName>
<CreateTime>1495908270</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[pic_photo_or_album]]></Event>
<EventKey><![CDATA[EVENT_CONTRIBUTEPHOTO]]></EventKey>
<SendPicsInfo><Count>4</Count>
<PicList><item><PicMd5Sum><![CDATA[2a509d384018ab66e6571d1e163ce439]]></PicMd5Sum>
</item>
<item><PicMd5Sum><![CDATA[2a509d384018ab66e6571d1e163ce439]]></PicMd5Sum>
</item>
<item><PicMd5Sum><![CDATA[9f27adfd23367a008e78810f1a9d72df]]></PicMd5Sum>
</item>
<item><PicMd5Sum><![CDATA[9f27adfd23367a008e78810f1a9d72df]]></PicMd5Sum>
</item>

+ 22
- 2
serveCommand.go Ver fichero

@@ -18,8 +18,11 @@ func echoCommand(openID string, in InWechatMsg) (state chatState, processed bool
switch in.body.(type) {
case TextMsg:
m := in.body.(TextMsg)
str, err = BuildTextMsg(openID, m.Content)
processed = false
str, err = BuildTextMsg(openID, m.Content+"\n\n 转接 可以测试客服")
if m.Content == "转接" {
processed = false
}

case PicMsg:
m := in.body.(PicMsg)
str = buildPicMsg(openID, m.MediaId)
@@ -76,9 +79,26 @@ func echoEvents(openID string, in InWechatMsg) (state chatState, processed bool)
case "CLICK":
str, _ = BuildTextMsg(openID, m.EventKey)
case "subscribe":
str, _ = BuildTextMsg(openID, m.EventKey)
case "unsubscribe":
str, _ = BuildTextMsg(openID, m.EventKey)
case "SCAN":
str, _ = BuildTextMsg(openID, m.EventKey)
case "VIEW":
str, _ = BuildTextMsg(openID, m.EventKey)
case "kf_create_session":
kfSendTxt(openID, m.KfAccount)
//str, _ = BuildTextMsg(openID, m.KfAccount) // response msg is ignored by wechat
case "kf_close_session":
kfSendTxt(openID, m.KfAccount+"\n close type ="+m.CloseType)
//str, _ = BuildTextMsg(openID, m.KfAccount+"\n close type ="+m.CloseType) //response msg is ignored by wechat
case "scancode_waiting":
case "pic_photo_or_album":
log.Println(m.SendPicsInfo.Count)
for _, v := range m.SendPicsInfo.PicList.Item {
log.Println(v.PicMd5Sum)
}

default:
str, _ = BuildTextMsg(openID, " unknown event :"+m.Event)
}

Cargando…
Cancelar
Guardar