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
d6224769
Commit
d6224769
authored
May 06, 2019
by
Cui
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request library/utils!2
parents
4f00bb35
d1454d90
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
15 deletions
+152
-15
caller_test.go
caller_test.go
+1
-1
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-11
jpush.go
sender/jpush.go
+90
-0
structs.go
sender/structs.go
+40
-2
wrapper.go
sender/wrapper.go
+18
-0
No files found.
caller_test.go
View file @
d6224769
...
...
@@ -12,7 +12,7 @@ import (
func
TestGetCurrentFunctionName
(
t
*
testing
.
T
)
{
funcName
:=
GetCurrentFunctionName
()
if
funcName
==
"gitlab.qingclass.cn/
cuiweiqiang
/utils.TestGetCurrentFunctionName"
{
if
funcName
==
"gitlab.qingclass.cn/
library
/utils.TestGetCurrentFunctionName"
{
t
.
Log
(
"success"
)
}
else
{
t
.
Failed
()
...
...
go.mod
View file @
d6224769
...
...
@@ -4,5 +4,5 @@ require (
github.com/heycayc/chkcki v0.0.0-20180425093509-ad62647adf04
github.com/sirupsen/logrus v1.3.0
github.com/valyala/fasthttp v1.0.0
gitlab.qingclass.cn/library/
utils v0.1.15
gitlab.qingclass.cn/library/
jpush v0.0.2
)
go.sum
View file @
d6224769
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/heycayc/chkcki v0.0.0-20180425093509-ad62647adf04 h1:S+9Ua2s9IVhZUzuqEBRtgvGyE0BNOwAVtl5zvVsoNAw=
github.com/heycayc/chkcki v0.0.0-20180425093509-ad62647adf04/go.mod h1:68nSgivWifFndv3X4OMS7EIuHaNxJb1PlYECLiH99jU=
github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco=
github.com/valyala/fasthttp v1.0.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
gitlab.qingclass.cn/cuiweiqiang/utils v0.1.15 h1:MBcVPFTRIEuhRAwey8+T1e6VZTzh1YoHOGr+9an9pZs=
gitlab.qingclass.cn/cuiweiqiang/utils v0.1.15/go.mod h1:0dBvE/L/l27nygQFQ0tb0tegE4hmuR49B5TIq30Ej+M=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
gitlab.qingclass.cn/library/jpush v0.0.2 h1:GzRWzf/L38wvIxSyWniWwGTse7CrVh6lofa/ZBlGNks=
gitlab.qingclass.cn/library/jpush v0.0.2/go.mod h1:h4wvcwtBQSlZKJhpE2FwcXFLIZREfB7fBNYJSCWdGhE=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
sender/jpush.go
0 → 100644
View file @
d6224769
package
sender
import
(
"encoding/json"
"github.com/sirupsen/logrus"
.
"gitlab.qingclass.cn/library/utils"
Push
"gitlab.qingclass.cn/library/jpush"
"gitlab.qingclass.cn/library/jpush/push"
)
// const appKey = "2eccc8d57e1bfd374e690f9d"
// const masterSecret = "30ce7445d75af8a6dd0f251b"
func
AppMessageSender
(
am
AppMessage
,
appKey
,
masterSecret
string
,
iosProduction
bool
)
(
statusCode
int
,
errorStr
string
)
{
log
:=
Logger
.
WithFields
(
logrus
.
Fields
{
"position"
:
"jpush.go"
,
"func"
:
"AppMessageSender"
,
})
client
:=
Push
.
NewJPushClient
(
appKey
,
masterSecret
)
platform
:=
push
.
NewPlatform
()
platform
.
All
()
// Add("android")
audience
:=
push
.
NewAudience
()
audience
.
SetRegistrationId
(
am
.
ToUser
)
notification
:=
push
.
NewNotification
(
am
.
Title
)
// android 平台专有的 notification,用 alert 属性初始化
androidNotification
:=
push
.
NewAndroidNotification
(
am
.
SubTitle
)
androidNotification
.
Title
=
am
.
Title
iosNotification
:=
push
.
NewIosNotification
(
am
.
Title
)
notification
.
Android
=
androidNotification
notification
.
Ios
=
iosNotification
// option 对象,表示推送可选项
options
:=
push
.
NewOptions
()
// iOS 平台,是否推送生产环境,false 表示开发环境;如果不指定,就是生产环境
options
.
ApnsProduction
=
iosProduction
// Options 的 Validate 方法会对 time_to_live 属性做范围限制,以满足 JPush 的规范
// options.TimeToLive = 10000000
// Options 的 Validate 方法会对 big_push_duration 属性做范围限制,以满足 JPush 的规范
// options.BigPushDuration = 1500
if
am
.
Extra
.
MessageId
!=
""
{
androidNotification
.
AddExtra
(
"messageId"
,
am
.
Extra
.
MessageId
)
iosNotification
.
AddExtra
(
"messageId"
,
am
.
Extra
.
MessageId
)
}
androidNotification
.
AddExtra
(
"unReadCount"
,
am
.
Extra
.
UnReadCount
)
iosNotification
.
AddExtra
(
"unReadCount"
,
am
.
Extra
.
UnReadCount
)
payload
:=
push
.
NewPushObject
()
payload
.
Platform
=
platform
payload
.
Audience
=
audience
payload
.
Notification
=
notification
payload
.
Options
=
options
// result, err := client.PushValidate(payload)
result
,
err
:=
client
.
Push
(
payload
)
res
,
_
:=
json
.
Marshal
(
result
)
if
err
!=
nil
{
log
.
WithField
(
"error"
,
err
)
.
Error
(
"AppMessageSender Error "
)
statusCode
=
-
1
errorStr
=
"AppMessageSender Error -"
+
err
.
Error
()
}
else
if
result
.
StatusCode
!=
200
{
log
.
WithField
(
"error"
,
result
.
Error
.
String
())
.
Error
(
"AppMessageSender Error "
)
statusCode
=
-
2
errorStr
=
"AppMessageSender Error -"
+
result
.
Error
.
String
()
}
else
{
log
.
WithFields
(
am
.
ToFields
())
.
WithField
(
"response"
,
string
(
res
))
.
Info
(
"AppMessageSender send success !"
)
}
return
}
sender/structs.go
View file @
d6224769
...
...
@@ -2,12 +2,13 @@ package sender
import
(
"encoding/json"
"github.com/sirupsen/logrus"
)
type
MessageLog
struct
{
MessageType
string
`json:"messageType" bson:"messageType"`
// CUSTOMER-客服消息 TEMPLATE-模板消息 SUBSCRIBE-订阅消息 SMS-短信消息 MASS-高级群发
MessageSubType
string
`json:"messageSubType" bson:"messageSubType"`
// TEXT IMAGE VOICE VIDEO MUSIC NEWS MPNEWS WXCARD MINIPROGRAMPAGE
MessageType
string
`json:"messageType" bson:"messageType"`
// CUSTOMER-客服消息 TEMPLATE-模板消息 SUBSCRIBE-订阅消息 SMS-短信消息 MASS-高级群发
APP-app 消息
MessageSubType
string
`json:"messageSubType" bson:"messageSubType"`
// TEXT IMAGE VOICE VIDEO MUSIC NEWS MPNEWS WXCARD MINIPROGRAMPAGE
ANDROID IOS
RemindType
string
`json:"remindType" bson:"remindType"`
// 开课提醒、购买成功通知、上课提醒、打卡失败提醒、复习提醒、结课提醒、到期提醒、获得补卡券提醒、提前获得奖学金提醒、现金券到期提醒、成绩单提醒、提成消息<br/>classBegin,purchaseSuccessNotice,classRemind,PUNCH_FAIL,review,classEnd,Expire,replacementCardGain,previousScholarship,CouponExpire,transcript,profit
JsonId
string
`json:"jsonId"`
// 分组ID
UserOpenid
string
`json:"userOpenid" bson:"userOpenid"`
// 用户openid
...
...
@@ -52,6 +53,10 @@ type MessageStruct struct {
SmsAppId
int
`json:"smsAppId" bson:"smsAppId"`
SmsAppKey
string
`json:"smsAppKey" bson:"smsAppKey"`
JAppKey
string
`json:"jappKey"`
JAppSecret
string
`json:"jappSecret"`
IosProduction
bool
`json:"iosProduction"`
Retry
int
`json:"retry"`
PushCount
int
`json:"pushCount"`
...
...
@@ -361,3 +366,36 @@ func (sm *SmsMessage) ToFields() (fields logrus.Fields) {
fields
[
"time"
]
=
sm
.
Time
return
}
// App 消息
type
AppMessage
struct
{
ToUser
[]
string
`json:"toUser"`
Title
string
`json:"title"`
SubTitle
string
`json:"subTitle"`
// MsgContent string `json:"msg_content"`
// JumpEnable bool `json:"jumpEnable"`
// JumpUrl string `json:"jumpUrl"`
// JumpType string `json:"jumpType"` // enum: [ 'internal', 'external' ],
// JumpParams map[string]interface{} `json:"jumpParams"`
Extra
struct
{
UnReadCount
int
`json:"unReadCount"`
MessageId
string
`json:"messageId"`
}
`json:"extra"`
}
func
(
am
*
AppMessage
)
ToFields
()
(
fields
logrus
.
Fields
)
{
fields
=
make
(
logrus
.
Fields
)
fields
[
"title"
]
=
am
.
Title
fields
[
"subTitle"
]
=
am
.
SubTitle
// fields["msg_content"] = am.MsgContent
// fields["jumpEnable"] = am.JumpEnable
// fields["jumpUrl"] = am.JumpUrl
// fields["jumpType"] = am.JumpType
fields
[
"unReadCount"
]
=
am
.
Extra
.
UnReadCount
fields
[
"messageId"
]
=
am
.
Extra
.
MessageId
return
}
sender/wrapper.go
View file @
d6224769
...
...
@@ -2,7 +2,9 @@ package sender
import
(
"encoding/json"
"github.com/sirupsen/logrus"
.
"gitlab.qingclass.cn/library/utils"
)
...
...
@@ -197,6 +199,22 @@ func Sender(accessToken string, message MessageStruct) (code int, msg string) {
code
,
msg
=
SmsMessageSender
(
sm
,
message
.
SmsAppId
,
message
.
SmsAppKey
)
break
case
"APP"
:
var
am
AppMessage
err
:=
json
.
Unmarshal
(
message
.
MessageData
,
&
am
)
if
err
!=
nil
{
msg
=
"Unmarshal AppMessage failed"
log
.
WithField
(
"error"
,
err
)
.
Error
(
msg
)
code
=
-
10005
break
}
code
,
msg
=
AppMessageSender
(
am
,
message
.
JAppKey
,
message
.
JAppSecret
,
message
.
IosProduction
)
break
default
:
msg
=
"MessageType is not match"
...
...
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