7
0

添加邮件发送sdk

This commit is contained in:
liaokaishan 2021-09-27 15:52:02 +08:00
parent 45616c93cd
commit cb0730aebd
3 changed files with 108 additions and 0 deletions

50
services/mail/client.go Normal file
View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}