- add callbackURL for mtwm api
This commit is contained in:
@@ -51,7 +51,7 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
|||||||
|
|
||||||
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
data := utils.URLValues2Map(request.PostForm)
|
data := utils.URLValues2Map(request.PostForm)
|
||||||
fullURL := strings.TrimRight(request.URL.String(), "/")
|
fullURL := strings.TrimRight(a.callbackURL+request.URL.Path, "/")
|
||||||
sign := a.signParams(fullURL+"?", data)
|
sign := a.signParams(fullURL+"?", data)
|
||||||
if sign != data[signKey] {
|
if sign != data[signKey] {
|
||||||
return nil, SignatureIsNotOk
|
return nil, SignatureIsNotOk
|
||||||
|
|||||||
@@ -36,22 +36,24 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
appID string
|
appID string
|
||||||
secret string
|
secret string
|
||||||
client *http.Client
|
callbackURL string
|
||||||
config *platformapi.APIConfig
|
client *http.Client
|
||||||
|
config *platformapi.APIConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(appID, secret string, config ...*platformapi.APIConfig) *API {
|
func New(appID, secret, callbackURL string, config ...*platformapi.APIConfig) *API {
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
}
|
}
|
||||||
return &API{
|
return &API{
|
||||||
appID: appID,
|
appID: appID,
|
||||||
secret: secret,
|
secret: secret,
|
||||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
callbackURL: callbackURL,
|
||||||
config: &curConfig,
|
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||||
|
config: &curConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func init() {
|
|||||||
sugarLogger = logger.Sugar()
|
sugarLogger = logger.Sugar()
|
||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f")
|
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccessAPI(t *testing.T) {
|
func TestAccessAPI(t *testing.T) {
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ func Params2Map(key1, value1 interface{}, kv ...interface{}) (retVal map[string]
|
|||||||
func URLValues2Map(values url.Values) (retVal map[string]interface{}) {
|
func URLValues2Map(values url.Values) (retVal map[string]interface{}) {
|
||||||
retVal = make(map[string]interface{})
|
retVal = make(map[string]interface{})
|
||||||
for k := range values {
|
for k := range values {
|
||||||
retVal[k] = values.Get(k)
|
retVal[k], _ = url.QueryUnescape(values.Get(k))
|
||||||
}
|
}
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user