ソースを参照

try nick name test

master
Patrick Peng Sun 8年前
コミット
4181fc2192
3個のファイルの変更26行の追加3行の削除
  1. +17
    -0
      kfsend.go
  2. +3
    -1
      kfsend_test.go
  3. +6
    -2
      main.go

+ 17
- 0
kfsend.go ファイルの表示

Text struct { Text struct {
Content string `json:"content"` Content string `json:"content"`
} `json:"text"` } `json:"text"`
CustomerService struct {
KfAccount string `json:"kf_account"`
} `json:"customservice"`
} }


func kfSendTxt(user, txt string) { func kfSendTxt(user, txt string) {
postJSON(j, u) 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) { func myJSONMarshal(t interface{}) ([]byte, error) {
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer) encoder := json.NewEncoder(buffer)

+ 3
- 1
kfsend_test.go ファイルの表示

// randinit() // randinit()
// msg = RandStringRunes(2048) // msg = RandStringRunes(2048)


kfSendTxt(toUser, msg)
//kfSendTxt(toUser, msg)
kfSendTxtAs(toUser, msg, "孙鹏")
//kfSendTxtAs(toUser, msg, "kf2002@gh_f09231355c68")
} }


func TestSendPic(t *testing.T) { func TestSendPic(t *testing.T) {

+ 6
- 2
main.go ファイルの表示

"/tmp/", "/tmp/",
"/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"} "/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"}


//KFUsers info cache about current customer service
var KFUsers kfCache

func main() { func main() {
err := readConfig() //wechat API config err := readConfig() //wechat API config
if err != nil { if err != nil {
} }


setupRootFileServer() setupRootFileServer()

startSessionManager(2048) startSessionManager(2048)

KFUsers.kfRenewList()
//always the last one
setupHTTPHandler() setupHTTPHandler()

} }


func setupHTTPHandler() { func setupHTTPHandler() {

読み込み中…
キャンセル
保存