- GetQiniuUploadToken
This commit is contained in:
@@ -4,6 +4,13 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
"github.com/qiniu/api.v7/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
qiniuTokenExpires = 300 // 七牛TOKEN有效时间,5分钟
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -39,3 +46,14 @@ func GetPurchaseHandler(vendorID int) partner.IPurchasePlatformHandler {
|
|||||||
func GetServiceInfo() interface{} {
|
func GetServiceInfo() interface{} {
|
||||||
return serviceInfo
|
return serviceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetQiniuUploadToken() (upTokenInfo map[string]interface{}, err error) {
|
||||||
|
putPolicy := storage.PutPolicy{
|
||||||
|
Scope: globals.QiniuBucket,
|
||||||
|
Expires: qiniuTokenExpires,
|
||||||
|
}
|
||||||
|
upTokenInfo = make(map[string]interface{})
|
||||||
|
upTokenInfo["token"] = putPolicy.UploadToken(api.QiniuAPI)
|
||||||
|
upTokenInfo["expires"] = putPolicy.Expires
|
||||||
|
return upTokenInfo, err
|
||||||
|
}
|
||||||
|
|||||||
28
business/jxstore/cms/cms_test.go
Normal file
28
business/jxstore/cms/cms_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package cms
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
||||||
|
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
||||||
|
|
||||||
|
globals.Init()
|
||||||
|
beegodb.Init()
|
||||||
|
api.Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetQiniuUploadToken(t *testing.T) {
|
||||||
|
token, err := GetQiniuUploadToken()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Print(token)
|
||||||
|
}
|
||||||
@@ -21,6 +21,10 @@ enableStoreWrite = false
|
|||||||
aliKey = "LTAI6xJUGaP6WdMQ"
|
aliKey = "LTAI6xJUGaP6WdMQ"
|
||||||
aliSecret = "CLmx5T93Bgi89EGAxWM4RTAXUsiHbM"
|
aliSecret = "CLmx5T93Bgi89EGAxWM4RTAXUsiHbM"
|
||||||
|
|
||||||
|
qiniuAK = "bKWilgyrJlc8aXgLEpCUmRrYcxJ8OYhoKk5mO3jJ"
|
||||||
|
qiniuSK = "3MNdU_lKnu22vrNtUELDcLBv23UOUWYKzc16Pmkj"
|
||||||
|
qiniuBucket = "jingxistandardlib"
|
||||||
|
|
||||||
[dev]
|
[dev]
|
||||||
freshFoodServerURL = "http://portal.beta.jxc4.com"
|
freshFoodServerURL = "http://portal.beta.jxc4.com"
|
||||||
|
|
||||||
|
|||||||
@@ -21,3 +21,16 @@ func (c *CmsController) GetServiceInfo() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 得到七牛上传服务临时token
|
||||||
|
// @Description 得到七牛上传服务临时token,当前设置为5分钟内有效。正常使用场景为每次上传资源前实时获取,而不是保存下来一直使用
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetQiniuUploadToken [get]
|
||||||
|
func (c *CmsController) GetQiniuUploadToken() {
|
||||||
|
c.callGetQiniuUploadToken(func(params *tCmsGetQiniuUploadTokenParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = cms.GetQiniuUploadToken()
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"github.com/qiniu/api.v7/auth/qbox"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -20,6 +21,7 @@ var (
|
|||||||
DadaAPI *dadaapi.API
|
DadaAPI *dadaapi.API
|
||||||
WeixinAPI *weixinapi.API
|
WeixinAPI *weixinapi.API
|
||||||
AutonaviAPI *autonavi.API
|
AutonaviAPI *autonavi.API
|
||||||
|
QiniuAPI *qbox.Mac
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -29,6 +31,7 @@ func Init() {
|
|||||||
DadaAPI = dadaapi.New(beego.AppConfig.String("dadaAppKey"), beego.AppConfig.String("dadaAppSecret"), beego.AppConfig.String("dadaSourceID"), beego.AppConfig.String("dadaCallbackURL"), beego.AppConfig.DefaultBool("dadaIsProd", false))
|
DadaAPI = dadaapi.New(beego.AppConfig.String("dadaAppKey"), beego.AppConfig.String("dadaAppSecret"), beego.AppConfig.String("dadaSourceID"), beego.AppConfig.String("dadaCallbackURL"), beego.AppConfig.DefaultBool("dadaIsProd", false))
|
||||||
WeixinAPI = weixinapi.New(beego.AppConfig.String("weixinAppID"), beego.AppConfig.String("weixinSecret"))
|
WeixinAPI = weixinapi.New(beego.AppConfig.String("weixinAppID"), beego.AppConfig.String("weixinSecret"))
|
||||||
AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey"))
|
AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey"))
|
||||||
|
QiniuAPI = qbox.NewMac(beego.AppConfig.String("qiniuAK"), beego.AppConfig.String("qiniuSK"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initElm() {
|
func initElm() {
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ var (
|
|||||||
|
|
||||||
EnableStore bool
|
EnableStore bool
|
||||||
EnableStoreWrite bool
|
EnableStoreWrite bool
|
||||||
|
|
||||||
|
QiniuBucket string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -65,4 +67,6 @@ func Init() {
|
|||||||
|
|
||||||
EnableStore = beego.AppConfig.DefaultBool("enableStore", false)
|
EnableStore = beego.AppConfig.DefaultBool("enableStore", false)
|
||||||
EnableStoreWrite = beego.AppConfig.DefaultBool("enableStoreWrite", false)
|
EnableStoreWrite = beego.AppConfig.DefaultBool("enableStoreWrite", false)
|
||||||
|
|
||||||
|
QiniuBucket = beego.AppConfig.String("qiniuBucket")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ func init() {
|
|||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetQiniuUploadToken",
|
||||||
|
Router: `/GetQiniuUploadToken`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetServiceInfo",
|
Method: "GetServiceInfo",
|
||||||
|
|||||||
Reference in New Issue
Block a user