mtmember
This commit is contained in:
@@ -3,6 +3,7 @@ package jdshopapi
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -96,16 +97,6 @@ func TestFindStoreInfoByExtStoreId(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWIREHL(t *testing.T) {
|
func TestWIREHL(t *testing.T) {
|
||||||
list := []int{1, 2, 3, 4, 5}
|
str := "https://51106.cn/c/22f06354336ca9"
|
||||||
index := 0
|
fmt.Println(str[strings.LastIndex(str, "/")+1 : len(str)])
|
||||||
for k, v := range list {
|
|
||||||
if v == 3 {
|
|
||||||
index = k
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wsList := list
|
|
||||||
list = list[0:0]
|
|
||||||
list = append(list, wsList[0:index]...)
|
|
||||||
list = append(list, wsList[index+1:len(wsList)]...)
|
|
||||||
fmt.Println(list)
|
|
||||||
}
|
}
|
||||||
|
|||||||
65
platformapi/mtmemberapi/mtmemberapi.go
Normal file
65
platformapi/mtmemberapi/mtmemberapi.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package mtmemberapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
prodURL = "https://wechat.chengquan.cn"
|
||||||
|
)
|
||||||
|
|
||||||
|
type API struct {
|
||||||
|
client *http.Client
|
||||||
|
config *platformapi.APIConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(config ...*platformapi.APIConfig) *API {
|
||||||
|
curConfig := platformapi.DefAPIConfig
|
||||||
|
if len(config) > 0 {
|
||||||
|
curConfig = *config[0]
|
||||||
|
}
|
||||||
|
return &API{
|
||||||
|
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||||
|
config: &curConfig,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
|
fullURL := utils.GenerateGetURL(url, action, nil)
|
||||||
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
|
func() *http.Request {
|
||||||
|
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(bizParams).Encode()))
|
||||||
|
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
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 {
|
||||||
|
if utils.MustInterface2Int64(jsonResult1["errorCode"]) != http.StatusOK {
|
||||||
|
errLevel = platformapi.ErrLevelGeneralFail
|
||||||
|
err = utils.NewErrorCode(utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["errorMsg"])), utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["errorCode"])))
|
||||||
|
baseapi.SugarLogger.Debugf("mtmember AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||||
|
}
|
||||||
|
retVal = jsonResult1
|
||||||
|
}
|
||||||
|
return errLevel, err
|
||||||
|
})
|
||||||
|
return retVal, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) RechargeExchange(account int, shortLink string) (err error) {
|
||||||
|
_, err = a.AccessAPI("uniteExchange/rechargeExchange", prodURL, map[string]interface{}{
|
||||||
|
"account": account,
|
||||||
|
"shortLink": shortLink,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
28
platformapi/mtmemberapi/mtmemberapi_test.go
Normal file
28
platformapi/mtmemberapi/mtmemberapi_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package mtmemberapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
api *API
|
||||||
|
sugarLogger *zap.SugaredLogger
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
logger, _ := zap.NewDevelopment()
|
||||||
|
sugarLogger = logger.Sugar()
|
||||||
|
baseapi.Init(sugarLogger)
|
||||||
|
api = New() //总店
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRechargeExchange(t *testing.T) {
|
||||||
|
err := api.RechargeExchange(15, "a")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user