aa
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
var (
|
||||
api *API
|
||||
apiv3 *APIv3
|
||||
sugarLogger *zap.SugaredLogger
|
||||
)
|
||||
|
||||
@@ -19,6 +20,8 @@ func init() {
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("6a3e2073-1850-413b-9eb7-6c342ec36e1c", "a8248088-a742-4c33-a0db-03aeae00ca7d")
|
||||
api.SetToken("n-606c907a-5117-4c64-bc32-291c3091cabd-w")
|
||||
apiv3 = Newv3("6a3e2073-1850-413b-9eb7-6c342ec36e1c", "a8248088-a742-4c33-a0db-03aeae00ca7d")
|
||||
apiv3.SetTokenv3("n-606c907a-5117-4c64-bc32-291c3091cabd-w")
|
||||
}
|
||||
|
||||
func TestGetAccessToken(t *testing.T) {
|
||||
|
||||
139
platformapi/fnpsapi/fnpsapiv3.go
Normal file
139
platformapi/fnpsapi/fnpsapiv3.go
Normal file
@@ -0,0 +1,139 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
merchantID = "51658"
|
||||
|
||||
URLv3 = "https://open-anubis.ele.me/anubis-webapi/v3/invoke"
|
||||
)
|
||||
|
||||
type APIv3 struct {
|
||||
accessToken string
|
||||
appID string
|
||||
appSecret string
|
||||
|
||||
locker sync.RWMutex
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
func Newv3(appID, appSecret string, config ...*platformapi.APIConfig) *APIv3 {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &APIv3{
|
||||
appID: appID,
|
||||
appSecret: appSecret,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIv3) SetTokenv3(token string) {
|
||||
a.locker.Lock()
|
||||
defer a.locker.Unlock()
|
||||
a.accessToken = token
|
||||
}
|
||||
|
||||
func (a *APIv3) signParamv3(params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
sig = strings.Join(valueList, "&")
|
||||
sig = a.appSecret + sig
|
||||
binSig := sha1.Sum([]byte(sig))
|
||||
sig = fmt.Sprintf("%x", binSig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (a *APIv3) AccessAPIv3(action string, url string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["timestamp"] = time.Now().UnixNano()
|
||||
params["app_id"] = a.appID
|
||||
params["merchant_id"] = merchantID
|
||||
params["version"] = "1.0"
|
||||
params["access_token"] = a.accessToken
|
||||
data, _ := json.Marshal(bizParams)
|
||||
params["business_data"] = string(data)
|
||||
signStr := a.signParamv3(params)
|
||||
params[sigKey] = signStr
|
||||
datas, _ := json.Marshal(params)
|
||||
fullURL := utils.GenerateGetURL(url, action, nil)
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
var request *http.Request
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(datas)))
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, params), nil)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
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["code"]) != 200 {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["code"])))
|
||||
baseapi.SugarLogger.Debugf("fnps AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
type PreCreateOrderParam struct {
|
||||
PartnerOrderCode string `json:"partner_order_code"`
|
||||
OutShopCode string `json:"out_shop_code"`
|
||||
OrderType int `json:"order_type"`
|
||||
PositionSource int `json:"position_source"` // 3:高德地图
|
||||
ReceiverAddress string `json:"receiver_address"`
|
||||
ReceiverLongitude float64 `json:"receiver_longitude"`
|
||||
ReceiverLatitude float64 `json:"receiver_latitude"`
|
||||
GoodsTotalAmountCent float64 `json:"goods_total_amount_cent"`
|
||||
GoodsActualAmountCent float64 `json:"goods_actual_amount_cent"`
|
||||
GoodsWeight float64 `json:"goods_weight"`
|
||||
GoodsCount float64 `json:"goods_count"`
|
||||
GoodsItemList []*ItemsJSON2 `json:"goods_item_list"`
|
||||
}
|
||||
|
||||
type ItemsJSON2 struct {
|
||||
ItemName string `json:"item_name"`
|
||||
ItemQuantity int `json:"item_quantity"`
|
||||
ItemAmountCent float64 `json:"item_amount_cent"`
|
||||
ItemActualAmountCent float64 `json:"item_actual_amount_cent"`
|
||||
}
|
||||
|
||||
func (a *APIv3) PreCreateOrder(preCreateOrderParam *PreCreateOrderParam) (queryOrderResult *QueryOrderResult, err error) {
|
||||
result, err := a.AccessAPIv3("preCreateOrder", URLv3, utils.Struct2FlatMap(preCreateOrderParam), true)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryOrderResult, false)
|
||||
}
|
||||
return queryOrderResult, err
|
||||
}
|
||||
46
platformapi/fnpsapi/fnpsapiv3_test.go
Normal file
46
platformapi/fnpsapi/fnpsapiv3_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPreCreateOrder(t *testing.T) {
|
||||
result, err := apiv3.PreCreateOrder(&PreCreateOrderParam{
|
||||
PartnerOrderCode: "2118717546000352",
|
||||
OutShopCode: "667002",
|
||||
OrderType: 1,
|
||||
PositionSource: 3,
|
||||
ReceiverAddress: "徐州市泉山区大润发(欣欣店)一楼咔啦嘟熊童装店",
|
||||
ReceiverLongitude: 117.195360,
|
||||
ReceiverLatitude: 34.201010,
|
||||
GoodsTotalAmountCent: 66.2,
|
||||
GoodsActualAmountCent: 67.2,
|
||||
GoodsWeight: 2.3,
|
||||
GoodsCount: 6,
|
||||
GoodsItemList: []*ItemsJSON2{
|
||||
&ItemsJSON2{
|
||||
ItemName: "巨峰葡萄约500g/份",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 15.2,
|
||||
ItemActualAmountCent: 15.2,
|
||||
},
|
||||
&ItemsJSON2{
|
||||
ItemName: "[新鲜]苹果150g/个(约150g-250g)",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 4.3,
|
||||
ItemActualAmountCent: 4.3,
|
||||
},
|
||||
&ItemsJSON2{
|
||||
ItemName: "脆桃 鲜,甜,脆约500g/份",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 14.6,
|
||||
ItemActualAmountCent: 14.6,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
@@ -404,3 +404,51 @@ func (a *API) RiderLocation(deliveryId int64, mtPeiSongId string) (lng, lat int,
|
||||
}
|
||||
return lng, lat, err
|
||||
}
|
||||
|
||||
type PreCreateByShopParam struct {
|
||||
DeliveryID int64 `json:"delivery_id"`
|
||||
OrderID string `json:"order_id"`
|
||||
OuterOrderSourceDesc string `json:"outer_order_source_desc"` //101.美团(外卖&闪购) 102.饿了么 103.京东到家
|
||||
OuterOrderSourceNo string `json:"outer_order_source_no"`
|
||||
ShopID string `json:"shop_id"`
|
||||
DeliveryServiceCode int `json:"delivery_service_code"`
|
||||
ReceiverName string `json:"receiver_name"`
|
||||
ReceiverAddress string `json:"receiver_address"`
|
||||
ReceiverPhone string `json:"receiver_phone"`
|
||||
ReceiverLng int `json:"receiver_lng"`
|
||||
ReceiverLat int `json:"receiver_lat"`
|
||||
PayTypeCode int `json:"pay_type_code"`
|
||||
GoodsValue float64 `json:"goods_value"`
|
||||
GoodsWeight float64 `json:"goods_weight"`
|
||||
|
||||
// 以下为可选参数
|
||||
|
||||
CoordinateType int `json:"coordinate_type"`
|
||||
GoodsHeight float64 `json:"goods_height,omitempty"`
|
||||
GoodsWidth float64 `json:"goods_width,omitempty"`
|
||||
GoodsLength float64 `json:"goods_length,omitempty"`
|
||||
GoodsDetail string `json:"goods_detail,omitempty"`
|
||||
GoodsPickupInfo string `json:"goods_pickup_info,omitempty"`
|
||||
GoodsDeliveryInfo string `json:"goods_delivery_info,omitempty"`
|
||||
ExpectedPickupTime int64 `json:"expected_pickup_time,omitempty"` // 期望取货时间,时区为GMT+8,当前距离Epoch(1970年1月1日) 以秒计算的时间,即unix-timestamp。
|
||||
// 期望送达时间,时区为GMT+8,当前距离Epoch(1970年1月1日) 以秒计算的时间,即unix-timestamp
|
||||
// 即时单:以发单时间 + 服务包时效作为期望送达时间(当天送服务包需客户指定期望送达时间)
|
||||
// 预约单:以客户传参数据为准(预约时间必须大于当前下单时间+服务包时效+3分钟)
|
||||
ExpectedDeliveryTime int64 `json:"expected_delivery_time,omitempty"`
|
||||
OrderType int `json:"order_type,omitempty"`
|
||||
PoiSeq string `json:"poi_seq,omitempty"`
|
||||
Note string `json:"note,omitempty"`
|
||||
CashOnDelivery float64 `json:"cash_on_delivery,omitempty"`
|
||||
CashOnPickup float64 `json:"cash_on_pickup,omitempty"`
|
||||
InvoiceTitle string `json:"invoice_title,omitempty"`
|
||||
}
|
||||
|
||||
// 预发单
|
||||
func (a *API) PreCreateByShop(basicParams *PreCreateByShopParam) (lng, lat int, err error) {
|
||||
params := utils.Struct2MapByJson(basicParams)
|
||||
_, err = a.AccessAPI("order/preCreateByShop", params)
|
||||
if err == nil {
|
||||
|
||||
}
|
||||
return lng, lat, err
|
||||
}
|
||||
|
||||
@@ -102,3 +102,27 @@ func TestRiderLocation(t *testing.T) {
|
||||
}
|
||||
t.Logf("lng:%d,lat:%d", lng, lat)
|
||||
}
|
||||
|
||||
func TestPreCreateByShop(t *testing.T) {
|
||||
_, _, err := api.PreCreateByShop(&PreCreateByShopParam{
|
||||
DeliveryID: 123456789,
|
||||
OrderID: "order_123456789",
|
||||
// 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km
|
||||
ShopID: "667235",
|
||||
DeliveryServiceCode: DeliveryServiceCodeRapid,
|
||||
ReceiverName: "xjh",
|
||||
ReceiverAddress: "九里堤",
|
||||
ReceiverPhone: "18112345678",
|
||||
ReceiverLng: 113860710,
|
||||
ReceiverLat: 27628259,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
GoodsValue: 12.34,
|
||||
GoodsWeight: 3.7,
|
||||
PayTypeCode: 0,
|
||||
OuterOrderSourceDesc: "103",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//sugarLogger.Debug(result)
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ func init() {
|
||||
//商超
|
||||
// api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_tE0txRtx7CRuPIOjh2BH4w") //token_nH_IlcWQKAkZBqklwItNRw
|
||||
cookieStr := `
|
||||
uuid=e8034a4d222c4b51b81c.1574126611.1.0.0; _ga=GA1.2.827950563.1574128001; _lxsdk_cuid=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; _lxsdk=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; t_lxid=1719bfe9d5e30-0cf08957b60ff-3d375b01-15f900-1719bfe9d5fc8-tid; lsu=; mtcdn=K; _source=PC; virtual=0; vacctId=0; acctName=null; terminal=bizCenter; logan_custom_report=; igateApp=shangouepc; uuid_update=true; wpush_server_url=wss://wpush.meituan.com; shopCategory=market; device_uuid=!3fb10fb5-cd78-41e2-afd6-4d656136a3fc; e_u_id_3299326472=e5ae16afe444349d24af7d33b66620a1; token=06eu5I1k0_C9L1O__0BB-PWk8mqIpagIL3aKWuTPz8t8*; acctId=57396785; bsid=40I5kUwAJ5uq67jA3bNkn3hT3xpZCkAwhPCq5bGnfIXlBpdbIR9Zz-waWJqJYX6jIe6yK7KCsl4Q_ickenwIcA; wmPoiId=7169838; _lxsdk_s=1787cb12bac-7cd-4f6-eb2%7C%7C378; logan_session_token=1yndau3dxtsh4kg3znsl
|
||||
`
|
||||
acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;
|
||||
`
|
||||
api.SetCookieWithStr(cookieStr)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ var (
|
||||
"reuse/sc/product/retail/r/getStandardProductListWithCond": orderURL,
|
||||
"api/sg/promotion/invite/centerList": actURL,
|
||||
"api/invite/detail": actURL,
|
||||
"v2/logon/setToken": orderURL,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -105,6 +106,10 @@ func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retV
|
||||
return a.AccessUserPage2(subURL, params, true)
|
||||
}
|
||||
|
||||
func (a *API) AccessUserPage3(subURL string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||
return a.AccessUserPage2(subURL, params, false)
|
||||
}
|
||||
|
||||
func (a *API) GetStoreList(lng, lat float64) (shopList []*ListShopItem, err error) {
|
||||
params := map[string]interface{}{
|
||||
"sortId": 1,
|
||||
@@ -438,3 +443,20 @@ func (a *API) GetStandardProductListWithCond(upc string) (getStandardProductList
|
||||
}
|
||||
return getStandardProductListWithCondResult, err
|
||||
}
|
||||
|
||||
func (a *API) SetTokenPage() (err error) {
|
||||
params := map[string]interface{}{
|
||||
"acctId": 57396785,
|
||||
"wmPoiId": -1,
|
||||
"bsid": "y-5VaK3uFxP705tpXsnJPee2sJc9dJ23LmGwYmg2kCO81d9EjD7TJrUeflcJRrqRxg9DFCNGhrJSaWYSCgXvxg",
|
||||
"device_uuid": "!ac34e5d7-5472-47fd-b7c4-029c1f7e7576",
|
||||
"token": "1bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*",
|
||||
"region_version": 0,
|
||||
"region_id": "",
|
||||
}
|
||||
a.SetCookieWithStr(`
|
||||
uuid=350a86177dd64c43b875.1619071312.1.0.0; _lxsdk_cuid=178f88ba3cec8-0db6e384ebfa36-5b1f321a-1fa400-178f88ba3cec8; _lxsdk=178f88ba3cec8-0db6e384ebfa36-5b1f321a-1fa400-178f88ba3cec8; uuid_update=true; _ga=GA1.2.2092976141.1619502287; pushToken=04OVj3PayJdT62H_Irz4BXYfNQHh9N33gDO_WFnGaovs*; device_uuid=!ac34e5d7-5472-47fd-b7c4-029c1f7e7576; mtcdn=K; lsu=; e_u_id_3299326472=e5ae16afe444349d24af7d33b66620a1; wpush_server_url=wss://wpush.meituan.com; shopCategory=food; _lxsdk_s=17b15442f31-e81-89b-533%7C%7C187
|
||||
`)
|
||||
_, err = a.AccessUserPage3("v2/logon/setToken", params)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -49,3 +49,11 @@ func TestGetStandardProductListWithCond(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestSetTokenPage(t *testing.T) {
|
||||
err := api.SetTokenPage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user