Просмотр исходного кода

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

master
Patrick Peng Sun 8 лет назад
Родитель
Сommit
bf1d20b0c4
3 измененных файлов: 72 добавлений и 11 удалений
  1. +20
    -8
      inMsg.go
  2. +30
    -1
      sample_data/kf_event.txt
  3. +22
    -2
      serveCommand.go

+ 20
- 8
inMsg.go Просмотреть файл



//EventMsg all type of event //EventMsg all type of event
type EventMsg struct { 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 //ReadCommonHeader parse xml of common field of wechat post message

+ 30
- 1
sample_data/kf_event.txt Просмотреть файл

<Event><![CDATA[kf_close_session]]></Event> <Event><![CDATA[kf_close_session]]></Event>
<KfAccount><![CDATA[kf2001@gh_f09231355c68]]></KfAccount> <KfAccount><![CDATA[kf2001@gh_f09231355c68]]></KfAccount>
<CloseType><![CDATA[KF]]></CloseType> <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 Просмотреть файл

switch in.body.(type) { switch in.body.(type) {
case TextMsg: case TextMsg:
m := in.body.(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: case PicMsg:
m := in.body.(PicMsg) m := in.body.(PicMsg)
str = buildPicMsg(openID, m.MediaId) str = buildPicMsg(openID, m.MediaId)
case "CLICK": case "CLICK":
str, _ = BuildTextMsg(openID, m.EventKey) str, _ = BuildTextMsg(openID, m.EventKey)
case "subscribe": case "subscribe":
str, _ = BuildTextMsg(openID, m.EventKey)
case "unsubscribe": case "unsubscribe":
str, _ = BuildTextMsg(openID, m.EventKey)
case "SCAN": case "SCAN":
str, _ = BuildTextMsg(openID, m.EventKey)
case "VIEW": 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: default:
str, _ = BuildTextMsg(openID, " unknown event :"+m.Event) str, _ = BuildTextMsg(openID, " unknown event :"+m.Event)
} }

Загрузка…
Отмена
Сохранить