From b582b554939d1f0fc4c657858dbd5d8832018a69 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 29 Nov 2019 15:29:25 +0800 Subject: [PATCH] =?UTF-8?q?ProcessQuestionPic=E4=B8=AD=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E8=BF=94=E5=9B=9E=E4=B8=8D=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=9C=B0=E5=9D=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/order.go | 17 +++++++++++++---- platformapi/jdapi/order_test.go | 26 ++++++++++++++++++++++++++ platformapi/jdapi/store_test.go | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index 4a40a73b..2ce8c9b3 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -10,7 +10,8 @@ import ( ) const ( - AfsPicPrefix = "http://img10.360buyimg.com/o2o" + AfsPicPrefix = "http://img10.360buyimg.com/o2o" + AfsPicPrefixHttps = "https://img10.360buyimg.com/o2o" ) const ( @@ -675,11 +676,19 @@ func (a *API) AfsSubmit(OrderID, pin, questionTypeCode, questionDesc, questionPi } func ProcessQuestionPic(questionPic string) (outQuestionPic string) { + const httpsPrefix = "https:" if questionPic != "" { picList := strings.Split(questionPic, ",") - picList2 := make([]string, len(picList)) - for index, pic := range picList { - picList2[index] = AfsPicPrefix + "/" + pic + var picList2 []string + for _, pic := range picList { + baseURL := AfsPicPrefix + pic2 := strings.ReplaceAll(pic, httpsPrefix, "") + if pic2 != pic { + baseURL = AfsPicPrefixHttps + } + if pic2 = utils.TrimBlankChar(pic2); pic2 != "" { + picList2 = append(picList2, utils.GenerateGetURL(baseURL, pic2, nil)) + } } outQuestionPic = strings.Join(picList2, ",") } diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index b95119c4..e8c8ad39 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -259,3 +259,29 @@ func TestCheckSelfPickCode(t *testing.T) { t.Fatal(err.Error()) } } + +func TestProcessQuestionPic(t *testing.T) { + for _, v := range [][]string{ + []string{ + "http://img10.360buyimg.com/o2o/jfs/a.jpg", + ",,,jfs/a.jpg", + }, + []string{ + "http://img10.360buyimg.com/o2o/jfs/a.jpg,https://img10.360buyimg.com/o2o/jfs/b.jpg", + " , ,, jfs/a.jpg,https:jfs/b.jpg", + }, + []string{ + "https://img10.360buyimg.com/o2o/jfs/a.jpg", + ",https:jfs/a.jpg", + }, + []string{ + "", + ",https:", + }, + } { + str := ProcessQuestionPic(v[1]) + if str != v[0] { + t.Fatalf("%s, desired:%s, but its:%s", v[1], v[0], str) + } + } +} diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 0c809544..33531478 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -153,7 +153,7 @@ func TestUpdateStoreFreightConfigNew(t *testing.T) { } func TestPrivilegeSearchUser(t *testing.T) { - result, err := api.PrivilegeSearchUser(1, 1) + result, _, _, err := api.PrivilegeSearchUser(1) if err != nil { t.Fatal(err) }