transfer_middleware/until/request/test/wxbiz_test.go

93 lines
2.7 KiB
Go
Raw Normal View History

2024-06-07 11:11:04 +08:00
package test
import (
2024-10-15 18:35:45 +08:00
"encoding/json"
2024-06-07 11:11:04 +08:00
"fmt"
"testing"
2024-10-15 18:35:45 +08:00
"trasfer_middleware/cmd/rpc/pb/transfer"
2024-06-12 13:46:14 +08:00
"trasfer_middleware/until/request"
2024-06-07 11:11:04 +08:00
)
// 发送GET 请求
func TestGet(t *testing.T) {
r := request.Request{
Method: "GET",
Url: "https://httpbin.org/get?name=张三&age=12",
Headers: map[string]string{"Cookie": "abc", "Token": "123"}}
resp, _ := r.Send()
fmt.Printf("状态码: %d\n", resp.StatusCode)
fmt.Printf("原因: %s\n", resp.Reason)
fmt.Printf("响应时间: %f秒\n", resp.Elapsed)
fmt.Printf("响应文本: %s\n", resp.Text)
}
// 发送GET 带单独Query参数请求
func TestWAccessToken(t *testing.T) {
appid := "wx381e6a04ab7f69b6"
secret := "16f6152c216c07fdff4c0ecaf1a173ed"
r := request.Request{
Method: "GET",
Url: "https://api.weixin.qq.com/cgi-bin/token",
Params: map[string]string{"grant_type": "client_credential", "appid": appid, "secret": secret},
}
resp, err := r.Send()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("状态码: %d\n", resp.StatusCode)
fmt.Printf("原因: %s\n", resp.Reason)
fmt.Printf("响应时间: %f秒\n", resp.Elapsed)
fmt.Printf("响应文本: %s\n", resp.Text)
}
func TestDtalkBlackBard(t *testing.T) {
r := request.Request{
Method: "POST",
Url: "https://httpbin.org/post",
Data: map[string]string{"name": "张三", "age": "12"},
Headers: map[string]string{"Cookie": "abc", "Token": "123"}}
resp, _ := r.Send()
fmt.Printf("状态码: %d\n", resp.StatusCode)
fmt.Printf("原因: %s\n", resp.Reason)
fmt.Printf("响应时间: %f秒\n", resp.Elapsed)
fmt.Printf("响应文本: %s\n", resp.Text)
}
// 发送POST 表单请求
func TestPostForm(t *testing.T) {
r := request.Request{
Method: "POST",
Url: "https://httpbin.org/post",
Data: map[string]string{"name": "张三", "age": "12"},
Headers: map[string]string{"Cookie": "abc", "Token": "123"}}
resp, _ := r.Send()
fmt.Printf("状态码: %d\n", resp.StatusCode)
fmt.Printf("原因: %s\n", resp.Reason)
fmt.Printf("响应时间: %f秒\n", resp.Elapsed)
fmt.Printf("响应文本: %s\n", resp.Text)
}
// 发送POST JSON请求
func TestPostJson(t *testing.T) {
r := request.Request{
Method: "POST",
Url: "https://httpbin.org/post",
Json: map[string]string{"name": "张三", "age": "12"},
Headers: map[string]string{"Cookie": "abc", "Token": "123"}}
resp, _ := r.Send()
fmt.Printf("状态码: %d\n", resp.StatusCode)
fmt.Printf("原因: %s\n", resp.Reason)
fmt.Printf("响应时间: %f秒\n", resp.Elapsed)
fmt.Printf("响应文本: %s\n", resp.Text)
}
2024-10-15 18:35:45 +08:00
func TestA(T *testing.T) {
var res transfer.MarketKeySendRes
data := "{\"errCode\":\"-1\",\"msg\":\"券码库存不足\"}"
_ = json.Unmarshal([]byte(data), &res)
fmt.Println(res)
}