From 39c1c304ee51fe50e101edcf57599656f0529d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 24 Feb 2021 09:43:43 +0800 Subject: [PATCH] aa --- platformapi/autonavi/autonavi.go | 2 + platformapi/autonavi/autonavi_page.go | 7 +- platformapi/autonavi/autonavi_test.go | 1 + platformapi/jdshopapi/store_page_test.go | 88 ++++++++++++------------ 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index dacdcc6a..7561b87d 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -112,6 +112,8 @@ type Coordinate struct { type ResponseResult map[string]interface{} type API struct { + platformapi.APICookie + client *http.Client config *platformapi.APIConfig key string diff --git a/platformapi/autonavi/autonavi_page.go b/platformapi/autonavi/autonavi_page.go index 5d60727a..b9688dbd 100644 --- a/platformapi/autonavi/autonavi_page.go +++ b/platformapi/autonavi/autonavi_page.go @@ -15,6 +15,8 @@ func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}) func() *http.Request { var request *http.Request request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", bizParams), nil) + request.Header.Set("Referer", "https://lbs.amap.com/") + // a.FillRequestCookies(request) return request }, a.config, @@ -41,7 +43,7 @@ func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}) func (a *API) GetCoordinateFromAddressByPage(address string, cityCode int) (lng, lat float64, err error) { result, err := a.AccessStorePage("https://restapi.amap.com/v3/place/text", map[string]interface{}{ "s": "rsv3", - "key": "8325164e247e15eea68b59e89200988b", + "key": "e07ffdf58c8e8672037bef0d6cae7d4a", "page": 1, "offset": 10, "city": cityCode, @@ -50,8 +52,9 @@ func (a *API) GetCoordinateFromAddressByPage(address string, cityCode int) (lng, "logversion": 2.0, "sdkversion": 1.3, "appname": "https://lbs.amap.com/console/show/picker", - "csid": "170EFB02-7F7C-4F47-A1D5-47E98DC17ABB", + "csid": "7A90908C-BBA6-49FE-895E-DB70600E14F8", "keywords": address, + "children": "", }) if err == nil { if len(result["pois"].([]interface{})) > 0 { diff --git a/platformapi/autonavi/autonavi_test.go b/platformapi/autonavi/autonavi_test.go index 08f1a849..78568150 100644 --- a/platformapi/autonavi/autonavi_test.go +++ b/platformapi/autonavi/autonavi_test.go @@ -20,6 +20,7 @@ func init() { baseapi.Init(sugarLogger) autonaviAPI = New("ef64f638f31e05cb7bde28790f7309fe") + autonaviAPI.SetCookieWithStr(`cna=dyUYGJ5k1VICAbffYm17n9kQ; UM_distinctid=176036a06055e-0ee495abe2301e-5c173a1b-15f900-176036a060673; isg=BOrqQBinfq1rFcyHs0cHGEFiO1CMW261b382TXSjAz3bp4phXO9bxTLWM9O7V-ZN; l=eBLn3bArQD-PVZ6OBO5ZPurza77tgIRb4sPzaNbMiInca6GF9FPIpNCI6EvkWdtjgtC33etzuK-oqdLHR3xJ2xDDB5XXG7RE3xvO.; tfstk=cgmVBA_rmnK25ur6JoZNGm2q2UqAZinnX3yUoV3YnkeyezzcifCTEIYxUAPpqrf..`) } func TestCoordinateConvert(t *testing.T) { diff --git a/platformapi/jdshopapi/store_page_test.go b/platformapi/jdshopapi/store_page_test.go index 161e1f46..80ff8d4c 100644 --- a/platformapi/jdshopapi/store_page_test.go +++ b/platformapi/jdshopapi/store_page_test.go @@ -8,6 +8,8 @@ import ( "fmt" "math" "sort" + "strconv" + "strings" "testing" "git.rosy.net.cn/baseapi/utils" @@ -218,56 +220,52 @@ func TestUpdateExpand(t *testing.T) { } func TestUploadImageNew(t *testing.T) { - fmt.Println(calculate("22+23*2/22")) + fmt.Println(calculate("1 - (2-(1-3))")) } //给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。 //表达式仅包含非负整数,+, - ,*,/ 四种运算符和空格  。 整数除法仅保留整数部分。 func calculate(s string) int { - // result := 0 - // s = strings.Trim(s, " ") - // count := map[string]func(a, b int) int{ - // "+": func(a, b int) int { - // return a + b - // }, - // "-": func(a, b int) int { - // return a - b - // }, - // "*": func(a, b int) int { - // return a * b - // }, - // "/": func(a, b int) int { - // return a / b - // }, - // } - // var str []string - // mem := "" - // for k, v := range s { - // if _, ok := count[string(v)]; !ok { - // mem = mem + string(v) - // } else { - // str = append(str, mem) - // mem = "" - // str = append(str, string(v)) - // } - // if k == len(s)-1 { - // str = append(str, mem) - // } - // } - // count := func(s []string) (r []string) { - - // return r - // } - - // for k, v := range str { - // if v == "*" || v == "/" { - // if k1, err := strconv.Atoi(str[k-1]); err == nil { - // if k2, err := strconv.Atoi(str[k+1]); err == nil { - // result += count[v](k1, k2) - // } - // } - // } - // } + s = "+" + strings.ReplaceAll(s, " ", "") + count := map[string]int{ + "+": 1, + "(": 1, + ")": 1, + "-": 1, + } + var str []string + mem := "" + for k, v := range s { + if _, ok := count[string(v)]; !ok { + mem = mem + string(v) + } else { + if mem != "" { + str = append(str, mem) + } + mem = "" + str = append(str, string(v)) + } + if k == len(s)-1 { + str = append(str, mem) + } + } + changeNum := func(s string) int { + i, _ := strconv.Atoi(s) + return i + } + var ss []int + for k, v := range str { + switch v { + case "+": + ss = append(ss, changeNum(str[k+1])) + case "-": + ss = append(ss, -changeNum(str[k+1])) + } + } + sum := 0 + for _, v := range ss { + sum += v + } return 1 }