This commit is contained in:
苏尹岚
2020-12-08 17:23:58 +08:00
parent 6722987cfe
commit 2ab9cc97c2
6 changed files with 161 additions and 5 deletions

View File

@@ -70,19 +70,37 @@ func (a *API) signParam(params map[string]interface{}) (sig string) {
return sig
}
func (a *API) signParam2(params map[string]interface{}) (sig string) {
sb := new(strings.Builder)
sb.WriteString("app_id=")
sb.WriteString(a.appID)
sb.WriteString("&access_token=")
sb.WriteString(a.accessToken)
sb.WriteString("&data=")
sb.WriteString(url.QueryEscape(params["data"].(string)))
sb.WriteString("&salt=")
sb.WriteString(utils.Int64ToStr(utils.MustInterface2Int64(params["salt"])))
sig = sb.String()
fmt.Println("aaaaaaaaaaaaaaaaa", sig)
binSig := md5.Sum([]byte(sig))
sig = fmt.Sprintf("%x", binSig)
return sig
}
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
params := make(map[string]interface{})
params["salt"] = GetSalt()
params["app_id"] = a.appID
if action != tokenAction {
if a.accessToken == "" {
params["access_token"] = a.accessToken
}
// params["access_token"] = a.accessToken
data, _ := json.Marshal(bizParams)
params["data"] = string(data)
signStr := a.signParam2(params)
params[sigKey] = signStr
} else {
signStr := a.signParam(params)
params[sigKey] = signStr
}
signStr := a.signParam(params)
params[sigKey] = signStr
data, _ := json.Marshal(params)
fullURL := utils.GenerateGetURL(url, action, nil)
err = platformapi.AccessPlatformAPIWithRetry(a.client,

View File

@@ -18,6 +18,7 @@ func init() {
sugarLogger = logger.Sugar()
baseapi.Init(sugarLogger)
api = New("6a3e2073-1850-413b-9eb7-6c342ec36e1c", "a8248088-a742-4c33-a0db-03aeae00ca7d")
api.SetToken("n-a4b3a9cf-44c9-4a96-b2ba-d7c9006d4773-w")
}
func TestGetAccessToken(t *testing.T) {

View File

@@ -0,0 +1,89 @@
package fnpsapi
import "git.rosy.net.cn/baseapi/utils"
type CreateOrderParam struct {
PartnerRemark string `json:"partner_remark,omitempty"`
PartnerOrderCode string `json:"partner_order_code,omitempty"`
NotifyURL string `json:"notify_url,omitempty"`
OrderType int `json:"order_type,omitempty"`
ChainStoreCode string `json:"chain_store_code,omitempty"`
TransportInfo struct {
TransportName string `json:"transport_name,omitempty"`
TransportAddress string `json:"transport_address,omitempty"`
TransportLongitude float64 `json:"transport_longitude,omitempty"`
TransportLatitude float64 `json:"transport_latitude,omitempty"`
PositionSource int `json:"position_source,omitempty"`
TransportTel string `json:"transport_tel,omitempty"`
TransportRemark string `json:"transport_remark,omitempty"`
} `json:"transport_info,omitempty"`
OrderAddTime int64 `json:"order_add_time,omitempty"`
OrderTotalAmount float64 `json:"order_total_amount,omitempty"`
OrderActualAmount float64 `json:"order_actual_amount,omitempty"`
OrderWeight float64 `json:"order_weight,omitempty"`
OrderRemark string `json:"order_remark,omitempty"`
IsInvoiced int `json:"is_invoiced,omitempty"`
Invoice string `json:"invoice,omitempty"`
OrderPaymentStatus int `json:"order_payment_status,omitempty"`
OrderPaymentMethod int `json:"order_payment_method,omitempty"`
IsAgentPayment int `json:"is_agent_payment,omitempty"`
RequirePaymentPay float64 `json:"require_payment_pay,omitempty"`
GoodsCount int `json:"goods_count,omitempty"`
RequireReceiveTime int64 `json:"require_receive_time,omitempty"`
SerialNumber string `json:"serial_number,omitempty"`
ReceiverInfo struct {
ReceiverName string `json:"receiver_name,omitempty"`
ReceiverPrimaryPhone string `json:"receiver_primary_phone,omitempty"`
ReceiverSecondPhone string `json:"receiver_second_phone,omitempty"`
ReceiverAddress string `json:"receiver_address,omitempty"`
ReceiverLongitude float64 `json:"receiver_longitude,omitempty"`
ReceiverLatitude float64 `json:"receiver_latitude,omitempty"`
PositionSource int `json:"position_source,omitempty"`
} `json:"receiver_info,omitempty"`
ItemsJSON []*ItemsJSON `json:"items_json,omitempty"`
CookingTime int64 `json:"cooking_time,omitempty"`
PlatformPaidTime int64 `json:"platform_paid_time,omitempty"`
PlatformCreatedTime int64 `json:"platform_created_time,omitempty"`
MerchantCode string `json:"merchant_code,omitempty"`
}
type ItemsJSON struct {
ItemID string `json:"item_id,omitempty"`
ItemName string `json:"item_name,omitempty"`
ItemQuantity int `json:"item_quantity,omitempty"`
ItemPrice float64 `json:"item_price,omitempty"`
ItemActualPrice float64 `json:"item_actual_price,omitempty"`
ItemSize int `json:"item_size,omitempty"`
ItemRemark string `json:"item_remark,omitempty"`
IsNeedPackage int `json:"is_need_package,omitempty"`
IsAgentPurchase int `json:"is_agent_purchase,omitempty"`
AgentPurchasePrice float64 `json:"agent_purchase_price,omitempty"`
}
func (a *API) CreateOrder(createOrderParam *CreateOrderParam) (err error) {
params := utils.Struct2FlatMap(createOrderParam)
_, err = a.AccessAPI("v2/order", TestURL, params, true)
return err
}
//order_cancel_reason_code 订单取消原因代码(1:用户取消,2:商家取消)
// order_cancel_code 订单取消编码1:物流原因:订单长时间未分配骑手,
// 2:物流原因:分配骑手后,骑手长时间未取件 ,
// 3:物流原因:骑手告知不配送,让取消订单,
// 4:商品缺货/无法出货/已售完, 5:商户联系不上门店/门店关门了, 6:商户发错单,
// 7:商户/顾客自身定位错误, 8:商户改其他第三方配送, 9:顾客下错单/临时不想要了,
// 10:顾客自取/不在家/要求另改时间配送0类型已下线
type CancelOrderParam struct {
PartnerOrderCode string `json:"partner_order_code,omitempty"`
OrderCancelReasonCode int `json:"order_cancel_reason_code,omitempty"`
OrderCancelCode int `json:"order_cancel_code,omitempty"`
OrderCancelDescription string `json:"order_cancel_description,omitempty"`
OrderCancelTime int64 `json:"order_cancel_time,omitempty"`
}
func (a *API) CancelOrder(cancelOrderParam *CancelOrderParam) (err error) {
params := utils.Struct2FlatMap(cancelOrderParam)
_, err = a.AccessAPI("v2/order/cancel", TestURL, params, true)
return err
}

View File

@@ -0,0 +1 @@
package fnpsapi

View File

@@ -0,0 +1,24 @@
package fnpsapi
import (
"git.rosy.net.cn/baseapi/utils"
)
type CreateStoreParam struct {
ChainStoreCode string `json:"chain_store_code,omitempty"`
ChainStoreName string `json:"chain_store_name,omitempty"`
ChainStoreType int `json:"chain_store_type,omitempty"`
MerchantCode string `json:"merchant_code,omitempty"`
ContactPhone string `json:"contact_phone,omitempty"`
Address string `json:"address,omitempty"`
PositionSource int `json:"position_source,omitempty"`
Longitude string `json:"longitude,omitempty"`
Latitude string `json:"latitude,omitempty"`
ServiceCode string `json:"service_code,omitempty"`
}
func (a *API) CreateStore(createStoreParam *CreateStoreParam) (err error) {
params := utils.Struct2FlatMap(createStoreParam)
_, err = a.AccessAPI("v2/chain_store", TestURL, params, true)
return err
}

View File

@@ -0,0 +1,23 @@
package fnpsapi
import (
"testing"
)
func TestCreateStore(t *testing.T) {
err := api.CreateStore(&CreateStoreParam{
ChainStoreCode: "123",
ChainStoreName: "测试门店1",
ChainStoreType: 2,
ContactPhone: "18160030913",
Address: "金牛区加州湾",
PositionSource: 3,
Longitude: "104.045409",
Latitude: "30.693387",
ServiceCode: "1",
})
if err != nil {
t.Fatal(err)
}
// t.Log(utils.Format4Output(result, false))
}