9 Commits

Author SHA1 Message Date
  lijianbin ed832a4cd0 推送消息的时候同时判断是否下发短信 2 years ago
  lijianbin 3d843c41e7 update 2 years ago
  lijianbin d9c17cd6a5 增加用户ID 2 years ago
  lijianbin 4d62b053a0 增加参数 2 years ago
  lijianbin cb14bbf9c7 消息提送增加额外参数 2 years ago
  lijianbin 399225f41c 消息提送增加图片参数 2 years ago
  lijianbin cde3148781 增加sendNotice函数 2 years ago
  guzeng f5929d44de 更新pb.go 2 years ago
  lijianbin c0058b8a9f 增加消息推送接口 2 years ago
7 changed files with 110 additions and 6 deletions
Split View
  1. +69
    -0
      client.go
  2. +18
    -0
      client_test.go
  3. +11
    -0
      common.go
  4. +3
    -2
      go.mod
  5. +4
    -4
      go.sum
  6. +4
    -0
      msg.pb.go
  7. +1
    -0
      msg.proto

+ 69
- 0
client.go View File

@ -2,6 +2,7 @@ package msgrpc
import (
"encoding/json"
"errors"
"log"
"strconv"
"time"
@ -69,3 +70,71 @@ func SendMsg(site_id, dbname, business_id, domainname, msg_type, order_sn, memo
return &res_arr, nil
}
// target_type:目标类型,商品或文章 target_id:目标ID
func SendNotcie(site_id, dbname, domain, user_id, manager_id, target_type, target_id string, template_data map[string]string, sms_data []string, url ...string) (bool, error) {
if site_id == "" || dbname == "" || manager_id == "" || user_id == "" {
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
arg := NoticeSend{}
arg.SiteId = site_id
arg.Dbname = dbname
arg.Domain = domain
arg.UserId = user_id
arg.ManagerId = manager_id
arg.TargetType = target_type
arg.TargetId = target_id
arg.TemplateData = template_data
arg.SmsData = sms_data
data_json, err := json.Marshal(arg)
if err != nil {
return false, err
}
now_int64 := time.Now().Unix()
encryData := crypter.DesEn(string(data_json), DES_KEY)
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
res := &Response{}
err = conn.SendNotcie(req, res)
if err != nil {
log.Println("msgrpc SendNotcie error:", err)
return false, err
}
res_data, err := GetOrgData(res)
if err != nil {
return false, err
}
if res_data == "" {
return false, nil
}
var notice_res bool
err = json.Unmarshal([]byte(res_data), &notice_res)
if err != nil {
return false, err
}
return notice_res, nil
}

+ 18
- 0
client_test.go View File

@ -20,3 +20,21 @@ func Test_SendMsg(t *testing.T) {
t.Log(ret)
t.Log(err)
}
func Test_SendNotcie(t *testing.T) {
site_id := "1058278"
dbname := "shop_v2_org"
domain := "http://dev6.tetele.net"
user_id := "2"
manager_id := "28"
target_type := "product"
target_id := "10"
template_data := map[string]string{"order_name": "商品订单名1", "score_get": "10"}
sms_data := []string{}
ret, err := SendNotcie(site_id, dbname, domain,user_id,manager_id,target_type,target_id,template_data,sms_data)
t.Log(ret)
t.Log(err)
}

+ 11
- 0
common.go View File

@ -22,6 +22,17 @@ type MsgSend struct {
Id string
}
type NoticeSend struct {
Req
Domain string
UserId string
ManagerId string
TargetType string
TargetId string
TemplateData map[string]string
SmsData []string
}
func rpc_server_conn(url ...string) (*MsgRpcServiceClient, error) {
var wx_rpc_url string = "127.0.0.1:7954"


+ 3
- 2
go.mod View File

@ -3,8 +3,9 @@ module git.tetele.net/tgo/msgrpc
go 1.14
require (
git.tetele.net/tgo/crypter v0.2.2 // indirect
github.com/chai2010/protorpc v1.0.0 // indirect
git.tetele.net/tgo/crypter v0.2.2
github.com/chai2010/protorpc v1.1.3
github.com/golang/protobuf v1.0.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
)

+ 4
- 4
go.sum View File

@ -1,11 +1,11 @@
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/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w=
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I=
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=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=


+ 4
- 0
msg.pb.go View File

@ -99,6 +99,7 @@ func init() {
type MsgRpcService interface {
SendMsg(in *Request, out *Response) error
SendNotcie(in *Request, out *Response) error
}
// AcceptMsgRpcServiceClient accepts connections on the listener and serves requests
@ -173,6 +174,9 @@ func NewMsgRpcServiceClient(conn io.ReadWriteCloser) (*MsgRpcServiceClient, *rpc
func (c *MsgRpcServiceClient) SendMsg(in *Request, out *Response) error {
return c.Call("MsgRpcService.SendMsg", in, out)
}
func (c *MsgRpcServiceClient) SendNotcie(in *Request, out *Response) error {
return c.Call("MsgRpcService.SendNotcie", in, out)
}
// DialMsgRpcService connects to an MsgRpcService at the specified network address.
func DialMsgRpcService(network, addr string) (*MsgRpcServiceClient, *rpc.Client, error) {


+ 1
- 0
msg.proto View File

@ -19,4 +19,5 @@ message Response {
// rpc方法
service MsgRpcService {
rpc sendMsg (Request) returns (Response); //
rpc sendNotcie (Request) returns (Response); //
}

Loading…
Cancel
Save