|
@ -1,139 +1,140 @@ |
|
|
package msgrpc |
|
|
package msgrpc |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
|
|
|
"errors" |
|
|
|
|
|
"log" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"encoding/json" |
|
|
|
|
|
"errors" |
|
|
|
|
|
"log" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"git.tetele.net/tgo/crypter" |
|
|
|
|
|
|
|
|
"git.tetele.net/tgo/crypter" |
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto" |
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func SendMsg(site_id, dbname, business_id, domainname, msg_type, order_sn, memo string, data interface{}, url ...string) (*MsgSend, error) { |
|
|
func SendMsg(site_id, dbname, business_id, domainname, msg_type, order_sn, memo string, data interface{}, url ...string) (*MsgSend, error) { |
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
arg_data, err := json.Marshal(data) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("json marshal error:", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
arg_data, err := json.Marshal(data) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("json marshal error:", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
arg := MsgBody{} |
|
|
|
|
|
arg.SiteId = site_id |
|
|
|
|
|
arg.Dbname = dbname |
|
|
|
|
|
arg.Platform = "1" |
|
|
|
|
|
arg.BusinessId = business_id |
|
|
|
|
|
arg.Domainname = domainname |
|
|
|
|
|
arg.Type = msg_type |
|
|
|
|
|
arg.Data = string(arg_data) |
|
|
|
|
|
arg.OrderSn = order_sn |
|
|
|
|
|
arg.Memo = memo |
|
|
|
|
|
|
|
|
arg := MsgBody{} |
|
|
|
|
|
arg.SiteId = site_id |
|
|
|
|
|
arg.Dbname = dbname |
|
|
|
|
|
arg.Platform = "1" |
|
|
|
|
|
arg.BusinessId = business_id |
|
|
|
|
|
arg.Domainname = domainname |
|
|
|
|
|
arg.Type = msg_type |
|
|
|
|
|
arg.Data = string(arg_data) |
|
|
|
|
|
arg.OrderSn = order_sn |
|
|
|
|
|
arg.Memo = memo |
|
|
|
|
|
|
|
|
data_json, err := json.Marshal(arg) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
now_int64 := time.Now().Unix() |
|
|
|
|
|
|
|
|
data_json, err := json.Marshal(arg) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
now_int64 := time.Now().Unix() |
|
|
|
|
|
|
|
|
encryData := crypter.DesEn(string(data_json), DES_KEY) |
|
|
|
|
|
|
|
|
encryData := crypter.DesEn(string(data_json), DES_KEY) |
|
|
|
|
|
|
|
|
now := strconv.FormatInt(now_int64, 10) |
|
|
|
|
|
|
|
|
now := strconv.FormatInt(now_int64, 10) |
|
|
|
|
|
|
|
|
sign := Sign(encryData, now) |
|
|
|
|
|
|
|
|
sign := Sign(encryData, now) |
|
|
|
|
|
|
|
|
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil} |
|
|
|
|
|
|
|
|
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil} |
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
err = conn.SendMsg(req, res) |
|
|
|
|
|
|
|
|
err = conn.SendMsg(req, res) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
res_data, err := GetOrgData(res) |
|
|
|
|
|
|
|
|
res_data, err := GetOrgData(res) |
|
|
|
|
|
|
|
|
var res_arr MsgSend |
|
|
|
|
|
|
|
|
var res_arr MsgSend |
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data), &res_arr) |
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data), &res_arr) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
return &res_arr, nil |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
return &res_arr, nil |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// target_type:目标类型,商品或文章 target_id:目标ID
|
|
|
// 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, url ...string) (bool, error) { |
|
|
|
|
|
if site_id == "" || dbname == "" || manager_id == "" || user_id == "" { |
|
|
|
|
|
return false, errors.New("参数错误") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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...) |
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
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 := 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) |
|
|
|
|
|
|
|
|
data_json, err := json.Marshal(arg) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
now_int64 := time.Now().Unix() |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
now_int64 := time.Now().Unix() |
|
|
|
|
|
|
|
|
encryData := crypter.DesEn(string(data_json), DES_KEY) |
|
|
|
|
|
|
|
|
encryData := crypter.DesEn(string(data_json), DES_KEY) |
|
|
|
|
|
|
|
|
now := strconv.FormatInt(now_int64, 10) |
|
|
|
|
|
|
|
|
now := strconv.FormatInt(now_int64, 10) |
|
|
|
|
|
|
|
|
sign := Sign(encryData, now) |
|
|
|
|
|
|
|
|
sign := Sign(encryData, now) |
|
|
|
|
|
|
|
|
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil} |
|
|
|
|
|
|
|
|
req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil} |
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
err = conn.SendNotcie(req, res) |
|
|
|
|
|
|
|
|
err = conn.SendNotcie(req, res) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("msgrpc SendNotcie error:", err) |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("msgrpc SendNotcie error:", err) |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
res_data, err := GetOrgData(res) |
|
|
|
|
|
|
|
|
res_data, err := GetOrgData(res) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
if res_data == "" { |
|
|
|
|
|
return false, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
if res_data == "" { |
|
|
|
|
|
return false, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var notice_res bool |
|
|
|
|
|
|
|
|
var notice_res bool |
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data), ¬ice_res) |
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data), ¬ice_res) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
return notice_res, nil |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false, err |
|
|
|
|
|
} |
|
|
|
|
|
return notice_res, nil |
|
|
|
|
|
|
|
|
} |
|
|
} |