From cb0730aebda673e1885c40dd97b1b9f0a712b06b Mon Sep 17 00:00:00 2001 From: liaokaishan <874998826@qq.com> Date: Mon, 27 Sep 2021 15:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/mail/client.go | 50 ++++++++++++++++++++++++++++++++++++ services/mail/client_test.go | 22 ++++++++++++++++ services/mail/end_email.go | 36 ++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 services/mail/client.go create mode 100644 services/mail/client_test.go create mode 100644 services/mail/end_email.go diff --git a/services/mail/client.go b/services/mail/client.go new file mode 100644 index 0000000..7059b64 --- /dev/null +++ b/services/mail/client.go @@ -0,0 +1,50 @@ +package mail + +import ( + "crypto/md5" + "fmt" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "time" +) + +const ( + VERSION = "2021-09-27" +) + +var HOST requests.Host = requests.Host{ + Default: "mail.gaore.com", + Func: func(s string) string { + var a = map[string]string{ + requests.RELEASE: "mail.gaore.com", + requests.PRE: "mail.gaore.com", + requests.TEST: "mail.gaore.com", + } + return a[s] + }, +} + +type Client struct { + sdk.Client +} + +func NewClient() (client *Client) { + client = &Client{} + client.InitWithAccessKey("", "", "") + return +} + +func (c *Client) SendEmail(req *PostEmailRequest) (response *PostEmailResponse, err error) { + + now := time.Now().Second() + key := "04573fc4c8e01999a0909ab9c00bca5a" + signstr := fmt.Sprintf("%d%s", now, key) + data := []byte(signstr) + has := md5.Sum(data) + sign := fmt.Sprintf("%x", has) + req.Time = now + req.Sign = sign + response = CreatePostEmailResponse() + err = c.DoAction(req, response) + return +} diff --git a/services/mail/client_test.go b/services/mail/client_test.go new file mode 100644 index 0000000..e18fc11 --- /dev/null +++ b/services/mail/client_test.go @@ -0,0 +1,22 @@ +package mail + +import ( + "fmt" + "testing" + "time" +) + +func TestClient_GetUserInfo(t *testing.T) { + c := NewClient() + req := CreatePostEmailRequest() + req.Addresses = "3002467428@qq.com" + req.Body = "1111" + req.FromName = "213123121" + req.SetReadTimeout(60 * time.Second) + resp, err := c.SendEmail(req) + + fmt.Println(req) + fmt.Println(resp.GetHttpContentString()) + fmt.Println(err) + +} diff --git a/services/mail/end_email.go b/services/mail/end_email.go new file mode 100644 index 0000000..a45ad36 --- /dev/null +++ b/services/mail/end_email.go @@ -0,0 +1,36 @@ +package mail + +import ( + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +type PostEmailRequest struct { + *requests.RpcRequest + Addresses string `position:"Body" field:"addresses" default:"" ` + Subject string `position:"Body" field:"subject" default:"" ` + Body string `position:"Body" field:"body" default:""` + FromName string `position:"Body" field:"fromName" default:""` + Time int `position:"Body" field:"time" default:""` + Sign string `position:"Body" field:"sign" default:""` +} + +type PostEmailResponse struct { + *responses.BaseResponse +} + +func CreatePostEmailRequest() (req *PostEmailRequest) { + req = &PostEmailRequest{ + RpcRequest: &requests.RpcRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/email/post_email.php") + req.Method = requests.POST + return +} + +func CreatePostEmailResponse() (response *PostEmailResponse) { + response = &PostEmailResponse{ + BaseResponse: &responses.BaseResponse{}, + } + return +}