Browse Source

try nick name test

master
Patrick Peng Sun 8 years ago
parent
commit
4181fc2192
3 changed files with 26 additions and 3 deletions
  1. +17
    -0
      kfsend.go
  2. +3
    -1
      kfsend_test.go
  3. +6
    -2
      main.go

+ 17
- 0
kfsend.go View File

@@ -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)

+ 3
- 1
kfsend_test.go View File

@@ -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) {

+ 6
- 2
main.go View File

@@ -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() {

Loading…
Cancel
Save