- 内嵌APICookie后,删除一些冗余的数据成员

This commit is contained in:
gazebo
2019-09-10 14:22:49 +08:00
parent a1c5ec77ff
commit 938b28e5a8
7 changed files with 21 additions and 36 deletions

View File

@@ -7,7 +7,6 @@ import (
"net/url"
"sort"
"strings"
"sync"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi"
@@ -43,9 +42,6 @@ type API struct {
config *platformapi.APIConfig
speedLimiter *platformapi.Limiter
supplierID int64
locker sync.RWMutex
storeCookies map[string]string
}
func New(source, secret string, config ...*platformapi.APIConfig) *API {
@@ -60,7 +56,6 @@ func New(source, secret string, config ...*platformapi.APIConfig) *API {
client: &http.Client{Timeout: curConfig.ClientTimeout},
config: &curConfig,
speedLimiter: platformapi.New(apiLimitConfigs, nil), //defaultAPILimitConfig),
storeCookies: make(map[string]string),
supplierID: -1,
}
@@ -155,12 +150,12 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon
}
func (a *API) GetSupplierID() (supplierID int64) {
a.locker.RLock()
a.RLock()
supplierID = a.supplierID
a.locker.RUnlock()
a.RUnlock()
if supplierID < 0 {
a.locker.Lock()
defer a.locker.Unlock()
a.Lock()
defer a.Unlock()
a.supplierID = 0
if shopList, err := a.ShopList(SysStatusAll); err == nil {

View File

@@ -16,7 +16,7 @@ func TestShopCategoryCreate(t *testing.T) {
}
func TestShopCategoryGet(t *testing.T) {
result, err := api.ShopCategoryGet("102493")
result, err := api.ShopCategoryGet("300034")
if err != nil {
t.Fatal(err)
} else {
@@ -69,7 +69,7 @@ func TestSkuUploadRTF(t *testing.T) {
}
func TestSkuCreate(t *testing.T) {
result, err := api.SkuCreate(testShopID, 17, map[string]interface{}{
result, err := api.SkuCreate("", testShopID, 17, map[string]interface{}{
"name": "测试商品",
"status": SkuStatusOnline,
"left_num": MaxLeftNum,

View File

@@ -7,7 +7,6 @@ import (
"net/http"
"sort"
"strings"
"sync"
"git.rosy.net.cn/baseapi"
@@ -66,9 +65,6 @@ type API struct {
appSecret string
client *http.Client
config *platformapi.APIConfig
locker sync.RWMutex
storeCookie string
}
var (

View File

@@ -27,7 +27,7 @@ func init() {
// 天天果园
// api = New("84541069-fbe2-424b-b625-9b2ba1d4c9e6", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26")
const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHDYZP7PPVMRGO4VWG2JRBMKFTOGIWZ5L2XHXC3SXQ4OLX7EL4RKUPZQT6GOH63KE3EVK37L5LG7TGSDGXFQP4377YK72UB5YZG6IJH6PY25YLLCJYPMDSHKPGYBUFJ4MMMKGN6MWB37CP7XVDBBZJ3U462ENTEXH744AWCQCIG2AAE2PKYVHC"
const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHCT3RM3CQG7IJIPUQ3THS5UIUYWMKINM7ETUOQB7OBPOPZVCT3ZJY55243TDVXLO25PP4UYSPTTPMNQ7HPMWOJKJ3BJWGVHD243MXH7NZWW264TKN5UOCJBSSSOKD2QQII"
api.SetCookie(accessStorePageCookieName, cookieValue)
api.SetCookie(accessStorePageCookieName2, cookieValue)
}

View File

@@ -8,9 +8,9 @@ import (
)
func TestGetRealMobileNumber4Order(t *testing.T) {
orderId := "910170516000941"
desiredMobile := "13398196274"
mobile, err := api.GetRealMobile4Order(orderId, "")
orderId := "921823424000122"
desiredMobile := "13722455105"
mobile, err := api.GetRealMobile4Order(orderId, "11893205")
if err != nil {
t.Fatal(err)
}
@@ -21,8 +21,8 @@ func TestGetRealMobileNumber4Order(t *testing.T) {
}
func TestGetStoreOrderInfo(t *testing.T) {
orderId := "910170516000941"
orderInfo, err := api.GetStoreOrderInfo(orderId, "")
orderId := "921823424000122"
orderInfo, err := api.GetStoreOrderInfo(orderId, "11893205")
if err != nil {
t.Fatal(err)
}

View File

@@ -9,7 +9,6 @@ import (
"net/url"
"sort"
"strings"
"sync"
"time"
"git.rosy.net.cn/baseapi"
@@ -60,9 +59,6 @@ type API struct {
callbackURL string
client *http.Client
config *platformapi.APIConfig
locker sync.RWMutex
userCookies map[string]string
}
var (
@@ -85,8 +81,6 @@ func New(appID, secret, callbackURL string, config ...*platformapi.APIConfig) *A
callbackURL: callbackURL,
client: &http.Client{Timeout: curConfig.ClientTimeout},
config: &curConfig,
userCookies: make(map[string]string),
}
}

View File

@@ -11,7 +11,7 @@ import (
)
type APICookie struct {
locker sync.RWMutex
sync.RWMutex
storeCookies map[string]string
}
@@ -44,28 +44,28 @@ func (a *APICookie) SetCookieWithStr(cookieStr string) {
}
func (a *APICookie) SetCookie(key, value string) {
a.locker.Lock()
defer a.locker.Unlock()
a.Lock()
defer a.Unlock()
a.createMapIfNeeded()
a.storeCookies[key] = value
}
func (a *APICookie) GetCookie(key string) string {
a.locker.RLock()
defer a.locker.RUnlock()
a.RLock()
defer a.RUnlock()
a.createMapIfNeeded()
return a.storeCookies[key]
}
func (a *APICookie) GetCookieCount() int {
a.locker.RLock()
defer a.locker.RUnlock()
a.RLock()
defer a.RUnlock()
return len(a.storeCookies)
}
func (a *APICookie) FillRequestCookies(r *http.Request) *http.Request {
a.locker.RLock()
defer a.locker.RUnlock()
a.RLock()
defer a.RUnlock()
for k, v := range a.storeCookies {
r.AddCookie(&http.Cookie{
Name: k,