Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
U
utils
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
library
utils
Commits
f5cfc22f
Verified
Commit
f5cfc22f
authored
Jan 21, 2019
by
Cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add send wrapper
parent
72113e39
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
structs.go
sender/structs.go
+9
-0
wrapper.go
sender/wrapper.go
+75
-0
No files found.
sender/structs.go
View file @
f5cfc22f
...
...
@@ -5,6 +5,15 @@ import (
"github.com/sirupsen/logrus"
)
type
MessageStruct
struct
{
AppId
string
`json:"appId" bson:"appId"`
SmsAppId
int
`json:"smsAppId" bson:"smsAppId"`
SmsAppKey
string
`json:"smsAppKey" bson:"smsAppKey"`
MessageType
string
`json:"messageType" bson:"messageType"`
// CUSTOMER TEMPLATE SUBSCRIBE SMS
MessageSubType
string
`json:"messageSubType" bson:"messageSubType"`
// TEXT IMAGE VOICE VIDEO MUSIC NEWS MPNEWS WXCARD MINIPROGRAMPAGE
MessageData
json
.
RawMessage
`json:"messageData" bson:"messageData"`
}
type
TemplateMessage
struct
{
Touser
string
`json:"touser" bson:"touser"`
// 接收者openid
TemplateId
string
`json:"template_id" bson:"template_id"`
// 模板ID
...
...
sender/wrapper.go
0 → 100644
View file @
f5cfc22f
package
sender
import
(
"encoding/json"
"github.com/sirupsen/logrus"
.
"gitlab.qingclass.cn/cuiweiqiang/utils"
)
func
Sender
(
accessToken
string
,
message
MessageStruct
)
(
int
,
string
)
{
log
:=
Logger
.
WithFields
(
logrus
.
Fields
{
"position"
:
"wrapper.go"
,
"func"
:
"Sender"
,
})
switch
message
.
MessageType
{
case
"CUSTOMER"
:
var
cmi
CustomerMessageInterface
err
:=
json
.
Unmarshal
(
message
.
MessageData
,
&
cmi
)
if
err
!=
nil
{
msg
:=
"Unmarshal CustomerMessageInterface failed"
log
.
WithField
(
"error"
,
err
)
.
Error
(
msg
)
return
-
10001
,
msg
}
return
CustomerMessageSender
(
accessToken
,
cmi
)
case
"TEMPLATE"
:
var
tm
TemplateMessage
err
:=
json
.
Unmarshal
(
message
.
MessageData
,
&
tm
)
if
err
!=
nil
{
msg
:=
"Unmarshal TemplateMessage failed"
log
.
WithField
(
"error"
,
err
)
.
Error
(
msg
)
return
-
10002
,
msg
}
return
TemplateMessageSender
(
accessToken
,
tm
)
case
"SUBSCRIBE"
:
var
sm
SubscribeMessage
err
:=
json
.
Unmarshal
(
message
.
MessageData
,
&
sm
)
if
err
!=
nil
{
msg
:=
"Unmarshal SubscribeMessage failed"
log
.
WithField
(
"error"
,
err
)
.
Error
(
msg
)
return
-
10003
,
msg
}
return
SubscribeMessageSender
(
accessToken
,
sm
)
case
"SMS"
:
var
sm
SmsMessage
err
:=
json
.
Unmarshal
(
message
.
MessageData
,
&
sm
)
if
err
!=
nil
{
msg
:=
"Unmarshal SmsMessage failed"
log
.
WithField
(
"error"
,
err
)
.
Error
(
msg
)
return
-
10004
,
msg
}
return
SmsMessageSender
(
sm
,
message
.
SmsAppId
,
message
.
SmsAppKey
)
default
:
msg
:=
"MessageType is not match"
log
.
WithField
(
"MessageType"
,
message
.
MessageType
)
.
Error
(
msg
)
return
-
10000
,
msg
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment