作者 yangfu

Merge remote-tracking branch 'origin/test'

正在显示 67 个修改的文件 包含 2070 行增加88 行删除
@@ -7,10 +7,15 @@ aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}" @@ -7,10 +7,15 @@ aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
7 #阿里云基础配置 7 #阿里云基础配置
8 AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC" 8 AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
9 AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO" 9 AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
10 -#AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"  
11 -#AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"  
12 -#阿里云->绑定域名 cname = https://media.goexample.live/  
13 -cname ="https://media.fjmaimaimai.com/" 10 +cname ="https://media.goexample.live/"
14 11
15 12
16 #友盟推送 13 #友盟推送
  14 +UMENG_API_HOST = "http://msg.umeng.com"
  15 +
  16 +#数据库相关
  17 +MYSQL_USER = "${MYSQL_USER||root}"
  18 +MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia2018}"
  19 +MYSQL_HOST = "${MYSQL_HOST||101.37.68.23}"
  20 +MYSQL_PORT = "${MYSQL_PORT||3306}"
  21 +MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open_dev}"
@@ -7,5 +7,12 @@ AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg" @@ -7,5 +7,12 @@ AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
7 log_level = "${LOG_LEVEL||debug}" 7 log_level = "${LOG_LEVEL||debug}"
8 aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}" 8 aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
9 9
10 -#阿里云 https://media.goexample.live/ 10 +#阿里云
11 cname ="https://media.fjmaimaimai.com/" 11 cname ="https://media.fjmaimaimai.com/"
  12 +
  13 +#数据库相关
  14 +MYSQL_USER = "${MYSQL_USER||root}"
  15 +MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia2018}"
  16 +MYSQL_HOST = "${MYSQL_HOST||101.37.68.23}"
  17 +MYSQL_PORT = "${MYSQL_PORT||3306}"
  18 +MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open_dev}"
@@ -8,4 +8,11 @@ AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS" @@ -8,4 +8,11 @@ AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
8 AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg" 8 AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
9 9
10 #阿里云 10 #阿里云
11 -cname ="https://media.fjmaimaimai.com/"  
  11 +cname ="https://media.fjmaimaimai.com/"
  12 +
  13 +#数据库相关
  14 +MYSQL_USER = "${MYSQL_USER||root}"
  15 +MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia2018}"
  16 +MYSQL_HOST = "${MYSQL_HOST||101.37.68.23}"
  17 +MYSQL_PORT = "${MYSQL_PORT||3306}"
  18 +MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open}"
@@ -8,4 +8,11 @@ AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS" @@ -8,4 +8,11 @@ AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
8 AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg" 8 AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
9 9
10 #阿里云 10 #阿里云
11 -cname ="https://media.fjmaimaimai.com/"  
  11 +cname ="https://media.fjmaimaimai.com/"
  12 +
  13 +#数据库相关
  14 +MYSQL_USER = "${MYSQL_USER||root}"
  15 +MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia2018}"
  16 +MYSQL_HOST = "${MYSQL_HOST||101.37.68.23}"
  17 +MYSQL_PORT = "${MYSQL_PORT||3306}"
  18 +MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open_test}"
@@ -3,11 +3,26 @@ module openapi @@ -3,11 +3,26 @@ module openapi
3 go 1.12 3 go 1.12
4 4
5 require ( 5 require (
  6 + github.com/ajg/form v1.5.1 // indirect
6 github.com/aliyun/alibaba-cloud-sdk-go v1.60.348 7 github.com/aliyun/alibaba-cloud-sdk-go v1.60.348
7 github.com/aliyun/aliyun-sts-go-sdk v0.0.0-20171106034748-98d3903a2309 8 github.com/aliyun/aliyun-sts-go-sdk v0.0.0-20171106034748-98d3903a2309
8 github.com/astaxie/beego v1.10.0 9 github.com/astaxie/beego v1.10.0
  10 + github.com/fatih/structs v1.1.0 // indirect
  11 + github.com/gavv/httpexpect v2.0.0+incompatible
  12 + github.com/go-sql-driver/mysql v1.4.1
  13 + github.com/google/go-querystring v1.0.0 // indirect
  14 + github.com/imkira/go-interpol v1.1.0 // indirect
9 github.com/klauspost/cpuid v1.2.3 // indirect 15 github.com/klauspost/cpuid v1.2.3 // indirect
  16 + github.com/moul/http2curl v1.0.0 // indirect
  17 + github.com/onsi/ginkgo v1.10.3
  18 + github.com/onsi/gomega v1.7.1
10 github.com/satori/go.uuid v1.2.0 19 github.com/satori/go.uuid v1.2.0
  20 + github.com/sergi/go-diff v1.1.0 // indirect
  21 + github.com/valyala/fasthttp v1.13.1 // indirect
  22 + github.com/xeipuuv/gojsonschema v1.2.0 // indirect
  23 + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
  24 + github.com/yudai/gojsondiff v1.0.0 // indirect
  25 + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
11 gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1 26 gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
12 ) 27 )
13 28
1 package main 1 package main
2 2
3 import ( 3 import (
4 - "fmt"  
5 "github.com/astaxie/beego" 4 "github.com/astaxie/beego"
6 - "gitlab.fjmaimaimai.com/mmm-go/gocomm/config"  
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
8 - "openapi/internal/utils"  
9 - _ "openapi/routers"  
10 - "time" 6 + _ "openapi/pkg/infrastructure/bgorm"
  7 + _ "openapi/pkg/log"
  8 + _ "openapi/pkg/port/beego"
11 ) 9 )
12 10
13 -func init() {  
14 - time.Local = time.FixedZone("CST", 3600*8)  
15 - log.InitLog(config.Logger{  
16 - Filename: beego.AppConfig.String("aliyun_logs_access"),  
17 - Level: fmt.Sprintf("%v", utils.ResolveLogLevel(beego.AppConfig.String("log_level"))),  
18 - })  
19 -}  
20 -  
21 func main() { 11 func main() {
22 defer func() { 12 defer func() {
23 - log.Info("open-api on stop!") 13 + log.Info("server on stop!")
24 }() 14 }()
25 -  
26 - log.Info("open-api on start!")  
27 - log.Info("Beego Run Mode:", beego.BConfig.RunMode)  
28 - 15 + log.Info("server on start!")
  16 + //constant.DebugConfig()
29 beego.Run() 17 beego.Run()
30 } 18 }
  1 +package push
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + protocol "openapi/pkg/domain"
  7 + "openapi/pkg/infrastructure/push"
  8 + "openapi/pkg/infrastructure/push/getui"
  9 + "openapi/pkg/infrastructure/repository"
  10 + "openapi/pkg/infrastructure/utils"
  11 + "strings"
  12 +)
  13 +
  14 +//推送信息
  15 +func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequest) (rsp *protocol.PushInfoResponse, err error) {
  16 + var (
  17 + repApp, _ = repository.NewAppInfoRepository(nil)
  18 + repDevice, _ = repository.NewPushDeviceRepository(nil)
  19 + appInfo *protocol.AppInfo
  20 + receivers []string
  21 + deviceList []*protocol.Device
  22 + requestOriginal *protocol.PushInfoOriginalRequest = &protocol.PushInfoOriginalRequest{
  23 + Type: request.Type,
  24 + Title: request.Title,
  25 + Content: request.Content,
  26 + Ext: request.Ext,
  27 + }
  28 + )
  29 + rsp = &protocol.PushInfoResponse{}
  30 + if appInfo, err = repApp.FindOne(map[string]interface{}{"project_key": request.ProjectKey}); err != nil {
  31 + log.Error(err)
  32 + err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey))
  33 + return
  34 + }
  35 + if deviceList, err = repDevice.Find(map[string]interface{}{"receivers": request.Receivers}); err != nil {
  36 + log.Error(err)
  37 + err = nil
  38 + return
  39 + }
  40 + if len(deviceList) == 0 {
  41 + err = protocol.NewSuccessWithMessage(fmt.Sprintf("接收人:%v 未查询到注册的设备信息!", request.Receivers))
  42 + return
  43 + }
  44 + for i := range deviceList {
  45 + receivers = append(receivers, deviceList[i].ClientId)
  46 + }
  47 + requestOriginal.AppKey = appInfo.AppKey
  48 + requestOriginal.AppId = appInfo.AppId
  49 + requestOriginal.Secret = appInfo.AppMasterSecret
  50 + requestOriginal.ClientIdList = receivers
  51 + return NotificationOriginal(header, requestOriginal)
  52 +}
  53 +
  54 +func NotificationOriginal(header *protocol.RequestHeader, request *protocol.PushInfoOriginalRequest) (rsp *protocol.PushInfoResponse, err error) {
  55 + var (
  56 + sendData = make(map[string]interface{})
  57 + clientIds []string
  58 + options []push.Option = []push.Option{
  59 + push.DebugModule(true),
  60 + push.AppId(request.AppId),
  61 + push.AppKey(request.AppKey),
  62 + push.AppMasterSecret(request.Secret),
  63 + push.MsgType(request.Type),
  64 +
  65 + push.Title(request.Title),
  66 + push.Content(request.Content),
  67 + //push.TransmissionContent(utils.JsonAssertString(request.Ext)),
  68 + }
  69 + )
  70 +
  71 + if v, ok := request.Ext["transData"]; ok {
  72 + options = append(options, push.TransmissionContent(utils.JsonAssertString(v)))
  73 + }
  74 + clientIds = request.ClientIdList
  75 + switch len(clientIds) {
  76 + case 0:
  77 + err = protocol.NewCustomMessage(2, "clientId/deviceToken 不能同时为空.")
  78 + return
  79 + case 1:
  80 + options = append(options,
  81 + push.PushType(push.PushToSingle),
  82 + push.ClientId(clientIds[0]),
  83 + )
  84 + break
  85 + default:
  86 + options = append(options,
  87 + push.PushType(push.PushToList),
  88 + push.ClientIds(clientIds),
  89 + )
  90 + break
  91 + }
  92 +
  93 + var pushService push.INotification = &getui.GetuiNotification{}
  94 + err = pushService.Init(options...)
  95 + if err != nil {
  96 + log.Error(err)
  97 + return
  98 + }
  99 + if err = pushService.Send(sendData); err != nil {
  100 + log.Error(err)
  101 + return
  102 + }
  103 + rsp = &protocol.PushInfoResponse{}
  104 + return
  105 +}
  106 +
  107 +//更新设备信息
  108 +func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
  109 + var (
  110 + device *protocol.Device
  111 + )
  112 + rsp = &protocol.UpdateDeviceResponse{}
  113 + rep, _ := repository.NewPushDeviceRepository(nil)
  114 + if device, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil {
  115 + if err == protocol.ERR_DB_NOT_FOUND {
  116 + err = nil
  117 + rep.Save(request)
  118 + return
  119 + }
  120 + log.Error(err)
  121 + return
  122 + }
  123 + if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) {
  124 + err = protocol.NewSuccessWithMessage("更新成功")
  125 + return
  126 + }
  127 + if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken); err != nil {
  128 + log.Error(err)
  129 + }
  130 + err = protocol.NewSuccessWithMessage("更新成功")
  131 + return
  132 +}
1 -package vod 1 +package service
2 2
3 import ( 3 import (
4 - "openapi/internal/aliyun"  
5 - "openapi/protocol" 4 + protocol "openapi/pkg/domain"
  5 + "openapi/pkg/infrastructure/aliyun"
6 ) 6 )
7 7
8 //错误处理 8 //错误处理
1 -package vod 1 +package service
2 2
3 import ( 3 import (
4 - "github.com/astaxie/beego"  
5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 4 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
6 - "openapi/internal/aliyun"  
7 - "openapi/internal/utils"  
8 - "openapi/protocol" 5 + "openapi/pkg/constant"
  6 + protocol "openapi/pkg/domain"
  7 + "openapi/pkg/infrastructure/aliyun"
  8 + "openapi/pkg/infrastructure/utils"
9 ) 9 )
10 10
11 //创建视频上传凭证 11 //创建视频上传凭证
@@ -44,7 +44,7 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl @@ -44,7 +44,7 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
44 return 44 return
45 } 45 }
46 rsp.FileName = fileName 46 rsp.FileName = fileName
47 - rsp.FileURL = up.GetFileUrl(beego.AppConfig.String("cname")) 47 + rsp.FileURL = up.GetFileUrl(constant.CName)
48 return 48 return
49 } 49 }
50 50
  1 +package constant
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 +)
  7 +
  8 +var (
  9 + LogFilePath string = "F:/log/app.log"
  10 + LogLevel string = "error"
  11 +)
  12 +
  13 +func init() {
  14 + LogLevel = config.StringDefault("log_level", LogLevel)
  15 + LogFilePath = config.StringDefault("aliyun_logs_access", LogFilePath)
  16 +}
  17 +
  18 +func DebugConfig() {
  19 + for i := range config.HistorySort {
  20 + k := config.HistorySort[i]
  21 + v, ok := config.History[k]
  22 + if !ok {
  23 + continue
  24 + }
  25 + log.Debug(fmt.Sprintf("【load config】 %v=%v", k, v))
  26 + }
  27 +}
  1 +package constant
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 +)
  6 +
  7 +var config = NewConfigLoader()
  8 +
  9 +type ConfigLoader struct {
  10 + History map[string]interface{}
  11 + HistorySort []string
  12 +}
  13 +
  14 +func NewConfigLoader() *ConfigLoader {
  15 + return &ConfigLoader{
  16 + History: make(map[string]interface{}),
  17 + HistorySort: make([]string, 0),
  18 + }
  19 +}
  20 +
  21 +func (c *ConfigLoader) String(key string) (ret string, ok bool) {
  22 + if ret = beego.AppConfig.String(key); len(ret) != 0 {
  23 + ok = true
  24 + c.SetHistory(key, ret)
  25 + return
  26 + }
  27 + return
  28 +}
  29 +
  30 +func (c *ConfigLoader) StringDefault(key string, defaultValue string) string {
  31 + if ret, ok := c.String(key); ok {
  32 + return ret
  33 + }
  34 + return defaultValue
  35 +}
  36 +
  37 +func (c *ConfigLoader) SetHistory(key string, value interface{}) {
  38 + if _, ok := c.History[key]; !ok {
  39 + c.History[key] = value
  40 + c.HistorySort = append(c.HistorySort, key)
  41 + }
  42 +}
  1 +package constant
  2 +
  3 +import "fmt"
  4 +
  5 +var MYSQL_DB_NAME = "mmm_open_dev"
  6 +var MYSQL_USER = "root"
  7 +var MYSQL_PASSWORD = "sutianxia2018"
  8 +var MYSQL_HOST = "101.37.68.23"
  9 +var MYSQL_PORT = "3306"
  10 +var MYSQL_DATA_SOURCE = ""
  11 +var MYSQL_MAX_IDLE = 100
  12 +var MYSQL_MAX_OPEN = 100
  13 +
  14 +func init() {
  15 + MYSQL_USER = config.StringDefault("MYSQL_USER", MYSQL_USER)
  16 + MYSQL_PASSWORD = config.StringDefault("MYSQL_PASSWORD", MYSQL_PASSWORD)
  17 + MYSQL_HOST = config.StringDefault("MYSQL_HOST", MYSQL_HOST)
  18 + MYSQL_PORT = config.StringDefault("MYSQL_PORT", MYSQL_PORT)
  19 +
  20 + MYSQL_DB_NAME = config.StringDefault("MYSQL_DB_NAME", MYSQL_DB_NAME)
  21 +
  22 + MYSQL_DATA_SOURCE = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai&charset=utf8mb4",
  23 + MYSQL_USER,
  24 + MYSQL_PASSWORD,
  25 + MYSQL_HOST,
  26 + MYSQL_PORT,
  27 + MYSQL_DB_NAME,
  28 + )
  29 +}
  1 +package constant
  2 +
  3 +var (
  4 + RegionID = "cn-shanghai"
  5 + AccessKeyID string = "LTAI4FhiZ3UktC6N1u3H5GFC"
  6 + AccessKeySecret string = "UyspWwdni55CYQ02hUCint4qY2jNYO"
  7 + CName string = "https://media.goexample.live/"
  8 +)
  9 +
  10 +func init() {
  11 + AccessKeyID = config.StringDefault("AccessKeyID", AccessKeyID)
  12 + AccessKeySecret = config.StringDefault("AccessKeySecret", AccessKeySecret)
  13 + CName = config.StringDefault("cname", CName)
  14 +}
1 -package protocol 1 +package domain
2 2
3 const RelateSplit = "/" 3 const RelateSplit = "/"
1 -package protocol 1 +package domain
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
  6 +)
  7 +
  8 +var (
  9 + ERR_DB_NOT_FOUND = fmt.Errorf("db:not found")
5 ) 10 )
6 11
7 //CustomErrParse 解析自定义错误结构体 12 //CustomErrParse 解析自定义错误结构体
1 -package protocol 1 +package domain
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
1 -package protocol 1 +package domain
2 2
3 var errmessge ErrorMap = map[int]string{ 3 var errmessge ErrorMap = map[int]string{
4 0: "成功", 4 0: "成功",
  1 +package domain
  2 +
  3 +/*PushInfo 推送信息*/
  4 +type PushInfoOriginalRequest struct {
  5 + Type int `json:"msgType"`
  6 + ClientIdList []string `json:"clientId"`
  7 + AppKey string `json:"appKey" valid:"Required"`
  8 + Secret string `json:"secret" valid:"Required"`
  9 + AppId string `json:"appId" valid:"Required"`
  10 +
  11 + Title string `json:"title" valid:"Required"`
  12 + Content string `json:"content" valid:"Required"`
  13 + Ext map[string]interface{} `json:"ext"` //key->transData:透传数据
  14 +}
  15 +type PushInfoResponse struct {
  16 +}
  17 +
  18 +/*PushInfo 推送信息*/
  19 +type PushInfoRequest struct {
  20 + Type int `json:"msgType"`
  21 + Receivers []int64 `json:"receivers"` //接受用户id列表
  22 + ProjectKey string `json:"project"` //ability
  23 +
  24 + Title string `json:"title" valid:"Required"`
  25 + Content string `json:"content" valid:"Required"`
  26 + Ext map[string]interface{} `json:"ext"` //key->transData:透传数据
  27 +}
  28 +
  29 +/*UpdateDevice 更新设备*/
  30 +type UpdateDeviceRequest struct {
  31 + Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID
  32 + ClientId string `json:"clientId" valid:"Required"`
  33 + DeviceToken string `json:"deviceToken"`
  34 +}
  35 +type UpdateDeviceResponse struct {
  36 +}
  37 +
  38 +//设备信息
  39 +type Device struct {
  40 + Uid int64
  41 + ClientId string
  42 + DeviceToken string
  43 +}
  44 +
  45 +//应用信息
  46 +type AppInfo struct {
  47 + Id int
  48 + AppKey string
  49 + AppMasterSecret string
  50 + AppId string
  51 + ProjectName string
  52 + ProjectKey string
  53 +}
1 -package protocol 1 +package domain
2 2
3 import "mime/multipart" 3 import "mime/multipart"
4 4
@@ -10,7 +10,6 @@ const ( @@ -10,7 +10,6 @@ const (
10 10
11 /*Image */ 11 /*Image */
12 type FileRequest struct { 12 type FileRequest struct {
13 - //Xxx string`json:"xxx" valid:"Required"`  
14 Files []*multipart.FileHeader 13 Files []*multipart.FileHeader
15 FileType string 14 FileType string
16 } 15 }
1 package aliyun 1 package aliyun
2 2
3 -import "github.com/astaxie/beego"  
4 -  
5 var ( 3 var (
6 - RegionID = "cn-shanghai"  
7 - AccessKeyID = beego.AppConfig.String("AccessKeyID")  
8 - AccessKeySecret = beego.AppConfig.String("AccessKeySecret") 4 +//RegionID = "cn-shanghai"
  5 +//AccessKeyID = beego.AppConfig.String("AccessKeyID")
  6 +//AccessKeySecret = beego.AppConfig.String("AccessKeySecret")
9 ) 7 )
10 8
11 const ( 9 const (
@@ -9,7 +9,8 @@ import ( @@ -9,7 +9,8 @@ import (
9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
11 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time" 11 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
12 - "openapi/internal/utils" 12 + "openapi/pkg/constant"
  13 + "openapi/pkg/infrastructure/utils"
13 "path" 14 "path"
14 "path/filepath" 15 "path/filepath"
15 "time" 16 "time"
@@ -17,13 +18,13 @@ import ( @@ -17,13 +18,13 @@ import (
17 18
18 //客户端 19 //客户端
19 func DefaultVodClient() (client *vod.Client, err error) { 20 func DefaultVodClient() (client *vod.Client, err error) {
20 - return InitVodClient(AccessKeyID, AccessKeySecret) 21 + return InitVodClient(constant.AccessKeyID, constant.AccessKeySecret)
21 } 22 }
22 23
23 //初始化客户端 24 //初始化客户端
24 func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Client, err error) { 25 func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Client, err error) {
25 // 点播服务接入区域 26 // 点播服务接入区域
26 - regionId := RegionID 27 + regionId := constant.RegionID
27 // 创建授权对象 28 // 创建授权对象
28 credential := &credentials.AccessKeyCredential{ 29 credential := &credentials.AccessKeyCredential{
29 accessKeyId, 30 accessKeyId,
@@ -73,7 +74,7 @@ func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (respo @@ -73,7 +74,7 @@ func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (respo
73 if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil { 74 if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
74 log.Error(e) 75 log.Error(e)
75 } else { 76 } else {
76 - response.FileURL = up.GetFileUrl(beego.AppConfig.String("cname")) 77 + response.FileURL = up.GetFileUrl(constant.CName)
77 } 78 }
78 return 79 return
79 } 80 }
  1 +package bgorm
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 + _ "github.com/go-sql-driver/mysql"
  6 + "openapi/pkg/constant"
  7 + _ "openapi/pkg/infrastructure/bgorm/model"
  8 +)
  9 +
  10 +func init() {
  11 + aliasName := "default"
  12 + _ = orm.RegisterDataBase(aliasName, "mysql", constant.MYSQL_DATA_SOURCE)
  13 + orm.SetMaxIdleConns(aliasName, constant.MYSQL_MAX_IDLE)
  14 + orm.SetMaxOpenConns(aliasName, constant.MYSQL_MAX_OPEN)
  15 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type PushAppInfo struct {
  13 + Id int `orm:"column(id);auto" description:"编号"`
  14 + AppKey string `orm:"column(app_key);size(255);null" description:"推送key "`
  15 + AppMasterSecret string `orm:"column(app_master_secret);size(255);null" description:"推送服务端密钥"`
  16 + AppId string `orm:"column(app_id);size(255);null" description:"推送应用编号"`
  17 + ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"`
  18 + ProjectKey string `orm:"column(project_key);size(255);null" description:"项目唯一标识 ability"`
  19 +}
  20 +
  21 +func (t *PushAppInfo) TableName() string {
  22 + return "push_app_info"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(PushAppInfo))
  27 +}
  28 +
  29 +// AddPushAppInfo insert a new PushAppInfo into database and returns
  30 +// last inserted Id on success.
  31 +func AddPushAppInfo(m *PushAppInfo) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetPushAppInfoById retrieves PushAppInfo by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetPushAppInfoById(id int) (v *PushAppInfo, err error) {
  40 + o := orm.NewOrm()
  41 + v = &PushAppInfo{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllPushAppInfo retrieves all PushAppInfo matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllPushAppInfo(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(PushAppInfo))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []PushAppInfo
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdatePushAppInfo updates PushAppInfo by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdatePushAppInfoById(m *PushAppInfo) (err error) {
  129 + o := orm.NewOrm()
  130 + v := PushAppInfo{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeletePushAppInfo deletes PushAppInfo by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeletePushAppInfo(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := PushAppInfo{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&PushAppInfo{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/astaxie/beego/orm"
  7 +)
  8 +
  9 +type PushDeviceInfo struct {
  10 + Id int `orm:"column(id);auto"`
  11 + Uid int64 `orm:"column(uid);null" description:"企业平台用户id (muid)"`
  12 + ClientId string `orm:"column(client_id);size(100);null" description:"设备识别码 推送标识"`
  13 + DeviceToken string `orm:"column(device_token);size(100);null" description:"设备识别码 推送标识"`
  14 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  15 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
  16 +}
  17 +
  18 +func (t *PushDeviceInfo) TableName() string {
  19 + return "push_device_info"
  20 +}
  21 +
  22 +func init() {
  23 + orm.RegisterModel(new(PushDeviceInfo))
  24 +}
  1 +package push
  2 +
  3 +/*
  4 + PushType 推送类型
  5 +*/
  6 +const (
  7 + PushToSingle = iota + 1 //单推
  8 + PushToList //群推
  9 +)
  10 +
  11 +/*
  12 + MsgType 消息类型 -> 决定发送的模板样式
  13 +*/
  14 +const (
  15 + SystemTransmission = iota //系统消息透传
  16 + SystemNotification //系统通知
  17 +)
  1 +package getui
  2 +
  3 +import (
  4 + "crypto/sha256"
  5 + "fmt"
  6 + "github.com/astaxie/beego/httplib"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  8 + "openapi/pkg/infrastructure/push"
  9 + "openapi/pkg/infrastructure/utils"
  10 + "strings"
  11 + "sync"
  12 + "time"
  13 +)
  14 +
  15 +const (
  16 + host = "https://restapi.getui.com"
  17 + pushSingle = "push_single"
  18 + saveListBody = "save_list_body"
  19 + pushList = "push_list"
  20 + authSign = "auth_sign "
  21 +)
  22 +
  23 +var (
  24 + authtoken = ""
  25 + expire time.Time
  26 + authMux sync.RWMutex
  27 + expireSpan = time.Second * 600 //token 10分钟过期
  28 +)
  29 +
  30 +const (
  31 + error_not_auth = "not_auth"
  32 +)
  33 +
  34 +//GetuiNotification 个推消息推送
  35 +type GetuiNotification struct {
  36 + Options *push.Options
  37 + Request *httplib.BeegoHTTPRequest
  38 + retry int
  39 +}
  40 +
  41 +func (notify *GetuiNotification) Init(options ...push.Option) error {
  42 + notify.Options = &push.Options{}
  43 + for _, o := range options {
  44 + o(notify.Options)
  45 + }
  46 + notify.retry = 3
  47 + return nil
  48 +}
  49 +func (notify *GetuiNotification) Send(option map[string]interface{}) (err error) {
  50 + retry := 1
  51 + for {
  52 + switch notify.Options.PushType {
  53 + case push.PushToSingle:
  54 + err = notify.pushToSingle(option)
  55 + case push.PushToList:
  56 + err = notify.pushToList(option)
  57 + default:
  58 + err = notify.pushToSingle(option)
  59 + }
  60 + if err == nil {
  61 + break
  62 + }
  63 + //重试
  64 + if err != nil && retry > notify.retry {
  65 + return err
  66 + }
  67 + log.Error(fmt.Sprintf("【个推】 重试:%v 失败:%v", retry, err))
  68 + retry++
  69 + if retry > notify.retry {
  70 + break
  71 + }
  72 + }
  73 + return nil
  74 +}
  75 +
  76 +//pushToSingle 单推
  77 +func (notify *GetuiNotification) pushToSingle(option map[string]interface{}) (err error) {
  78 + var token string
  79 + if token, err = notify.GetAuthToken(); err != nil {
  80 + return err
  81 + }
  82 +
  83 + var (
  84 + result *Result
  85 + url = notify.Url(notify.Options.AppId, pushSingle)
  86 + m = notify.Message(pushSingle)
  87 + )
  88 + notify.Request = httplib.Post(url)
  89 + notify.Request.Header("authtoken", token)
  90 + notify.Request.JSONBody(m)
  91 + if err = notify.Request.ToJSON(&result); err != nil {
  92 + return err
  93 + }
  94 + notify.print(url, m, result, result)
  95 + if err = handleResult(url, result); err != nil {
  96 + return err
  97 + }
  98 + return nil
  99 +}
  100 +
  101 +//pushToList 群推
  102 +//步骤1.获取token
  103 +//步骤2.save_list_body保存消息共同体
  104 +//步骤3.push_list
  105 +func (notify *GetuiNotification) pushToList(option map[string]interface{}) (err error) {
  106 + var (
  107 + token string
  108 + taskId string
  109 + )
  110 + if token, err = notify.GetAuthToken(); err != nil {
  111 + return err
  112 + }
  113 + if taskId, err = notify.saveListBody(token, option); err != nil {
  114 + return err
  115 + }
  116 + var (
  117 + result *Result
  118 + url = notify.Url(notify.Options.AppId, pushList)
  119 + m = struct {
  120 + Cid []string `json:"cid"`
  121 + TaskId string `json:"taskid"`
  122 + NeedDetail bool `json:"need_detail"`
  123 + }{
  124 + Cid: notify.Options.ClientIds,
  125 + TaskId: taskId,
  126 + NeedDetail: true,
  127 + }
  128 + )
  129 + notify.Request = httplib.Post(url)
  130 + notify.Request.Header("authtoken", token)
  131 + notify.Request.JSONBody(m)
  132 + if err = notify.Request.ToJSON(&result); err != nil {
  133 + return err
  134 + }
  135 + notify.print(url, m, result, result)
  136 + if err = handleResult(url, result); err != nil {
  137 + return err
  138 + }
  139 + return nil
  140 +}
  141 +
  142 +//saveListBody 保存消息共同体
  143 +func (notify *GetuiNotification) saveListBody(token string, option map[string]interface{}) (taskId string, err error) {
  144 + var (
  145 + result *Result
  146 + url = notify.Url(notify.Options.AppId, saveListBody)
  147 + m = notify.Message(saveListBody)
  148 + )
  149 + notify.Request = httplib.Post(url)
  150 + notify.Request.Header("authtoken", token)
  151 + notify.Request.JSONBody(m)
  152 + if err = notify.Request.ToJSON(&result); err != nil {
  153 + return
  154 + }
  155 + notify.print(url, m, result, result)
  156 + if err = handleResult(url, result); err != nil {
  157 + return
  158 + }
  159 + taskId = result.TaskId
  160 + return
  161 +}
  162 +
  163 +//Message 组装消息体
  164 +func (notify *GetuiNotification) Message(method string) interface{} {
  165 + var m interface{}
  166 + switch notify.Options.MsgType {
  167 + case push.SystemNotification:
  168 + t := NewNotificationTemplate(notify.Options)
  169 + if method == saveListBody {
  170 + t.ClientId = ""
  171 + t.RequestId = ""
  172 + }
  173 + m = t
  174 + break
  175 + case push.SystemTransmission:
  176 + t := NewTransmissionTemplate(notify.Options)
  177 + if method == saveListBody {
  178 + t.ClientId = ""
  179 + t.RequestId = ""
  180 + }
  181 + m = t
  182 + break
  183 + default:
  184 + m = NewNotificationTemplate(notify.Options)
  185 + break
  186 + }
  187 + return m
  188 +}
  189 +
  190 +//Url 组装请求地址
  191 +func (notify *GetuiNotification) Url(param string, method string) string {
  192 + return fmt.Sprintf("%v/v1/%v/%v", host, param, method)
  193 +}
  194 +
  195 +//GetAuthToken 获取token
  196 +func (notify *GetuiNotification) GetAuthToken() (token string, err error) {
  197 + if authtoken != "" && expire.Unix() > time.Now().Unix() {
  198 + token = authtoken
  199 + return
  200 + }
  201 +
  202 + authMux.Lock()
  203 + defer authMux.Unlock()
  204 + url := notify.Url(notify.Options.AppId, authSign)
  205 + notify.Request = httplib.Post(strings.TrimSpace(url))
  206 + req := &AuthSignRequest{
  207 + Timestamp: fmt.Sprintf("%v", time.Now().Unix()*1000), //"1589797286000",//
  208 + AppKey: notify.Options.AppKey,
  209 + }
  210 + req.Sign = sign(req.AppKey, req.Timestamp, notify.Options.AppMasterSecret)
  211 + _, err = notify.Request.JSONBody(req)
  212 + if err != nil {
  213 + return
  214 + }
  215 + var rsp *AuthSignResponse
  216 + err = notify.Request.ToJSON(&rsp)
  217 + notify.print(url, req, rsp, rsp.Result)
  218 + if err != nil {
  219 + return
  220 + }
  221 + if err = handleResult(url, rsp.Result); err != nil {
  222 + return
  223 + }
  224 + authtoken = rsp.AuthToken
  225 + token = rsp.AuthToken
  226 + expire = time.Now().Add(expireSpan)
  227 + log.Info(fmt.Sprintf("【个推】token:%v expire:%v", token, expire))
  228 + return
  229 +}
  230 +
  231 +//打印日志 debug_module=true print debug log
  232 +func (notify *GetuiNotification) print(url string, v interface{}, rsp interface{}, result *Result) {
  233 + if !notify.Options.DebugModule {
  234 + return
  235 + }
  236 + log.Error(fmt.Sprintf("【个推】 url:%v \n request:%v \n response:%v 结果:%v", url, utils.JsonAssertString(v), utils.JsonAssertString(rsp), result.Result))
  237 +}
  238 +
  239 +//处理结果
  240 +func handleResult(url string, result *Result) (err error) {
  241 + if strings.ToLower(result.Result) == "ok" {
  242 + return
  243 + }
  244 + switch result.Result {
  245 + case error_not_auth:
  246 + setToken("")
  247 + break
  248 + }
  249 + err = fmt.Errorf("grequest fail,url:%v error:%v", url, result.Result)
  250 + return err
  251 +}
  252 +func sign(appkey, timestamp, mastersecret string) string {
  253 + sha := sha256.New()
  254 + sha.Write([]byte(appkey + timestamp + mastersecret))
  255 + return fmt.Sprintf("%x", sha.Sum(nil))
  256 +}
  257 +
  258 +func setToken(token string) {
  259 + authMux.Lock()
  260 + defer authMux.Unlock()
  261 + authtoken = ""
  262 +}
  1 +package getui
  2 +
  3 +import (
  4 + "openapi/pkg/infrastructure/push"
  5 + "openapi/pkg/infrastructure/utils"
  6 + "testing"
  7 +)
  8 +
  9 +func TestGetui(t *testing.T) {
  10 + var param = make(map[string]interface{})
  11 + param["A"] = "A1"
  12 + param["B"] = 2
  13 + param["transData"] = struct{ Id int }{Id: 10}
  14 + notification := &GetuiNotification{}
  15 + err := notification.Init(
  16 + push.DebugModule(true),
  17 +
  18 + push.AppId("TkpBI4awmg9fBUx3NWKXS6"),
  19 + push.AppKey("5AjJeDOSOZ5ojQpXJFjhg9"),
  20 + push.AppMasterSecret("9VnM8MaA6n84Y5VnOIaSvA"),
  21 + //单推
  22 + push.PushType(push.PushToSingle),
  23 + push.ClientId("b5fff5f6b0af551da5f381fa47991828"),
  24 + //群推
  25 + //push.PushType(push.PushToList),
  26 + //push.ClientIds([]string{"b5fff5f6b0af551da5f381fa47991828"}),
  27 +
  28 + push.MsgType(push.SystemTransmission), //push.SystemNotification
  29 + push.Title("测试 hello"),
  30 + push.Content("hello content"),
  31 +
  32 + push.TransmissionContent(utils.JsonAssertString(param["transData"])),
  33 + push.Extra(param),
  34 + )
  35 + if err != nil {
  36 + t.Fatal(err)
  37 + }
  38 + err = notification.Send(param)
  39 + if err != nil {
  40 + t.Fatal(err)
  41 + }
  42 +}
  43 +
  44 +func TestGetuiPrd(t *testing.T) {
  45 + var param = make(map[string]interface{})
  46 + param["A"] = "A1"
  47 + param["B"] = 2
  48 + param["transData"] = struct {
  49 + Id int `json:"id"`
  50 + }{Id: 1}
  51 + notification := &GetuiNotification{}
  52 + err := notification.Init(
  53 + push.DebugModule(true),
  54 +
  55 + push.AppId("WgrbaaStTk7JElrXOCgUg6"),
  56 + push.AppKey("FG5lbqVrHa5rS9NVfxNP7"),
  57 + push.AppMasterSecret("FW3jMNLJrRARYKv2iqA5H5"),
  58 + //单推
  59 + //push.PushType(push.PushToSingle),
  60 + //push.ClientId("502f4fd7ba5df15ac6b3d5c561efd9ca"),
  61 + //群推
  62 + push.PushType(push.PushToList),
  63 + push.ClientIds([]string{"502f4fd7ba5df15ac6b3d5c561efd9ca"}),
  64 +
  65 + push.MsgType(push.SystemTransmission),
  66 + push.Title("hello"),
  67 + push.Content("hello content"),
  68 +
  69 + push.TransmissionContent(utils.JsonAssertString(param["transData"])),
  70 + push.Extra(param),
  71 + )
  72 + if err != nil {
  73 + t.Fatal(err)
  74 + }
  75 + err = notification.Send(param)
  76 + if err != nil {
  77 + t.Fatal(err)
  78 + }
  79 +}
  1 +package getui
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
  5 + "openapi/pkg/infrastructure/push"
  6 +)
  7 +
  8 +//1.消息模板
  9 +type NotificationTemplate struct {
  10 + *Template
  11 + Notification *Notification `json:"notification"`
  12 +}
  13 +
  14 +//1.新建通知模板
  15 +func NewNotificationTemplate(options *push.Options) *NotificationTemplate {
  16 + return &NotificationTemplate{
  17 + Template: NewTemplate(options),
  18 + Notification: &Notification{
  19 + Style: (&Style{}).SetStyle0(options),
  20 + Transmission: NewTransmission(options),
  21 + },
  22 + }
  23 +}
  24 +
  25 +//2.透传模板
  26 +type TransmissionTemplate struct {
  27 + *Template
  28 + Transmission *Transmission `json:"transmission"`
  29 + PushInfo *PushInfo `json:"push_info"`
  30 +}
  31 +
  32 +//2.新建透传模板
  33 +func NewTransmissionTemplate(options *push.Options) *TransmissionTemplate {
  34 + return &TransmissionTemplate{
  35 + Template: NewTemplate(options),
  36 + Transmission: NewTransmission(options),
  37 + PushInfo: NewPushInfo(options),
  38 + }
  39 +}
  40 +
  41 +type Template struct {
  42 + ClientId string `json:"cid,omitempty"`
  43 + RequestId string `json:"requestid,omitempty"`
  44 + Message *Message `json:"message"`
  45 +}
  46 +type Notification struct {
  47 + Style *Style `json:"style"`
  48 + *Transmission
  49 +}
  50 +type Message struct {
  51 + AppKey string `json:"appkey"`
  52 + IsOffline bool `json:"is_offline"`
  53 + MsgType string `json:"msgtype"`
  54 +}
  55 +
  56 +//透传
  57 +type Transmission struct {
  58 + TransmissionType bool `json:"transmission_type"` //收到消息是否立即启动应用,true为立即启动,false则广播等待启动,默认是否
  59 + TransmissionContent string `json:"transmission_content,omitempty"` //透传内容
  60 + DurationBegin string `json:"duration_begin,omitempty"`
  61 + DurationEnd string `json:"duration_end,omitempty"`
  62 +}
  63 +
  64 +func (o *Transmission) SetTransmissionType(t bool) {
  65 + o.TransmissionType = t
  66 +}
  67 +func (o *Transmission) SetTransmissionContent(s string) {
  68 + o.TransmissionContent = s
  69 +}
  70 +func (o *Transmission) SetDuration(begin, end string) {
  71 + o.DurationBegin = begin
  72 + o.DurationEnd = end
  73 +}
  74 +
  75 +func NewTemplate(options *push.Options) *Template {
  76 + return &Template{
  77 + Message: NewMessage(options),
  78 + ClientId: options.ClientId,
  79 + RequestId: genRequestId(),
  80 + }
  81 +}
  82 +func NewTransmission(options *push.Options) *Transmission {
  83 + t := &Transmission{}
  84 + if len(options.TransmissionContent) == 0 {
  85 + //t.SetTransmissionType(false)
  86 + return t
  87 + }
  88 + t.SetTransmissionType(false)
  89 + t.SetTransmissionContent(options.TransmissionContent)
  90 + return t
  91 +}
  92 +func NewMessage(options *push.Options) *Message {
  93 + return &Message{
  94 + AppKey: options.AppKey,
  95 + IsOffline: true,
  96 + MsgType: resolveMsgType(options.MsgType),
  97 + }
  98 +}
  99 +func resolveMsgType(msgType int) string {
  100 + /*
  101 + 消息应用类型,
  102 + 可选项:notification、link、notypopload、startactivity, transmission
  103 + */
  104 + switch msgType {
  105 + case push.SystemNotification:
  106 + return "notification"
  107 + case push.SystemTransmission:
  108 + return "transmission"
  109 + }
  110 + return "notification"
  111 +}
  112 +func genRequestId() string {
  113 + return uid.NewV1().StringNoDash()
  114 +}
  115 +
  116 +//样式 0:系统样式 1:个推样式 4:纯图样式 6:展开通知样式
  117 +type Style struct {
  118 + Type int `json:"type"` //样式类型
  119 + Text string `json:"text"` //通知内容
  120 + Title string `json:"title"` //通知标题
  121 + Logo string `json:"logo,omitempty"` //通知的图标名称,包含后缀名(需要在客户端开发时嵌入),如“push.png”
  122 + //IsRing bool `json:"is_ring"` //收到通知是否响铃:true响铃,false不响铃。默认响铃
  123 + //IsVibrate bool `json:"is_vibrate"` //收到通知是否振动:true振动,false不振动。默认振动
  124 + NotifyId int `json:"notify_id"` //需要被覆盖的消息已经增加了notifyId字段,用于实现下发消息的覆盖。新的消息使用相同的notifyId下发。
  125 +}
  126 +
  127 +//设置默认样式 0
  128 +func (s *Style) SetStyle0(options *push.Options) *Style {
  129 + s.Type = 0
  130 + s.Title = options.Title
  131 + s.Text = options.Content
  132 + s.Logo = "push.png" //TODO:设置Logo地址
  133 + s.NotifyId = 1
  134 + return s
  135 +}
  136 +
  137 +//认证请求/应答
  138 +type AuthSignRequest struct {
  139 + Sign string `json:"sign"`
  140 + Timestamp string `json:"timestamp"`
  141 + AppKey string `json:"appkey"`
  142 +}
  143 +type AuthSignResponse struct {
  144 + *Result
  145 + AuthToken string `json:"auth_token"`
  146 +}
  147 +
  148 +//应答结果
  149 +type Result struct {
  150 + Result string `json:"result"`
  151 + TaskId string `json:"taskid"`
  152 + Status string `json:"status"`
  153 + Desc string `json:"desc"`
  154 +}
  155 +
  156 +//透传附加的推送信息
  157 +func NewPushInfo(options *push.Options) (v *PushInfo) {
  158 + v = &PushInfo{
  159 + Aps: NewAps(options),
  160 + }
  161 + return
  162 +}
  163 +func NewAps(options *push.Options) (v *Aps) {
  164 + v = &Aps{
  165 + Alert: NewAlert(options),
  166 + AutoBadge: "+1",
  167 + ContentAvailable: 1,
  168 + }
  169 + return
  170 +}
  171 +func NewAlert(options *push.Options) (v *Alert) {
  172 + v = &Alert{
  173 + Title: options.Title,
  174 + Body: options.Content,
  175 + }
  176 + return
  177 +}
  178 +
  179 +type PushInfo struct {
  180 + Aps *Aps `json:"aps"`
  181 +}
  182 +type Aps struct {
  183 + Alert *Alert `json:"alert"`
  184 + AutoBadge string `json:"autoBadge"` //用于计算应用上面未读数字
  185 + ContentAvailable int `json:"content-available"` //推送直接带有透传数据 0:有通知栏消息 1:无通知栏消息
  186 + Payload string `json:"payload,omitempty"`
  187 +}
  188 +type Alert struct {
  189 + Title string `json:"title"`
  190 + Body string `json:"body"`
  191 +}
  1 +package push
  2 +
  3 +type Options struct {
  4 + AppId string
  5 + AppKey string
  6 + AppSecret string
  7 + AppMasterSecret string
  8 + ClientId string
  9 + ClientIds []string
  10 +
  11 + MsgType int //消息类型
  12 + PushType int //推送类型
  13 +
  14 + Title string
  15 + Content string
  16 + Extra interface{} //扩展数据
  17 + TransmissionContent string //透传内容
  18 +
  19 + DebugModule bool
  20 +}
  21 +type Option func(o *Options)
  22 +
  23 +//个推appId
  24 +func AppId(id string) Option {
  25 + return func(o *Options) {
  26 + o.AppId = id
  27 + }
  28 +}
  29 +
  30 +//个推appKey
  31 +func AppKey(key string) Option {
  32 + return func(o *Options) {
  33 + o.AppKey = key
  34 + }
  35 +}
  36 +
  37 +//个推appSecret
  38 +func AppSecret(secret string) Option {
  39 + return func(o *Options) {
  40 + o.AppSecret = secret
  41 + }
  42 +}
  43 +
  44 +//个推appMasterSecret
  45 +func AppMasterSecret(secret string) Option {
  46 + return func(o *Options) {
  47 + o.AppMasterSecret = secret
  48 + }
  49 +}
  50 +
  51 +//个推 app clientId
  52 +func ClientId(clientId string) Option {
  53 + return func(o *Options) {
  54 + o.ClientId = clientId
  55 + }
  56 +}
  57 +func ClientIds(clientId []string) Option {
  58 + return func(o *Options) {
  59 + o.ClientIds = clientId
  60 + }
  61 +}
  62 +
  63 +//消息类型
  64 +func MsgType(msgType int) Option {
  65 + return func(o *Options) {
  66 + o.MsgType = msgType
  67 + }
  68 +}
  69 +
  70 +//推送类型
  71 +func PushType(pushType int) Option {
  72 + return func(o *Options) {
  73 + o.PushType = pushType
  74 + }
  75 +}
  76 +
  77 +//消息内容
  78 +func Title(title string) Option {
  79 + return func(o *Options) {
  80 + o.Title = title
  81 + }
  82 +}
  83 +func Content(content string) Option {
  84 + return func(o *Options) {
  85 + o.Content = content
  86 + }
  87 +}
  88 +func Extra(extra interface{}) Option {
  89 + return func(o *Options) {
  90 + o.Extra = extra
  91 + }
  92 +}
  93 +func TransmissionContent(content string) Option {
  94 + return func(o *Options) {
  95 + o.TransmissionContent = content
  96 + }
  97 +}
  98 +func DebugModule(module bool) Option {
  99 + return func(o *Options) {
  100 + o.DebugModule = module
  101 + }
  102 +}
  103 +
  104 +const (
  105 + Message = iota + 1
  106 + Notification
  107 +)
  1 +package push
  2 +
  3 +type INotification interface {
  4 + Init(option ...Option) error
  5 + Send(option map[string]interface{}) error
  6 +}
  1 +package umeng
  2 +
  3 +const (
  4 + Android = iota + 1
  5 + IPhone
  6 + IPad
  7 +)
  8 +const (
  9 + ProjectDefault = "default"
  10 +)
  11 +
  12 +var UMAppAuths UMAppAuth
  13 +
  14 +func init() {
  15 + UMAppAuths = map[string]*AppAuth{
  16 + ProjectDefault: NewAppAuth(ProjectDefault).
  17 + AddAuth(Android, Auth{}).
  18 + AddAuth(IPhone, Auth{}),
  19 + }
  20 +}
  21 +
  22 +type UMAppAuth map[string]*AppAuth
  23 +
  24 +func (a UMAppAuth) DefaultAppAuth() *AppAuth {
  25 + return a.GetAppAuth(ProjectDefault)
  26 +}
  27 +func (a UMAppAuth) GetAppAuth(appName string) *AppAuth {
  28 + if auth, ok := a[appName]; ok {
  29 + return auth
  30 + }
  31 + return a.GetAppAuth(ProjectDefault)
  32 +}
  33 +
  34 +type AppAuth struct {
  35 + AppName string //app名称
  36 + AppAuthMap map[int]Auth //android ios ipad
  37 +}
  38 +
  39 +//新建
  40 +func NewAppAuth(appName string) *AppAuth {
  41 + return &AppAuth{
  42 + AppName: appName,
  43 + AppAuthMap: make(map[int]Auth),
  44 + }
  45 +}
  46 +
  47 +//添加凭证
  48 +func (a *AppAuth) AddAuth(t int, auth Auth) *AppAuth {
  49 + if _, ok := a.AppAuthMap[t]; !ok {
  50 + a.AppAuthMap[t] = auth
  51 + }
  52 + return a
  53 +}
  54 +
  55 +//凭证
  56 +type Auth struct {
  57 + AppKey string //应用唯一标识
  58 + AppMasterSecret string //服务器秘钥,用于服务器端调用API请求时对发送内容做签名验证
  59 +}
  1 +package umeng
  2 +
  3 +import (
  4 + "crypto/md5"
  5 + "encoding/json"
  6 + "fmt"
  7 + "github.com/astaxie/beego/httplib"
  8 + "io/ioutil"
  9 + "net/http"
  10 + "openapi/pkg/infrastructure/push"
  11 + "strings"
  12 + "time"
  13 +)
  14 +
  15 +var (
  16 + Host = "http://msg.umeng.com"
  17 + ApiSend = "/api/send"
  18 + UploadPath = "/upload"
  19 +)
  20 +
  21 +var FiledErrorFormat = "缺少字段:%v"
  22 +var FiledErrorFormatFunc = func(filed string) error {
  23 + return fmt.Errorf(FiledErrorFormat, filed)
  24 +}
  25 +
  26 +const (
  27 + AppKey = "appkey"
  28 + Timestamp = "timestamp"
  29 + Type = "type"
  30 + ProductionMode = "production_mode"
  31 + DeviceTokens = "device_tokens"
  32 + Payload = "payload"
  33 + Policy = "policy"
  34 + Description = "description"
  35 +
  36 + DisplayType = "displayType"
  37 + Body = "body"
  38 + Ticker = "ticker" // 必填,通知栏提示文字
  39 + Title = "title" // 必填,通知标题
  40 + Text = "text" //必填,通知文字描述
  41 + /*
  42 + // 可选,默认为"go_app",值可以为:
  43 + // "go_app": 打开应用
  44 + // "go_url": 跳转到URL
  45 + // "go_activity": 打开特定的activity
  46 + // "go_custom": 用户自定义内容。
  47 + */
  48 + AfterOpen = "after_open"
  49 + Extra = "extra"
  50 +)
  51 +
  52 +const (
  53 + Message = "message"
  54 + Notification = "notification"
  55 +)
  56 +const (
  57 + ExpireSpan = time.Second * 60 * 60 * 24
  58 +)
  59 +
  60 +type SetPayload func(msg *UnicastMsg, option map[string]interface{}) error
  61 +
  62 +type UmengNotification struct {
  63 + Auth *Auth
  64 + Request *httplib.BeegoHTTPRequest
  65 +}
  66 +
  67 +func (notify *UmengNotification) Init(options ...push.Option) error {
  68 + return nil
  69 +}
  70 +func (notify *UmengNotification) Send(option map[string]interface{}) error {
  71 + var (
  72 + setPayload SetPayload = SetAndroidPayload
  73 + body []byte
  74 + err error
  75 + httpRsp *http.Response
  76 + ret = make(map[string]interface{})
  77 + data []byte
  78 + )
  79 + if option["DeviceType"].(int) == 1 {
  80 + setPayload = SetAndroidPayload
  81 + }
  82 + if body, err = notify.PostBody(option, setPayload); err != nil {
  83 + return err
  84 + }
  85 + notify.Request = httplib.Post(notify.Url(ApiSend, body))
  86 + notify.Request.Body(body)
  87 +
  88 + if httpRsp, err = notify.Request.DoRequest(); err != nil {
  89 + return err
  90 + }
  91 + data, err = ioutil.ReadAll(httpRsp.Body)
  92 + defer httpRsp.Body.Close()
  93 + if err != nil {
  94 + return err
  95 + }
  96 + if err = json.Unmarshal(data, &ret); err != nil {
  97 + return err
  98 + }
  99 + if status, ok := ret["ret"]; ok {
  100 + if strings.EqualFold(fmt.Sprintf("%v", status), "SUCCESS") {
  101 + return nil
  102 + }
  103 + return fmt.Errorf("response:%v fail", ret)
  104 + }
  105 + return fmt.Errorf("response:%v invaild", ret)
  106 +}
  107 +func (notify *UmengNotification) PostBody(option map[string]interface{}, setPayload SetPayload) (body []byte, err error) {
  108 + var postData = new(UnicastMsg)
  109 + postData.AppKey = notify.Auth.AppKey
  110 + postData.Timestamp = fmt.Sprintf("%v", time.Now().Unix())
  111 + postData.ProductionMode = fmt.Sprintf("%v", true)
  112 + postData.Type = fmt.Sprintf("%v", option[Type])
  113 + postData.DeviceTokens = fmt.Sprintf("%v", option[DeviceTokens])
  114 + postData.Policy = MsgPolicy{ExpireTime: time.Now().Add(ExpireSpan).Format("2006-01-02 15:04:05")}
  115 + if err = setPayload(postData, option); err != nil {
  116 + return
  117 + }
  118 + postData.Description = fmt.Sprintf("%v", option[Title])
  119 + if body, err = json.Marshal(postData); err != nil {
  120 + return
  121 + }
  122 + return
  123 +}
  124 +func (notify *UmengNotification) Url(method string, body []byte) string {
  125 + var url string = fmt.Sprintf("%v%v", Host, method)
  126 + sign := fmt.Sprintf("%x", md5.Sum([]byte("POST"+url+string(body)+notify.Auth.AppMasterSecret)))
  127 + url = fmt.Sprintf("%v?sign=%v", url, sign)
  128 + return url
  129 +}
  130 +
  131 +type UnicastMsg struct {
  132 + AppKey string `json:"appkey"`
  133 + Timestamp string `json:"timestamp"`
  134 + Type string `json:"type"` //发送类型 单播 列播...
  135 + ProductionMode string `json:"production_mode"`
  136 + DeviceTokens string `json:"device_tokens"`
  137 + Payload MsgPayload `json:"payload"`
  138 + Policy MsgPolicy `json:"policy"`
  139 + Description string `json:"description"`
  140 +}
  141 +type MsgPayload map[string]interface{}
  142 +type MsgPolicy struct {
  143 + ExpireTime string `json:"expire_time"`
  144 +}
  145 +
  146 +//设置payload
  147 +func SetAndroidPayload(msg *UnicastMsg, option map[string]interface{}) error {
  148 + msg.Payload = make(map[string]interface{})
  149 + var (
  150 + displayType string
  151 + ok bool
  152 + )
  153 + if _, ok = option[DisplayType]; !ok {
  154 + return FiledErrorFormatFunc(DisplayType)
  155 + }
  156 + displayType = option[DisplayType].(string)
  157 + switch displayType {
  158 + case Message:
  159 + break
  160 + case Notification:
  161 + var payloadBody = make(map[string]interface{})
  162 + //if _,ok =option[Title];!ok{
  163 + // return FiledErrorFormatFunc(Title)
  164 + //}
  165 + //if _,ok =option[Text];!ok{
  166 + // return FiledErrorFormatFunc(Text)
  167 + //}
  168 + //if _,ok =option[Extra];ok{
  169 + // payloadBody[Extra]=option[Extra]
  170 + //}
  171 + payloadBody[Ticker] = option[Title]
  172 + payloadBody[Title] = option[Title]
  173 + payloadBody[Text] = option[Text]
  174 + payloadBody[AfterOpen] = "go_app"
  175 + msg.Payload[Body] = payloadBody
  176 + break
  177 + default:
  178 + return FiledErrorFormatFunc(DisplayType)
  179 + break
  180 + }
  181 + return nil
  182 +}
  1 +package repository
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 + "openapi/pkg/domain"
  6 + "openapi/pkg/infrastructure/bgorm/model"
  7 +)
  8 +
  9 +type AppInfoRepository struct {
  10 +}
  11 +
  12 +func (repository *AppInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.AppInfo, error) {
  13 + o := orm.NewOrm()
  14 + model := new(models.PushAppInfo)
  15 + qs := o.QueryTable(model).Filter("project_key", queryOptions["project_key"])
  16 + err := qs.One(model)
  17 + if err != nil {
  18 + return nil, err
  19 + }
  20 + return repository.transformBgormModelToDomainModel(model)
  21 +}
  22 +
  23 +func (repository *AppInfoRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.AppInfo, err error) {
  24 + return
  25 +}
  26 +
  27 +func (repository *AppInfoRepository) transformBgormModelToDomainModel(model *models.PushAppInfo) (*domain.AppInfo, error) {
  28 + return &domain.AppInfo{
  29 + Id: model.Id,
  30 + AppKey: model.AppKey,
  31 + AppMasterSecret: model.AppMasterSecret,
  32 + AppId: model.AppId,
  33 + ProjectName: model.ProjectName,
  34 + ProjectKey: model.ProjectKey,
  35 + }, nil
  36 +}
  37 +
  38 +func NewAppInfoRepository(transactionContext interface{}) (*AppInfoRepository, error) {
  39 + if transactionContext == nil {
  40 + return &AppInfoRepository{}, nil
  41 + } else {
  42 + return &AppInfoRepository{}, nil
  43 + }
  44 +}
  1 +package repository
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 + "openapi/pkg/domain"
  6 + "openapi/pkg/infrastructure/bgorm/model"
  7 + "strings"
  8 + "time"
  9 +)
  10 +
  11 +type PushDeviceRepository struct {
  12 +}
  13 +
  14 +func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) error {
  15 + o := orm.NewOrm()
  16 +
  17 + m := &models.PushDeviceInfo{
  18 + Uid: device.Muid,
  19 + ClientId: strings.TrimSpace(device.ClientId),
  20 + DeviceToken: strings.TrimSpace(device.DeviceToken),
  21 + CreateAt: time.Now(),
  22 + UpdateAt: time.Now(),
  23 + }
  24 + _, err := o.Insert(m)
  25 + return err
  26 +}
  27 +
  28 +func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interface{}) (*domain.Device, error) {
  29 + o := orm.NewOrm()
  30 + model := new(models.PushDeviceInfo)
  31 + qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"])
  32 + err := qs.One(model)
  33 + if err != nil {
  34 + err = domain.ERR_DB_NOT_FOUND
  35 + return nil, err
  36 + }
  37 + return repository.transformBgormModelToDomainModel(model)
  38 +}
  39 +
  40 +func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.Device, err error) {
  41 + o := orm.NewOrm()
  42 + model := new(models.PushDeviceInfo)
  43 + var ms []*models.PushDeviceInfo
  44 + qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"])
  45 + qs.All(&ms)
  46 + if len(ms) == 0 {
  47 + return
  48 + }
  49 + for i := range ms {
  50 + v, _ := repository.transformBgormModelToDomainModel(ms[i])
  51 + rsp = append(rsp, v)
  52 + }
  53 + return
  54 +}
  55 +
  56 +func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error {
  57 + o := orm.NewOrm()
  58 + _, err := o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now() where uid=?", clientId, deviceToken, uid).Exec()
  59 + if err != nil {
  60 + return err
  61 + }
  62 + return nil
  63 +}
  64 +
  65 +func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model *models.PushDeviceInfo) (*domain.Device, error) {
  66 + return &domain.Device{
  67 + Uid: model.Uid,
  68 + ClientId: model.ClientId,
  69 + DeviceToken: model.DeviceToken,
  70 + }, nil
  71 +}
  72 +
  73 +func NewPushDeviceRepository(transactionContext interface{}) (*PushDeviceRepository, error) {
  74 + if transactionContext == nil {
  75 + return &PushDeviceRepository{}, nil
  76 + } else {
  77 + return &PushDeviceRepository{}, nil
  78 + }
  79 +}
@@ -90,6 +90,13 @@ func JsonUnmarshal(jsonData string, v interface{}) { @@ -90,6 +90,13 @@ func JsonUnmarshal(jsonData string, v interface{}) {
90 } 90 }
91 } 91 }
92 92
  93 +func JsonAssertString(v interface{}) string {
  94 + if data, e := json.Marshal(v); e == nil {
  95 + return string(data)
  96 + }
  97 + return ""
  98 +}
  99 +
93 //深度拷贝 100 //深度拷贝
94 func DeepCopy(dst, src interface{}) error { 101 func DeepCopy(dst, src interface{}) error {
95 var buf bytes.Buffer 102 var buf bytes.Buffer
  1 +package log
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  7 + "openapi/pkg/constant"
  8 + "openapi/pkg/infrastructure/utils"
  9 +)
  10 +
  11 +func init() {
  12 + log.InitLog(config.Logger{
  13 + Filename: constant.LogFilePath,
  14 + Level: fmt.Sprintf("%v", utils.ResolveLogLevel(constant.LogLevel)),
  15 + })
  16 +}
  1 +package beego
  2 +
  3 +import (
  4 + _ "openapi/pkg/port/beego/routers"
  5 +)
  6 +
  7 +func init() {
  8 +
  9 +}
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 "fmt" 7 "fmt"
8 "github.com/astaxie/beego/plugins/cors" 8 "github.com/astaxie/beego/plugins/cors"
9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/time" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
10 - "openapi/protocol" 10 + protocol "openapi/pkg/domain"
11 "strconv" 11 "strconv"
12 "strings" 12 "strings"
13 13
  1 +package v1
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + push "openapi/pkg/application/push/service"
  7 + protocol "openapi/pkg/domain"
  8 + "openapi/pkg/port/beego/controllers"
  9 +)
  10 +
  11 +type PushController struct {
  12 + controllers.BaseController
  13 +}
  14 +
  15 +//推送信息 PushInfo
  16 +// @router /pushInfo [post]
  17 +func (this *PushController) PushInfo() {
  18 + var msg *protocol.ResponseMessage
  19 + defer func() {
  20 + this.Resp(msg)
  21 + }()
  22 + var request *protocol.PushInfoRequest
  23 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  24 + log.Error(err)
  25 + msg = protocol.BadRequestParam(1)
  26 + return
  27 + }
  28 + if b, m := this.Valid(request); !b {
  29 + msg = m
  30 + return
  31 + }
  32 + header := controllers.GetRequestHeader(this.Ctx)
  33 + msg = protocol.NewReturnResponse(push.Notification(header, request))
  34 +}
  35 +
  36 +//原生推送信息 PushInfoOriginal
  37 +// @router /pushInfoOriginal [post]
  38 +func (this *PushController) PushInfoOriginal() {
  39 + var msg *protocol.ResponseMessage
  40 + defer func() {
  41 + this.Resp(msg)
  42 + }()
  43 + var request *protocol.PushInfoOriginalRequest
  44 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  45 + log.Error(err)
  46 + msg = protocol.BadRequestParam(1)
  47 + return
  48 + }
  49 + if b, m := this.Valid(request); !b {
  50 + msg = m
  51 + return
  52 + }
  53 + header := controllers.GetRequestHeader(this.Ctx)
  54 + msg = protocol.NewReturnResponse(push.NotificationOriginal(header, request))
  55 +}
  56 +
  57 +//UpdateDevice
  58 +//@router /updateDevice [post]
  59 +func (this *PushController) UpdateDevice() {
  60 + var msg *protocol.ResponseMessage
  61 + defer func() {
  62 + this.Resp(msg)
  63 + }()
  64 + var request *protocol.UpdateDeviceRequest
  65 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  66 + log.Error(err)
  67 + msg = protocol.BadRequestParam(1)
  68 + return
  69 + }
  70 + if b, m := this.Valid(request); !b {
  71 + msg = m
  72 + return
  73 + }
  74 + header := controllers.GetRequestHeader(this.Ctx)
  75 + msg = protocol.NewReturnResponse(push.UpdateDevice(header, request))
  76 +}
@@ -3,10 +3,10 @@ package v1 @@ -3,10 +3,10 @@ package v1
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
6 - "openapi/controllers"  
7 - "openapi/internal/aliyun"  
8 - "openapi/protocol"  
9 - "openapi/services/vod" 6 + vod "openapi/pkg/application/vod/service"
  7 + "openapi/pkg/domain"
  8 + "openapi/pkg/infrastructure/aliyun"
  9 + "openapi/pkg/port/beego/controllers"
10 ) 10 )
11 11
12 type VodController struct { 12 type VodController struct {
@@ -16,14 +16,14 @@ type VodController struct { @@ -16,14 +16,14 @@ type VodController struct {
16 //创建视频上传凭证 CreateUploadVideo 16 //创建视频上传凭证 CreateUploadVideo
17 // @router /createUploadVideo [post] 17 // @router /createUploadVideo [post]
18 func (this *VodController) CreateUploadVideo() { 18 func (this *VodController) CreateUploadVideo() {
19 - var msg *protocol.ResponseMessage 19 + var msg *domain.ResponseMessage
20 defer func() { 20 defer func() {
21 this.Resp(msg) 21 this.Resp(msg)
22 }() 22 }()
23 var request *aliyun.CreateUploadVideoRequest 23 var request *aliyun.CreateUploadVideoRequest
24 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 24 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
25 log.Error(err) 25 log.Error(err)
26 - msg = protocol.BadRequestParam(1) 26 + msg = domain.BadRequestParam(1)
27 return 27 return
28 } 28 }
29 if b, m := this.Valid(request); !b { 29 if b, m := this.Valid(request); !b {
@@ -34,13 +34,13 @@ func (this *VodController) CreateUploadVideo() { @@ -34,13 +34,13 @@ func (this *VodController) CreateUploadVideo() {
34 request.FileName = aliyun.DefaultVideoFileName 34 request.FileName = aliyun.DefaultVideoFileName
35 } 35 }
36 header := controllers.GetRequestHeader(this.Ctx) 36 header := controllers.GetRequestHeader(this.Ctx)
37 - msg = protocol.NewReturnResponse(vod.CreateUploadVideo(header, request)) 37 + msg = domain.NewReturnResponse(vod.CreateUploadVideo(header, request))
38 } 38 }
39 39
40 //创建视频上传凭证(多个) CreateUploadVideos 40 //创建视频上传凭证(多个) CreateUploadVideos
41 // @router /createUploadVideos [post] 41 // @router /createUploadVideos [post]
42 func (this *VodController) CreateUploadVideos() { 42 func (this *VodController) CreateUploadVideos() {
43 - var msg *protocol.ResponseMessage 43 + var msg *domain.ResponseMessage
44 var response *aliyun.CreateUploadVideosResponse = &aliyun.CreateUploadVideosResponse{ 44 var response *aliyun.CreateUploadVideosResponse = &aliyun.CreateUploadVideosResponse{
45 List: make([]*aliyun.CreateUploadVideoResponse, 0), 45 List: make([]*aliyun.CreateUploadVideoResponse, 0),
46 } 46 }
@@ -50,7 +50,7 @@ func (this *VodController) CreateUploadVideos() { @@ -50,7 +50,7 @@ func (this *VodController) CreateUploadVideos() {
50 var request *aliyun.CreateUploadVideosRequest 50 var request *aliyun.CreateUploadVideosRequest
51 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 51 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
52 log.Error(err) 52 log.Error(err)
53 - msg = protocol.BadRequestParam(1) 53 + msg = domain.BadRequestParam(1)
54 return 54 return
55 } 55 }
56 if b, m := this.Valid(request); !b { 56 if b, m := this.Valid(request); !b {
@@ -60,7 +60,7 @@ func (this *VodController) CreateUploadVideos() { @@ -60,7 +60,7 @@ func (this *VodController) CreateUploadVideos() {
60 header := controllers.GetRequestHeader(this.Ctx) 60 header := controllers.GetRequestHeader(this.Ctx)
61 var err error 61 var err error
62 if len(request.Items) == 0 { 62 if len(request.Items) == 0 {
63 - msg = protocol.BadRequestParam(2) 63 + msg = domain.BadRequestParam(2)
64 } 64 }
65 for i := range request.Items { 65 for i := range request.Items {
66 r := request.Items[i] 66 r := request.Items[i]
@@ -71,20 +71,20 @@ func (this *VodController) CreateUploadVideos() { @@ -71,20 +71,20 @@ func (this *VodController) CreateUploadVideos() {
71 response.List = append(response.List, rsp) 71 response.List = append(response.List, rsp)
72 } 72 }
73 } 73 }
74 - msg = protocol.NewReturnResponse(response, err) 74 + msg = domain.NewReturnResponse(response, err)
75 } 75 }
76 76
77 //刷新视频上传凭证 RefreshUploadVideo 77 //刷新视频上传凭证 RefreshUploadVideo
78 // @router /refreshUploadVideo [post] 78 // @router /refreshUploadVideo [post]
79 func (this *VodController) RefreshUploadVideo() { 79 func (this *VodController) RefreshUploadVideo() {
80 - var msg *protocol.ResponseMessage 80 + var msg *domain.ResponseMessage
81 defer func() { 81 defer func() {
82 this.Resp(msg) 82 this.Resp(msg)
83 }() 83 }()
84 var request *aliyun.RefreshUploadVideoRequest 84 var request *aliyun.RefreshUploadVideoRequest
85 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 85 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
86 log.Error(err) 86 log.Error(err)
87 - msg = protocol.BadRequestParam(1) 87 + msg = domain.BadRequestParam(1)
88 return 88 return
89 } 89 }
90 if b, m := this.Valid(request); !b { 90 if b, m := this.Valid(request); !b {
@@ -92,20 +92,20 @@ func (this *VodController) RefreshUploadVideo() { @@ -92,20 +92,20 @@ func (this *VodController) RefreshUploadVideo() {
92 return 92 return
93 } 93 }
94 header := controllers.GetRequestHeader(this.Ctx) 94 header := controllers.GetRequestHeader(this.Ctx)
95 - msg = protocol.NewReturnResponse(vod.RefreshUploadVideo(header, request)) 95 + msg = domain.NewReturnResponse(vod.RefreshUploadVideo(header, request))
96 } 96 }
97 97
98 //创建图片上传凭证 CreateUploadImage 98 //创建图片上传凭证 CreateUploadImage
99 // @router /createUploadImage [post] 99 // @router /createUploadImage [post]
100 func (this *VodController) CreateUploadImage() { 100 func (this *VodController) CreateUploadImage() {
101 - var msg *protocol.ResponseMessage 101 + var msg *domain.ResponseMessage
102 defer func() { 102 defer func() {
103 this.Resp(msg) 103 this.Resp(msg)
104 }() 104 }()
105 var request *aliyun.CreateUploadImageRequest 105 var request *aliyun.CreateUploadImageRequest
106 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 106 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
107 log.Error(err) 107 log.Error(err)
108 - msg = protocol.BadRequestParam(1) 108 + msg = domain.BadRequestParam(1)
109 return 109 return
110 } 110 }
111 if b, m := this.Valid(request); !b { 111 if b, m := this.Valid(request); !b {
@@ -114,13 +114,13 @@ func (this *VodController) CreateUploadImage() { @@ -114,13 +114,13 @@ func (this *VodController) CreateUploadImage() {
114 } 114 }
115 115
116 header := controllers.GetRequestHeader(this.Ctx) 116 header := controllers.GetRequestHeader(this.Ctx)
117 - msg = protocol.NewReturnResponse(vod.CreateUploadImage(header, request)) 117 + msg = domain.NewReturnResponse(vod.CreateUploadImage(header, request))
118 } 118 }
119 119
120 //创建图片上传凭证 CreateUploadImages 120 //创建图片上传凭证 CreateUploadImages
121 // @router /createUploadImages [post] 121 // @router /createUploadImages [post]
122 func (this *VodController) CreateUploadImages() { 122 func (this *VodController) CreateUploadImages() {
123 - var msg *protocol.ResponseMessage 123 + var msg *domain.ResponseMessage
124 defer func() { 124 defer func() {
125 this.Resp(msg) 125 this.Resp(msg)
126 }() 126 }()
@@ -132,7 +132,7 @@ func (this *VodController) CreateUploadImages() { @@ -132,7 +132,7 @@ func (this *VodController) CreateUploadImages() {
132 ) 132 )
133 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 133 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
134 log.Error(err) 134 log.Error(err)
135 - msg = protocol.BadRequestParam(1) 135 + msg = domain.BadRequestParam(1)
136 return 136 return
137 } 137 }
138 if b, m := this.Valid(request); !b { 138 if b, m := this.Valid(request); !b {
@@ -141,7 +141,7 @@ func (this *VodController) CreateUploadImages() { @@ -141,7 +141,7 @@ func (this *VodController) CreateUploadImages() {
141 } 141 }
142 var err error 142 var err error
143 if len(request.Items) == 0 { 143 if len(request.Items) == 0 {
144 - msg = protocol.BadRequestParam(2) 144 + msg = domain.BadRequestParam(2)
145 } 145 }
146 header := controllers.GetRequestHeader(this.Ctx) 146 header := controllers.GetRequestHeader(this.Ctx)
147 for i := range request.Items { 147 for i := range request.Items {
@@ -153,20 +153,20 @@ func (this *VodController) CreateUploadImages() { @@ -153,20 +153,20 @@ func (this *VodController) CreateUploadImages() {
153 response.List = append(response.List, rsp) 153 response.List = append(response.List, rsp)
154 } 154 }
155 } 155 }
156 - msg = protocol.NewReturnResponse(response, err) 156 + msg = domain.NewReturnResponse(response, err)
157 } 157 }
158 158
159 //获取视频播放地址 GetPlayInfo 159 //获取视频播放地址 GetPlayInfo
160 // @router /getPlayInfo [post] 160 // @router /getPlayInfo [post]
161 func (this *VodController) GetPlayInfo() { 161 func (this *VodController) GetPlayInfo() {
162 - var msg *protocol.ResponseMessage 162 + var msg *domain.ResponseMessage
163 defer func() { 163 defer func() {
164 this.Resp(msg) 164 this.Resp(msg)
165 }() 165 }()
166 var request *aliyun.GetPlayInfoRequest 166 var request *aliyun.GetPlayInfoRequest
167 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 167 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
168 log.Error(err) 168 log.Error(err)
169 - msg = protocol.BadRequestParam(1) 169 + msg = domain.BadRequestParam(1)
170 return 170 return
171 } 171 }
172 if b, m := this.Valid(request); !b { 172 if b, m := this.Valid(request); !b {
@@ -174,20 +174,20 @@ func (this *VodController) GetPlayInfo() { @@ -174,20 +174,20 @@ func (this *VodController) GetPlayInfo() {
174 return 174 return
175 } 175 }
176 header := controllers.GetRequestHeader(this.Ctx) 176 header := controllers.GetRequestHeader(this.Ctx)
177 - msg = protocol.NewReturnResponse(vod.GetPlayInfo(header, request)) 177 + msg = domain.NewReturnResponse(vod.GetPlayInfo(header, request))
178 } 178 }
179 179
180 //获取视频播放凭证 GetVideoPlayAuth 180 //获取视频播放凭证 GetVideoPlayAuth
181 // @router /getVideoPlayAuth [post] 181 // @router /getVideoPlayAuth [post]
182 func (this *VodController) GetVideoPlayAuth() { 182 func (this *VodController) GetVideoPlayAuth() {
183 - var msg *protocol.ResponseMessage 183 + var msg *domain.ResponseMessage
184 defer func() { 184 defer func() {
185 this.Resp(msg) 185 this.Resp(msg)
186 }() 186 }()
187 var request *aliyun.GetVideoPlayAuthRequest 187 var request *aliyun.GetVideoPlayAuthRequest
188 if err := json.Unmarshal(this.ByteBody, &request); err != nil { 188 if err := json.Unmarshal(this.ByteBody, &request); err != nil {
189 log.Error(err) 189 log.Error(err)
190 - msg = protocol.BadRequestParam(1) 190 + msg = domain.BadRequestParam(1)
191 return 191 return
192 } 192 }
193 if b, m := this.Valid(request); !b { 193 if b, m := this.Valid(request); !b {
@@ -195,5 +195,5 @@ func (this *VodController) GetVideoPlayAuth() { @@ -195,5 +195,5 @@ func (this *VodController) GetVideoPlayAuth() {
195 return 195 return
196 } 196 }
197 header := controllers.GetRequestHeader(this.Ctx) 197 header := controllers.GetRequestHeader(this.Ctx)
198 - msg = protocol.NewReturnResponse(vod.GetVideoPlayAuth(header, request)) 198 + msg = domain.NewReturnResponse(vod.GetVideoPlayAuth(header, request))
199 } 199 }
@@ -7,7 +7,31 @@ import ( @@ -7,7 +7,31 @@ import (
7 7
8 func init() { 8 func init() {
9 9
10 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 10 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"],
  11 + beego.ControllerComments{
  12 + Method: "PushInfo",
  13 + Router: `/pushInfo`,
  14 + AllowHTTPMethods: []string{"post"},
  15 + MethodParams: param.Make(),
  16 + Params: nil})
  17 +
  18 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"],
  19 + beego.ControllerComments{
  20 + Method: "PushInfoOriginal",
  21 + Router: `/pushInfoOriginal`,
  22 + AllowHTTPMethods: []string{"post"},
  23 + MethodParams: param.Make(),
  24 + Params: nil})
  25 +
  26 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:PushController"],
  27 + beego.ControllerComments{
  28 + Method: "UpdateDevice",
  29 + Router: `/updateDevice`,
  30 + AllowHTTPMethods: []string{"post"},
  31 + MethodParams: param.Make(),
  32 + Params: nil})
  33 +
  34 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
11 beego.ControllerComments{ 35 beego.ControllerComments{
12 Method: "CreateUploadImage", 36 Method: "CreateUploadImage",
13 Router: `/createUploadImage`, 37 Router: `/createUploadImage`,
@@ -15,7 +39,7 @@ func init() { @@ -15,7 +39,7 @@ func init() {
15 MethodParams: param.Make(), 39 MethodParams: param.Make(),
16 Params: nil}) 40 Params: nil})
17 41
18 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 42 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
19 beego.ControllerComments{ 43 beego.ControllerComments{
20 Method: "CreateUploadImages", 44 Method: "CreateUploadImages",
21 Router: `/createUploadImages`, 45 Router: `/createUploadImages`,
@@ -23,7 +47,7 @@ func init() { @@ -23,7 +47,7 @@ func init() {
23 MethodParams: param.Make(), 47 MethodParams: param.Make(),
24 Params: nil}) 48 Params: nil})
25 49
26 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 50 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
27 beego.ControllerComments{ 51 beego.ControllerComments{
28 Method: "CreateUploadVideo", 52 Method: "CreateUploadVideo",
29 Router: `/createUploadVideo`, 53 Router: `/createUploadVideo`,
@@ -31,7 +55,7 @@ func init() { @@ -31,7 +55,7 @@ func init() {
31 MethodParams: param.Make(), 55 MethodParams: param.Make(),
32 Params: nil}) 56 Params: nil})
33 57
34 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 58 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
35 beego.ControllerComments{ 59 beego.ControllerComments{
36 Method: "CreateUploadVideos", 60 Method: "CreateUploadVideos",
37 Router: `/createUploadVideos`, 61 Router: `/createUploadVideos`,
@@ -39,7 +63,7 @@ func init() { @@ -39,7 +63,7 @@ func init() {
39 MethodParams: param.Make(), 63 MethodParams: param.Make(),
40 Params: nil}) 64 Params: nil})
41 65
42 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 66 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
43 beego.ControllerComments{ 67 beego.ControllerComments{
44 Method: "GetPlayInfo", 68 Method: "GetPlayInfo",
45 Router: `/getPlayInfo`, 69 Router: `/getPlayInfo`,
@@ -47,7 +71,7 @@ func init() { @@ -47,7 +71,7 @@ func init() {
47 MethodParams: param.Make(), 71 MethodParams: param.Make(),
48 Params: nil}) 72 Params: nil})
49 73
50 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 74 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
51 beego.ControllerComments{ 75 beego.ControllerComments{
52 Method: "GetVideoPlayAuth", 76 Method: "GetVideoPlayAuth",
53 Router: `/getVideoPlayAuth`, 77 Router: `/getVideoPlayAuth`,
@@ -55,7 +79,7 @@ func init() { @@ -55,7 +79,7 @@ func init() {
55 MethodParams: param.Make(), 79 MethodParams: param.Make(),
56 Params: nil}) 80 Params: nil})
57 81
58 - beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"], 82 + beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/pkg/port/beego/controllers/v1:VodController"],
59 beego.ControllerComments{ 83 beego.ControllerComments{
60 Method: "RefreshUploadVideo", 84 Method: "RefreshUploadVideo",
61 Router: `/refreshUploadVideo`, 85 Router: `/refreshUploadVideo`,
@@ -2,8 +2,9 @@ package routers @@ -2,8 +2,9 @@ package routers
2 2
3 import ( 3 import (
4 "github.com/astaxie/beego" 4 "github.com/astaxie/beego"
5 - "openapi/controllers"  
6 - "openapi/controllers/v1" 5 + "openapi/pkg/constant"
  6 + "openapi/pkg/port/beego/controllers"
  7 + "openapi/pkg/port/beego/controllers/v1"
7 ) 8 )
8 9
9 var nsV1 *beego.Namespace 10 var nsV1 *beego.Namespace
@@ -11,8 +12,8 @@ var nsV1 *beego.Namespace @@ -11,8 +12,8 @@ var nsV1 *beego.Namespace
11 func init() { 12 func init() {
12 nsV1 := beego.NewNamespace("v1", 13 nsV1 := beego.NewNamespace("v1",
13 beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})), 14 beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})),
14 - //beego.NSNamespace("vod", beego.NSBefore(controllers.FilterComm), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})), 15 + beego.NSNamespace("push", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.PushController{})),
15 ) 16 )
16 - beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access")) 17 + beego.SetStaticPath("/log", constant.LogFilePath)
17 beego.AddNamespace(nsV1) 18 beego.AddNamespace(nsV1)
18 } 19 }
  1 +package push
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("消息推送测试", func() {
  10 + ginkgo.Describe("消息推送测试", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "mmmType": 1,
  16 + "deviceToken": "",
  17 + "clientId": "b5fff5f6b0af551da5f381fa47991828",
  18 + "appkey": "5AjJeDOSOZ5ojQpXJFjhg9",
  19 + "secret": "9VnM8MaA6n84Y5VnOIaSvA",
  20 + "appId": "TkpBI4awmg9fBUx3NWKXS6",
  21 + "title": " hello",
  22 + "content": " hello content",
  23 + "ext": map[string]interface{}{"transData": "trans-content"},
  24 + }
  25 + httpExpect.POST("/v1/push/pushInfo").
  26 + WithJSON(body).
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "成功")
  33 + })
  34 + })
  35 + })
  36 +})
  1 +package push
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/onsi/ginkgo"
  6 + "github.com/onsi/gomega"
  7 + "net/http"
  8 + "net/http/httptest"
  9 + _ "openapi/pkg/port/beego"
  10 + "testing"
  11 +)
  12 +
  13 +func TestPush(t *testing.T) {
  14 + gomega.RegisterFailHandler(ginkgo.Fail)
  15 + ginkgo.RunSpecs(t, "Beego Port Config Correlations Test Case Suite")
  16 +}
  17 +
  18 +var handler http.Handler
  19 +var server *httptest.Server
  20 +
  21 +var _ = ginkgo.BeforeSuite(func() {
  22 + handler = beego.BeeApp.Handlers
  23 + beego.BConfig.CopyRequestBody = true
  24 + server = httptest.NewServer(handler)
  25 +})
  26 +
  27 +var _ = ginkgo.AfterSuite(func() {
  28 + server.Close()
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("创建图片上传凭证(单图片)", func() {
  10 + ginkgo.Describe("创建图片上传凭证(单图片)", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "fileName": "test.jpg",
  16 + }
  17 + httpExpect.POST("/v1/vod/createUploadImage").
  18 + WithJSON(body).
  19 + WithHeader("x-mmm-appproject", "opportunity").
  20 + Expect().
  21 + Status(http.StatusOK).
  22 + JSON().
  23 + Object().
  24 + ContainsKey("code").ValueEqual("code", 0).
  25 + ContainsKey("msg").ValueEqual("msg", "成功")
  26 + })
  27 + })
  28 + })
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("创建图片上传凭证(多图片)", func() {
  10 + ginkgo.Describe("创建图片上传凭证(多图片)", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "items": []struct {
  16 + FileName string `json:"fileName"`
  17 + }{{FileName: "test.jpg"}},
  18 + }
  19 + httpExpect.POST("/v1/vod/createUploadImages").
  20 + WithJSON(body).
  21 + WithHeader("x-mmm-appproject", "opportunity").
  22 + Expect().
  23 + Status(http.StatusOK).
  24 + JSON().
  25 + Object().
  26 + ContainsKey("code").ValueEqual("code", 0).
  27 + ContainsKey("msg").ValueEqual("msg", "成功")
  28 + })
  29 + })
  30 + })
  31 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("创建视频上传凭证(单视频)", func() {
  10 + ginkgo.Describe("创建视频上传凭证(单视频)", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "fileName": "test.mp4",
  16 + }
  17 + httpExpect.POST("/v1/vod/createUploadVideos").
  18 + WithJSON(body).
  19 + WithHeader("x-mmm-appproject", "opportunity").
  20 + Expect().
  21 + Status(http.StatusOK).
  22 + JSON().
  23 + Object().
  24 + ContainsKey("code").ValueEqual("code", 0).
  25 + ContainsKey("msg").ValueEqual("msg", "成功")
  26 + })
  27 + })
  28 + })
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("创建视频上传凭证(多视频)", func() {
  10 + ginkgo.Describe("创建视频上传凭证(多视频)", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "items": []struct {
  16 + FileName string `json:"fileName"`
  17 + }{{FileName: "test.mp4"}},
  18 + }
  19 + httpExpect.POST("/v1/vod/createUploadVideos").
  20 + WithJSON(body).
  21 + WithHeader("x-mmm-appproject", "opportunity").
  22 + Expect().
  23 + Status(http.StatusOK).
  24 + JSON().
  25 + Object().
  26 + ContainsKey("code").ValueEqual("code", 0).
  27 + ContainsKey("msg").ValueEqual("msg", "成功")
  28 + })
  29 + })
  30 + })
  31 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("获取播放信息测试", func() {
  10 + ginkgo.Describe("获取播放信息测试", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "videoId": "7be8e50dd65e45d285908bf28c8e94b2",
  16 + }
  17 + httpExpect.POST("/v1/vod/getPlayInfo").
  18 + WithJSON(body).
  19 + WithHeader("x-mmm-appproject", "opportunity").
  20 + Expect().
  21 + Status(http.StatusOK).
  22 + JSON().
  23 + Object().
  24 + ContainsKey("code").ValueEqual("code", 0).
  25 + ContainsKey("msg").ValueEqual("msg", "成功")
  26 + })
  27 + })
  28 + })
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("获取播放凭证测试", func() {
  10 + ginkgo.Describe("获取播放凭证测试", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "videoId": "7be8e50dd65e45d285908bf28c8e94b2",
  16 + }
  17 + httpExpect.POST("/v1/vod/getVideoPlayAuth").
  18 + WithJSON(body).
  19 + WithHeader("x-mmm-appproject", "opportunity").
  20 + Expect().
  21 + Status(http.StatusOK).
  22 + JSON().
  23 + Object().
  24 + ContainsKey("code").ValueEqual("code", 0).
  25 + ContainsKey("msg").ValueEqual("msg", "成功")
  26 + })
  27 + })
  28 + })
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/onsi/ginkgo"
  6 + "net/http"
  7 +)
  8 +
  9 +var _ = ginkgo.Describe("刷新视频上次凭证", func() {
  10 + ginkgo.Describe("刷新视频上次凭证", func() {
  11 + ginkgo.Context("", func() {
  12 + ginkgo.It("", func() {
  13 + httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
  14 + body := map[string]interface{}{
  15 + "videoId": "1023bc472c69499dbe332afa785ee610",
  16 + }
  17 + httpExpect.POST("/v1/vod/refreshUploadVideo").
  18 + WithJSON(body).
  19 + WithHeader("x-mmm-appproject", "opportunity").
  20 + Expect().
  21 + Status(http.StatusOK).
  22 + JSON().
  23 + Object().
  24 + ContainsKey("code").ValueEqual("code", 0).
  25 + ContainsKey("msg").ValueEqual("msg", "成功")
  26 + })
  27 + })
  28 + })
  29 +})
  1 +package vod
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/onsi/ginkgo"
  6 + "github.com/onsi/gomega"
  7 + "net/http"
  8 + "net/http/httptest"
  9 + _ "openapi/pkg/port/beego"
  10 + "testing"
  11 +)
  12 +
  13 +func TestPush(t *testing.T) {
  14 + gomega.RegisterFailHandler(ginkgo.Fail)
  15 + ginkgo.RunSpecs(t, "Beego Port Config Correlations Test Case Suite")
  16 +}
  17 +
  18 +var handler http.Handler
  19 +var server *httptest.Server
  20 +
  21 +var _ = ginkgo.BeforeSuite(func() {
  22 + handler = beego.BeeApp.Handlers
  23 + beego.BConfig.CopyRequestBody = true
  24 + server = httptest.NewServer(handler)
  25 +})
  26 +
  27 +var _ = ginkgo.AfterSuite(func() {
  28 + server.Close()
  29 +})