- 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) {
|
||||
data := utils.URLValues2Map(request.PostForm)
|
||||
fullURL := strings.TrimRight(request.URL.String(), "/")
|
||||
fullURL := strings.TrimRight(a.callbackURL+request.URL.Path, "/")
|
||||
sign := a.signParams(fullURL+"?", data)
|
||||
if sign != data[signKey] {
|
||||
return nil, SignatureIsNotOk
|
||||
|
||||
@@ -36,22 +36,24 @@ const (
|
||||
)
|
||||
|
||||
type API struct {
|
||||
appID string
|
||||
secret string
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
appID string
|
||||
secret string
|
||||
callbackURL string
|
||||
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
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &API{
|
||||
appID: appID,
|
||||
secret: secret,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
appID: appID,
|
||||
secret: secret,
|
||||
callbackURL: callbackURL,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func init() {
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
|
||||
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f")
|
||||
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "")
|
||||
}
|
||||
|
||||
func TestAccessAPI(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user