From 70e5cc16c8dfe6c426fdf5cbbb765f93ea451c64 Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 31 Mar 2021 12:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- access_token.client.go | 4 ++++ access_token.client_test.go | 11 ++++++++++ common.go | 3 +-- go.mod | 10 +++++++++ go.sum | 17 +++++++++++++++ send_uniform_message.client.go | 2 +- send_uniform_message.client_test.go | 33 +++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 access_token.client_test.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 send_uniform_message.client_test.go diff --git a/access_token.client.go b/access_token.client.go index 3574a64..e9ab503 100644 --- a/access_token.client.go +++ b/access_token.client.go @@ -13,6 +13,10 @@ import ( func GetAccessToken(dbname, site_id string, appid, secret string, url ...string) (*AccessTokenRes, error) { conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() data := AccessTokenReq{} data.SiteId = site_id diff --git a/access_token.client_test.go b/access_token.client_test.go new file mode 100644 index 0000000..7fbedfb --- /dev/null +++ b/access_token.client_test.go @@ -0,0 +1,11 @@ +package weixinrpc + +import ( + "testing" +) + +func Test_GetAccessToken(t *testing.T) { + + ret, err := GetAccessToken("test", "100005", "wx303b0cec4a8d1bc1", "90ddb8da4bc4e96e600532dd24be8c7b") + t.Log(ret, err) +} diff --git a/common.go b/common.go index fedf314..048ecee 100644 --- a/common.go +++ b/common.go @@ -31,7 +31,7 @@ type UniformMessageReq struct { TemplateId string Url string MiniProgram string - Data string + Data interface{} } func rpc_server_conn(url ...string) (*WeixinRpcServiceClient, error) { @@ -44,7 +44,6 @@ func rpc_server_conn(url ...string) (*WeixinRpcServiceClient, error) { if err != nil { return nil, err } - defer conn.Close() return conn, nil } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a8fe77d --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module git.tetele.net/tgo/weixinrpc + +go 1.14 + +require ( + git.tetele.net/tgo/crypter v0.2.2 // indirect + github.com/chai2010/protorpc v1.0.0 // indirect + golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c6beb24 --- /dev/null +++ b/go.sum @@ -0,0 +1,17 @@ +git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= +git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= +github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= +github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= +github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= +github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/send_uniform_message.client.go b/send_uniform_message.client.go index 128fc07..6eebc42 100644 --- a/send_uniform_message.client.go +++ b/send_uniform_message.client.go @@ -21,7 +21,7 @@ import ( * data 公众号模板消息的数据 */ -func SendUniformMessage(dbname, site_id string, appid, secret, touser, mp_appid, temp_id, redirect_url, mini_program, data string, url ...string) (*WxApiRes, error) { +func SendUniformMessage(dbname, site_id string, appid, secret, touser, mp_appid, temp_id, redirect_url, mini_program string, data interface{}, url ...string) (*WxApiRes, error) { conn, err := rpc_server_conn(url...) diff --git a/send_uniform_message.client_test.go b/send_uniform_message.client_test.go new file mode 100644 index 0000000..6365f10 --- /dev/null +++ b/send_uniform_message.client_test.go @@ -0,0 +1,33 @@ +package weixinrpc + +import ( + "encoding/json" + "testing" +) + +func Test_SendUniformMessage(t *testing.T) { + + db := "gkxy_tetele_net" + site_id := "1101832" + appid := "wx7be627d0325135f4" + secret := "984c6d213c60419c4f30c159fbbe1ce9" + touser := "osxVD5S0PAh82gyIXSiXCJzM_k6s" + mp_appid := "wx056995d61ca222f5" + temp_id := "6xgj_65KivigMvwdJgiveR4wLXJLDpzsT2-hShczLmU" + url := "" + mini_program := "wx7be627d0325135f4" + data := map[string]map[string]string{ + "first": map[string]string{"value": "来新订单了"}, + "keyword1": map[string]string{"value": "订单号是。。。"}, + "keyword2": map[string]string{"value": "取货位置"}, + "keyword3": map[string]string{"value": "收货人"}, + "keyword4": map[string]string{"value": "联系电话"}, + "keyword5": map[string]string{"value": "收货地址"}, + "remark": map[string]string{"value": "这是备注"}, + } + + data_json, _ := json.Marshal(data) + + ret, err := SendUniformMessage(db, site_id, appid, secret, touser, mp_appid, temp_id, url, mini_program, data) + t.Log(ret, err) +}