mtunion回调

This commit is contained in:
苏尹岚
2021-04-20 17:45:30 +08:00
parent 75a753ba4e
commit a8c8946082
4 changed files with 172 additions and 32 deletions

View File

@@ -98,6 +98,36 @@ func (a *API) AccessAPI(action string, isPost bool, bizParams map[string]interfa
return retVal, err
}
func (a *API) AccessAPI2(action string, isPost bool, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
params := make(map[string]interface{})
params["key"] = a.appKey
params = utils.MergeMaps(params, bizParams)
signStr := a.signParam(params)
params[sigKey] = signStr
fullURL := utils.GenerateGetURL(prodURL, action, nil)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
var request *http.Request
if !isPost {
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", params), nil)
} else {
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
}
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
if err == nil {
retVal = jsonResult1
}
return errLevel, err
})
return retVal, err
}
func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
@@ -143,27 +173,27 @@ func (a *API) MiniCode(actID int, userID string) (url string, err error) {
"sid": strings.ToLower(userID),
"actId": actID,
})
if err == nil {
if err == nil {
if utils.MustInterface2Int64(result["status"]) != 0 {
return "",fmt.Errorf(result["des"].(string))
}else {
return result["data"].(string),err
return "", fmt.Errorf(result["des"].(string))
} else {
return result["data"].(string), err
}
}
return url, err
}
func (a *API) GenerateLink(actID,linkType int, userID string) (url string, err error) {
func (a *API) GenerateLink(actID, linkType int, userID string) (url string, err error) {
result, err := a.AccessAPI("generateLink", false, map[string]interface{}{
"sid": strings.ToLower(userID),
"actId": actID,
"sid": strings.ToLower(userID),
"actId": actID,
"linkType": linkType,
})
if err == nil {
if err == nil {
if utils.MustInterface2Int64(result["status"]) != 0 {
return "",fmt.Errorf(result["des"].(string))
}else {
return result["data"].(string),err
return "", fmt.Errorf(result["des"].(string))
} else {
return result["data"].(string), err
}
}
return url, err