| @@ -31,14 +31,28 @@ func BuildTextMsg(txt string, ToUserName string) (xml string, err error) { | |||
| return | |||
| } | |||
| //BuildLocationMsg doesn't work for build location message | |||
| func BuildLocationMsg(long, lat, precision float64, ToUserName string) (xml string) { | |||
| msg := buildLocationMsg() | |||
| //BuildKFTransferAnyOneMsg Transfer to anyone | |||
| func BuildKFTransferAnyOneMsg(toUser string) (xml string, err error) { | |||
| return BuildKFTransferMsg(toUser, "") | |||
| } | |||
| //BuildKFTransferMsg Transfer a message to specific kf | |||
| func BuildKFTransferMsg(toUser, kf string) (xml string, err error) { | |||
| msg := buildKfForwardMsg(toUser, kf) | |||
| e := Encode(msg) | |||
| xml, _, _, _ = signMsg(e) | |||
| return | |||
| } | |||
| //BuildLocationMsg doesn't work for build location message | |||
| // func BuildLocationMsg(long, lat, precision float64, ToUserName string) (xml string) { | |||
| // msg := buildLocationMsg() | |||
| // e := Encode(msg) | |||
| // xml, _, _, _ = signMsg(e) | |||
| // return | |||
| // } | |||
| func signMsg(content string) (xml string, timestamp int32, nonce int32, signature string) { | |||
| timestamp = int32(time.Now().Unix()) | |||
| nonce = rand.Int31() | |||
| @@ -253,16 +267,45 @@ func newsMsgTemplate() string { | |||
| </xml>` | |||
| } | |||
| func buildLocationMsg() string { | |||
| template := `<xml> | |||
| <ToUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></ToUserName> | |||
| <FromUserName><![CDATA[gh_f09231355c68]]></FromUserName> | |||
| <CreateTime>1494124221</CreateTime> | |||
| <MsgType><![CDATA[location]]></MsgType> | |||
| <Location_X>23.134521</Location_X> | |||
| <Location_Y>113.358803</Location_Y> | |||
| <Scale>20</Scale> | |||
| <Label><![CDATA[位置信息]]></Label> | |||
| </xml> ` | |||
| return template | |||
| // func buildLocationMsg() string { | |||
| // template := `<xml> | |||
| // <ToUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></ToUserName> | |||
| // <FromUserName><![CDATA[gh_f09231355c68]]></FromUserName> | |||
| // <CreateTime>1494124221</CreateTime> | |||
| // <MsgType><![CDATA[location]]></MsgType> | |||
| // <Location_X>23.134521</Location_X> | |||
| // <Location_Y>113.358803</Location_Y> | |||
| // <Scale>20</Scale> | |||
| // <Label><![CDATA[位置信息]]></Label> | |||
| // </xml> ` | |||
| // return template | |||
| // } | |||
| func buildKfForwardMsg(toUser string, kf string) (msg string) { | |||
| //转发信息到任意客服 | |||
| template := `<xml>s | |||
| <ToUserName><![CDATA[%s]]></ToUserName> | |||
| <FromUserName><![CDATA[%s]]></FromUserName> | |||
| <CreateTime>%d</CreateTime> | |||
| <MsgType><![CDATA[transfer_customer_service]]></MsgType> | |||
| </xml>` | |||
| //发送信息指定客服人员 | |||
| templateKF := ` <xml> | |||
| <ToUserName><![CDATA[%s]]></ToUserName> | |||
| <FromUserName><![CDATA[%s]]></FromUserName> | |||
| <CreateTime>%d</CreateTime> | |||
| <MsgType><![CDATA[transfer_customer_service]]></MsgType> | |||
| <TransInfo> | |||
| <KfAccount><![CDATA[%s]]></KfAccount> | |||
| </TransInfo> | |||
| </xml>` | |||
| if kf == "" { | |||
| msg = fmt.Sprintf(template, toUser, APIConfig.PublicAccountID, time.Now().Unix()) | |||
| } else { | |||
| msg = fmt.Sprintf(templateKF, toUser, APIConfig.PublicAccountID, time.Now().Unix(), kf) | |||
| } | |||
| return | |||
| } | |||