- ddapi.Sign
This commit is contained in:
@@ -181,6 +181,7 @@ const (
|
||||
OrderStatusFinished = 110 // 订单已完成
|
||||
OrderStatusCanceled = 115 // 订单已取消
|
||||
OrderStatusFailed = 120 // 订单已失败
|
||||
OrderStatusRefund = 125 // 订单全额退款
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
55
controllers/dingding_api.go
Normal file
55
controllers/dingding_api.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type DDAPIController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
type DDAPI struct {
|
||||
Ticket string
|
||||
ExpiresIn time.Time
|
||||
}
|
||||
|
||||
var (
|
||||
ddapi *DDAPI
|
||||
)
|
||||
|
||||
func init() {
|
||||
ddapi = &DDAPI{}
|
||||
}
|
||||
|
||||
// @Title 得到门店用户信息
|
||||
// @Description 得到门店用户信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param url query string true "当前网页的URL,不包含#及其后面部分"
|
||||
// @Param nonceStr query string true "随机串,自己定义"
|
||||
// @Param timeStamp query string true "时间戳"
|
||||
// @Param agentId query string false "应用的标识"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Sign [get]
|
||||
func (c *DDAPIController) Sign() {
|
||||
c.callSign(func(params *tDdapiSignParams) (retVal interface{}, errCode string, err error) {
|
||||
if ddapi.Ticket == "" || time.Now().Sub(ddapi.ExpiresIn) >= -5*time.Minute {
|
||||
expiresIn, ticket, err2 := api.DingDingAPI.GetJSAPITicket("")
|
||||
if err = err2; err == nil {
|
||||
ddapi.Ticket = ticket
|
||||
ddapi.ExpiresIn = time.Now().Add(time.Duration(expiresIn) * time.Second)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
retVal = fmt.Sprintf("%x", sha1.Sum([]byte("jsapi_ticket="+ddapi.Ticket+
|
||||
"&noncestr="+params.NonceStr+"×tamp="+params.TimeStamp+"&url="+params.Url)))
|
||||
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -91,6 +91,11 @@ func init() {
|
||||
&controllers.User2Controller{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/ddapi",
|
||||
beego.NSInclude(
|
||||
&controllers.DDAPIController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user