diff --git a/kfsend.go b/kfsend.go index 82d86a7..661c322 100644 --- a/kfsend.go +++ b/kfsend.go @@ -19,6 +19,9 @@ type sendTxtMsg struct { Text struct { Content string `json:"content"` } `json:"text"` + CustomerService struct { + KfAccount string `json:"kf_account"` + } `json:"customservice"` } func kfSendTxt(user, txt string) { @@ -35,6 +38,20 @@ func kfSendTxt(user, txt string) { postJSON(j, u) } +func kfSendTxtAs(user, txt, KF string) { + u := getKfSendURL() + + s := sendTxtMsg{} + s.MsgType = "text" + s.Text.Content = txt + s.ToUser = user + s.CustomerService.KfAccount = KFUsers.kfAcc(KF) + //j, _ := json.Marshal(s) // it will escape html < > and & to \u0006 + j, _ := myJSONMarshal(s) // this reserves < > and & + log.Println(string(j)) + postJSON(j, u) +} + func myJSONMarshal(t interface{}) ([]byte, error) { buffer := &bytes.Buffer{} encoder := json.NewEncoder(buffer) diff --git a/kfsend_test.go b/kfsend_test.go index c1809bd..0124959 100644 --- a/kfsend_test.go +++ b/kfsend_test.go @@ -15,7 +15,9 @@ func TestSendTxt(t *testing.T) { // randinit() // msg = RandStringRunes(2048) - kfSendTxt(toUser, msg) + //kfSendTxt(toUser, msg) + kfSendTxtAs(toUser, msg, "孙鹏") + //kfSendTxtAs(toUser, msg, "kf2002@gh_f09231355c68") } func TestSendPic(t *testing.T) { diff --git a/main.go b/main.go index bbea87c..02b29d3 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,9 @@ var GlobalPath = PathsConfig{ "/tmp/", "/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"} +//KFUsers info cache about current customer service +var KFUsers kfCache + func main() { err := readConfig() //wechat API config if err != nil { @@ -34,10 +37,11 @@ func main() { } setupRootFileServer() - startSessionManager(2048) - + KFUsers.kfRenewList() + //always the last one setupHTTPHandler() + } func setupHTTPHandler() {