Bläddra i källkod

active send pic successful

master
Patrick Peng Sun 8 år sedan
förälder
incheckning
0b174d05eb
2 ändrade filer med 54 tillägg och 2 borttagningar
  1. +24
    -0
      kfsend.go
  2. +30
    -2
      kfsend_test.go

+ 24
- 0
kfsend.go Visa fil

@@ -30,3 +30,27 @@ func kfSendTxt(user, txt string) {
j, _ := json.Marshal(s)
postJSON(j, u)
}

type sendPicMsg struct {
ToUser string `json:"touser"`
MsgType string `json:"msgtype"`
Image struct {
MediaID string `json:"media_id"`
} `json:"image"`
}

func kfSendPic(user, pic string) {
mID := uploadImage(pic)
kfSendPicByMediaID(user, mID)
}

func kfSendPicByMediaID(user, mediaID string) {
u := getKfSendURL()
s := sendPicMsg{}
s.ToUser = user
s.MsgType = "image"
s.Image.MediaID = mediaID

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

+ 30
- 2
kfsend_test.go Visa fil

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

import "testing"
import (
"fmt"
"testing"
"time"
)

var toUser = "oUN420bxqFqlx0ZQHciUOesZO3PE"

func TestSendTxt(t *testing.T) {
SetupConfig()
kfSendTxt("oUN420bxqFqlx0ZQHciUOesZO3PE", "测试消息")
msg := fmt.Sprintf("测试消息, %s ", time.Now().String())
kfSendTxt(toUser, msg)
}

func TestSendPic(t *testing.T) {
SetupConfig()
kfSendPic(toUser, "media_for_test/200x200.png")
}

func TestSendVoice(t *testing.T) {

}

func TestSendVideo(t *testing.T) {

}

func TestSendMusic(t *testing.T) {

}

func TestSendArticle(t *testing.T) {

}

Laddar…
Avbryt
Spara