Explorar el Código

send text message as customer service 'active' send.

master
Patrick Peng Sun hace 8 años
padre
commit
da22cfad39
Se han modificado 2 ficheros con 40 adiciones y 0 borrados
  1. +32
    -0
      kfsend.go
  2. +8
    -0
      kfsend_test.go

+ 32
- 0
kfsend.go Ver fichero

@@ -0,0 +1,32 @@
package main

import (
"encoding/json"
"fmt"
)

func getKfSendURL() (url string) {
atk, _ := GetAccessToken()
url = fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s", atk)
return
}

type sendTxtMsg struct {
ToUser string `json:"touser"`
MsgType string `json:"msgtype"`
Text struct {
Content string `json:"content"`
} `json:"text"`
}

func kfSendTxt(user, txt string) {
u := getKfSendURL()

s := sendTxtMsg{}
s.MsgType = "text"
s.Text.Content = txt
s.ToUser = user

j, _ := json.Marshal(s)
postJSON(j, u)
}

+ 8
- 0
kfsend_test.go Ver fichero

@@ -0,0 +1,8 @@
package main

import "testing"

func TestSendTxt(t *testing.T) {
SetupConfig()
kfSendTxt("oUN420bxqFqlx0ZQHciUOesZO3PE", "测试消息")
}

Cargando…
Cancelar
Guardar