Commit 46eb31dc authored by honghuiliu's avatar honghuiliu 💬

日常提交

parent b335d09e
package web
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/gin-gonic/gin"
)
var ossService = service.ServiceGroupApp.WebServiceGroup.OssService
func GetOssConfig(c *gin.Context) {
response.OkWithData(ossService.GetPolicyToken(), c)
}
aliyun-oss:
endpoint: yourEndpoint
access-key-id: yourAccessKeyId
access-key-secret: yourAccessKeySecret
bucket-name: yourBucketName
bucket-url: yourBucketUrl
base-path: yourBasePath
autocode:
transfer-restart: true
root: /Users/honghuiliu/go/project/qsh-wc
server: /server
server-api: /api/v1/%s
server-plug: /plugin/%s
server-initialize: /initialize
server-model: /model/%s
server-request: /model/%s/request/
server-router: /router/%s
server-service: /service/%s
web: /web/src
web-api: /api
web-form: /view
web-table: /view
aws-s3:
bucket: xxxxx-10005608
region: ap-shanghai
endpoint: ""
s3-force-path-style: false
disable-ssl: false
secret-id: xxxxxxxx
secret-key: xxxxxxxx
base-url: https://gin.vue.admin
path-prefix: github.com/flipped-aurora/gin-vue-admin/server
captcha:
key-long: 6
img-width: 240
img-height: 80
cors:
mode: whitelist
whitelist:
- allow-origin: example1.com
allow-methods: GET, POST
allow-headers: content-type
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,
Content-Type
allow-credentials: true
- allow-origin: example2.com
allow-methods: GET, POST
allow-headers: content-type
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,
Content-Type
allow-credentials: true
db-list:
- disable: false
type: ""
alias-name: ""
path: ""
port: ""
config: ""
db-name: ""
username: ""
password: ""
max-idle-conns: 10
max-open-conns: 100
log-mode: ""
log-zap: false
email:
to: xxx@qq.com
port: 465
from: xxx@163.com
host: smtp.163.com
is-ssl: true
secret: xxx
nickname: test
excel:
dir: ./resource/excel/
hua-wei-obs:
path: you-path
bucket: you-bucket
endpoint: you-endpoint
access-key: you-access-key
secret-key: you-secret-key
jwt:
signing-key: 1471b45a-c33d-47d7-af4d-1d301feec572
expires-time: 604800
buffer-time: 86400
issuer: qmPlus
local:
path: uploads/file
store-path: uploads/file
mysql:
path: 116.62.162.87
port: "3306"
config: charset=utf8mb4&parseTime=True&loc=Local
db-name: qsh_wc
username: root
password: uekkkHDSKL63513
max-idle-conns: 10
max-open-conns: 100
log-mode: error
log-zap: false
pgsql:
path: ""
port: ""
config: ""
db-name: ""
username: ""
password: ""
max-idle-conns: 10
max-open-conns: 100
log-mode: ""
log-zap: false
qiniu:
zone: ZoneHuaDong
bucket: ""
img-path: ""
use-https: false
access-key: ""
secret-key: ""
use-cdn-domains: false
redis:
db: 0
addr: "r-bp1cm5ncyvq2hnul81pd.redis.rds.aliyuncs.com:16379"
password: "rRk2k3nf9JJi283lk119Jvwz"
system:
env: public
addr: 9801
db-type: mysql
oss-type: local
use-multipoint: false
use-redis: false
iplimit-count: 15000
iplimit-time: 3600
tencent-cos:
bucket: xxxxx-10005608
region: ap-shanghai
secret-id: xxxxxxxx
secret-key: xxxxxxxx
base-url: https://gin.vue.admin
path-prefix: github.com/flipped-aurora/gin-vue-admin/server
timer:
start: true
spec: '@daily'
with_seconds: false
detail:
- tableName: sys_operation_records
compareField: created_at
interval: 2160h
- tableName: jwt_blacklists
compareField: created_at
interval: 168h
zap:
level: info
prefix: '[github.com/flipped-aurora/gin-vue-admin/server]'
format: console
director: log
encode-level: LowercaseColorLevelEncoder
stacktrace-key: stacktrace
max-age: 30
show-line: true
log-in-console: true
oss:
AccessId: LTAI5t6Wngx37X2Auxr4sUCF
AccessKey: kyz2L5eQukcxLTYixJ7n8F4Y2og6JU
OssHost: "wensi-zhanlang.oss-cn-hangzhou.aliyuncs.com"
BucketName: "wensi-zhanlang"
OssInternalHost: "https://wensi-zhanlang.oss-cn-hangzhou-internal.aliyuncs.com"
EndPoint: "oss-cn-hangzhou.aliyuncs.com"
prefix: "qsh_wc/"
\ No newline at end of file
...@@ -123,7 +123,7 @@ redis: ...@@ -123,7 +123,7 @@ redis:
password: "rRk2k3nf9JJi283lk119Jvwz" password: "rRk2k3nf9JJi283lk119Jvwz"
system: system:
env: public env: public
addr: 9801 addr: 8888
db-type: mysql db-type: mysql
oss-type: local oss-type: local
use-multipoint: false use-multipoint: false
...@@ -158,3 +158,12 @@ zap: ...@@ -158,3 +158,12 @@ zap:
max-age: 30 max-age: 30
show-line: true show-line: true
log-in-console: true log-in-console: true
oss:
AccessId: LTAI5t6Wngx37X2Auxr4sUCF
AccessKey: kyz2L5eQukcxLTYixJ7n8F4Y2og6JU
OssHost: "wensi-zhanlang.oss-cn-hangzhou.aliyuncs.com"
BucketName: "wensi-zhanlang"
OssInternalHost: "https://wensi-zhanlang.oss-cn-hangzhou-internal.aliyuncs.com"
EndPoint: "oss-cn-hangzhou.aliyuncs.com"
prefix: "qsh_wc/"
\ No newline at end of file
...@@ -23,4 +23,8 @@ func InitWebRouter(router *gin.Engine) { ...@@ -23,4 +23,8 @@ func InitWebRouter(router *gin.Engine) {
patrol.POST("getPatrolList", web.GetPatrolList) patrol.POST("getPatrolList", web.GetPatrolList)
patrol.POST("getPatrolDetail", web.GetPatrolDetail) patrol.POST("getPatrolDetail", web.GetPatrolDetail)
} }
oss := webRouter.Group("oss")
{
oss.POST("getOssConfig", web.GetOssConfig)
}
} }
...@@ -4,6 +4,7 @@ type ServiceGroup struct { ...@@ -4,6 +4,7 @@ type ServiceGroup struct {
LoginService LoginService
ToiletService ToiletService
PatrolService PatrolService
OssService
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT. // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT. // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
......
package web
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"encoding/json"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"hash"
"io"
"time"
)
type OssService struct {
}
type CallbackParam struct {
CallbackUrl string `json:"callbackUrl"`
CallbackBody string `json:"callbackBody"`
CallbackBodyType string `json:"callbackBodyType"`
}
type ConfigStruct struct {
Expiration string `json:"expiration"`
Conditions [][]string `json:"conditions"`
}
const (
base64Table = "123QRSTUabcdVWXYZHijKLAWDCABDstEFGuvwxyzGHIJklmnopqr234560178912"
)
var coder = base64.NewEncoding(base64Table)
func base64Encode(src []byte) []byte {
return []byte(coder.EncodeToString(src))
}
func get_gmt_iso8601(expire_end int64) string {
var tokenExpire = time.Unix(expire_end, 0).UTC().Format("2006-01-02T15:04:05Z")
return tokenExpire
}
type PolicyToken struct {
AccessKeyId string `json:"accessid"` //keyId
Host string `json:"host"` //地址
Expire int64 `json:"expire"` //过期时间
Signature string `json:"signature"` //签名
Policy string `json:"policy"` //
Directory string `json:"dir"` //目录
Callback string `json:"callback"` //回调
}
func (s *OssService) GetPolicyToken() PolicyToken {
// AccessKeyId。
accessKeyId := global.GVA_VP.GetString("oss.AccessId")
// AccessKeySecret。
accessKeySecret := global.GVA_VP.GetString("oss.AccessKey")
// host的格式为 bucketname.endpoint
ossHost := global.GVA_VP.GetString("oss.OssHost")
prefix := global.GVA_VP.GetString("oss.prefix")
host := "//" + ossHost
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
var callbackUrl = "http://88.88.88.88:8888"
// 用户上传文件时指定的前缀。
var uploadDir = prefix + time.Now().Format("2006-01-02")
var expireTime = time.Now().Unix() + 7200
now := time.Now().Unix()
expireEnd := now + expireTime
var tokenExpire = get_gmt_iso8601(expireEnd)
//create post policy json
var config ConfigStruct
config.Expiration = tokenExpire
var condition []string
condition = append(condition, "starts-with")
condition = append(condition, "$key")
condition = append(condition, uploadDir)
config.Conditions = append(config.Conditions, condition)
//calucate signature
result, err := json.Marshal(config)
debyte := base64.StdEncoding.EncodeToString(result)
h := hmac.New(func() hash.Hash { return sha1.New() }, []byte(accessKeySecret))
io.WriteString(h, debyte)
signedStr := base64.StdEncoding.EncodeToString(h.Sum(nil))
var callbackParam CallbackParam
callbackParam.CallbackUrl = callbackUrl
callbackParam.CallbackBody = "filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}"
callbackParam.CallbackBodyType = "application/x-www-form-urlencoded"
callbackStr, err := json.Marshal(callbackParam)
if err != nil {
}
callbackBase64 := base64.StdEncoding.EncodeToString(callbackStr)
var policyToken PolicyToken
policyToken.AccessKeyId = accessKeyId
policyToken.Host = host
policyToken.Expire = expireEnd
policyToken.Signature = string(signedStr)
policyToken.Directory = uploadDir
policyToken.Policy = string(debyte)
policyToken.Callback = string(callbackBase64)
return policyToken
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment