From 73a084621e6d6d6ce19a02c21cc3bfc4690e24d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 10 Apr 2023 10:34:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=96=E9=9F=B3=E4=BA=91?= =?UTF-8?q?=E9=BC=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiktok_shop/tiktok_api/afs_test.go | 2 +- platformapi/tiktok_shop/tiktok_api/sku.go | 132 ++++++++++++------ 2 files changed, 93 insertions(+), 41 deletions(-) diff --git a/platformapi/tiktok_shop/tiktok_api/afs_test.go b/platformapi/tiktok_shop/tiktok_api/afs_test.go index 8e6a999d..7660e0c8 100644 --- a/platformapi/tiktok_shop/tiktok_api/afs_test.go +++ b/platformapi/tiktok_shop/tiktok_api/afs_test.go @@ -18,7 +18,7 @@ import ( // "authority_id": "" //}` -var token = `{"access_token":"d04f3829-3ee5-4886-bdcd-70f928055cbe","expires_in":1681311682,"scope":"SCOPE","shop_id":68023619,"shop_name":"京西到家","refresh_token":"e0b7bc95-067c-4cfb-a59a-1c00344ab851","authority_id":""}` +var token = `{"access_token":"b558d5bd-d55d-4322-8602-85ba449cbc79","expires_in":1681667840,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"3a3c0ad2-bcbd-4f55-b7af-6b406dabc47a","authority_id":""}` //var token = `{"access_token":"e3173e9f-266f-4d87-88e7-e7cd837bc9d9","expires_in":1672882632,"scope":"SCOPE","shop_id":68023619,"shop_name":"京西到家","refresh_token":"5070aae2-493f-46bd-b5d6-6ea0cd64729f","authority_id":""}` diff --git a/platformapi/tiktok_shop/tiktok_api/sku.go b/platformapi/tiktok_shop/tiktok_api/sku.go index 46a314a5..4663b3cc 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku.go +++ b/platformapi/tiktok_shop/tiktok_api/sku.go @@ -1,9 +1,9 @@ package tiktok_api import ( + "encoding/json" "errors" brand_list_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/brand_list/request" - order_batchDecrypt_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/order_batchDecrypt/request" order_batchSensitive_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/order_batchSensitive/request" product_GetRecommendCategory_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_GetRecommendCategory/request" product_addV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_addV2/request" @@ -30,8 +30,9 @@ import ( superm_product_batchRedistributeStoreProduct_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_product_batchRedistributeStoreProduct/request" superm_product_createSubProduct_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_product_createSubProduct/request" superm_product_launchProduct_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_product_launchProduct/request" - "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" + "io/ioutil" + "net/http" "strings" ) @@ -329,52 +330,103 @@ func (a *API) GetSkuBrand(categoryId int64, brandName string) (int64, error) { return BrandNameMap[brandNameLen], nil } -// OrderUserInfoDecrypt 用户信息解密 +type YunDecrypt struct { + Code string `json:"code"` + Data string `json:"data"` + Err string `json:"err"` +} + +// OrderUserInfoDecrypt 用户信息解密(此接口转入云鼎服务器,将不再直接通信) func (a *API) OrderUserInfoDecrypt(orderId, name, tel, address string) (string, string, string, error) { - request := order_batchDecrypt_request.New() - - cipherInfos := make([]order_batchDecrypt_request.CipherInfosItem, 0, 0) - for i := 1; i <= 3; i++ { - cipher := order_batchDecrypt_request.CipherInfosItem{} - cipher.AuthId = orderId - switch i { - case 1: // 姓名 - cipher.CipherText = name - cipherInfos = append(cipherInfos, cipher) - case 2: // 手机号 - cipher.CipherText = tel - cipherInfos = append(cipherInfos, cipher) - case 3: // 地址 - cipher.CipherText = address - cipherInfos = append(cipherInfos, cipher) - } - } - request.Param.CipherInfos = cipherInfos - - result, err := request.Execute(a.accessTokenObj) - globals.SugarLogger.Debugf("OrderUserInfoDecrypt======:%s", utils.Format4Output(result, false)) + url := "http://ddy.jxc4.com/tt/decrypt" + accessToken, err := json.Marshal(a.accessTokenObj.CreateTokenData) if err != nil { return "", "", "", err } - if result.Code != RequestSuccessCode { - return "", "", "", errors.New(result.SubCode) + + param := make(map[string]string, 5) + param["token"] = string(accessToken) + param["encrypt_post_tel"] = tel + param["encrypt_post_receiver"] = address + param["encrypt_post_name"] = name + param["order_id"] = orderId + param["app_key"] = a.appKey + param["app_secret"] = a.appSecret + + data, err := json.Marshal(param) + if err != nil { + return "", "", "", nil + } + payload := strings.NewReader(string(data)) + req, _ := http.NewRequest("POST", url, payload) + req.Header.Add("content-type", "application/json") + res, err := http.DefaultClient.Do(req) + if err != nil { + return "", "", "", err + } + defer res.Body.Close() + body, _ := ioutil.ReadAll(res.Body) + + var result *YunDecrypt + if err := json.Unmarshal(body, &result); err != nil { + return "", "", "", err + } + if result.Code != "200" { + return "", "", "", errors.New(result.Err) } - var ( - userName, userTel, userAddress = "", "", "" - ) - for _, v := range result.Data.DecryptInfos { - if v.CipherText != "" && v.CipherText == name { - userName = v.DecryptText - } - if v.CipherText != "" && v.CipherText == tel { - userTel = v.DecryptText - } - if v.CipherText != "" && v.CipherText == address { - userAddress = v.DecryptText + if len(result.Data) != 0 { + var decryData map[string]string + if err := json.Unmarshal([]byte(result.Data), decryData); err != nil { + return "", "", "", err } + return decryData["name"], decryData["tel"], decryData["address"], nil } - return userName, userTel, userAddress, err + return "", "", "", errors.New("返回值为空") + //request := order_batchDecrypt_request.New() + // + //cipherInfos := make([]order_batchDecrypt_request.CipherInfosItem, 0, 0) + //for i := 1; i <= 3; i++ { + // cipher := order_batchDecrypt_request.CipherInfosItem{} + // cipher.AuthId = orderId + // switch i { + // case 1: // 姓名 + // cipher.CipherText = name + // cipherInfos = append(cipherInfos, cipher) + // case 2: // 手机号 + // cipher.CipherText = tel + // cipherInfos = append(cipherInfos, cipher) + // case 3: // 地址 + // cipher.CipherText = address + // cipherInfos = append(cipherInfos, cipher) + // } + //} + //request.Param.CipherInfos = cipherInfos + // + //result, err := request.Execute(a.accessTokenObj) + //globals.SugarLogger.Debugf("OrderUserInfoDecrypt======:%s", utils.Format4Output(result, false)) + //if err != nil { + // return "", "", "", err + //} + //if result.Code != RequestSuccessCode { + // return "", "", "", errors.New(result.SubCode) + //} + // + //var ( + // userName, userTel, userAddress = "", "", "" + //) + //for _, v := range result.Data.DecryptInfos { + // if v.CipherText != "" && v.CipherText == name { + // userName = v.DecryptText + // } + // if v.CipherText != "" && v.CipherText == tel { + // userTel = v.DecryptText + // } + // if v.CipherText != "" && v.CipherText == address { + // userAddress = v.DecryptText + // } + //} + //return userName, userTel, userAddress, err } // OrderUserInfoSensitive 用户信息脱敏