diff --git a/platformapi/fnpsapi/fnpsapi.go b/platformapi/fnpsapi/fnpsapi.go index 0e04877d..527c9185 100644 --- a/platformapi/fnpsapi/fnpsapi.go +++ b/platformapi/fnpsapi/fnpsapi.go @@ -51,7 +51,7 @@ func New(appID, appSecret, merchantId, code string, config ...*platformapi.APICo appID: appID, merchantId: merchantId, signature: "", - timestamp: time.Now().UnixNano(), + timestamp: time.Now().Unix() * 1000, accessToken: "", version: "1.0", appSecret: appSecret, @@ -78,8 +78,9 @@ func (a *API) signParam(params map[string]interface{}) (sig string) { } func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) { - a.signature = a.signParam(bizParams) - bizParams["signature"] = a.signature + if a.signature == "" { + a.signature = a.signParam(bizParams) + } // 序列化 data, err := json.Marshal(bizParams) if err != nil { diff --git a/platformapi/fnpsapi_v3/fnClient_test.go b/platformapi/fnpsapi_v3/fnClient_test.go index 23f52d86..1c3cb674 100644 --- a/platformapi/fnpsapi_v3/fnClient_test.go +++ b/platformapi/fnpsapi_v3/fnClient_test.go @@ -23,7 +23,7 @@ func TestClient(t *testing.T) { // 创建门店, func TestCreateStore(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu") + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "51658", "DDSdQhSc02m6l4oPVDELgx") token, _ := api.GetAccessToken() api.accessToken = token.BusinessDataObj.AccessToken err := api.CreateStore(&CreateStoreBaseInfo{ @@ -93,8 +93,9 @@ func TestUpdataStore(t *testing.T) { // 查询单个门店 func TestQueryOneStore(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu") - token, _ := api.GetAccessToken() + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "51658", "DDSdQhSc02m6l4oPVDELgx") + token, err := api.GetAccessToken() + fmt.Println("err1==========", err) api.accessToken = token.BusinessDataObj.AccessToken data, err := api.GetStore("637910") fmt.Println(data) diff --git a/platformapi/fnpsapi_v3/fnpsapi.go b/platformapi/fnpsapi_v3/fnpsapi.go index 463cb3a3..333164bc 100644 --- a/platformapi/fnpsapi_v3/fnpsapi.go +++ b/platformapi/fnpsapi_v3/fnpsapi.go @@ -43,7 +43,7 @@ func New(appID, appSecret, merchantId, code string, config ...*platformapi.APICo appID: appID, merchantId: merchantId, signature: "", - timestamp: time.Now().UnixNano(), + timestamp: time.Now().Unix() * 1000, accessToken: "", version: "1.0", appSecret: appSecret, @@ -77,6 +77,7 @@ func (a *API) GetAccessToken() (tokenInfo *TokenInfo, err error) { parameter["app_id"] = a.appID parameter["merchant_id"] = a.merchantId parameter["timestamp"] = utils.Int64ToStr(a.timestamp) + parameter["signature"] = a.signParam result, err := a.AccessAPI(TokenURL, "", RequestPost, parameter) if err != nil { @@ -95,7 +96,9 @@ func (a *API) GetAccessToken() (tokenInfo *TokenInfo, err error) { } func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) { - a.signature = a.signParam(bizParams) + if a.signature == "" { + a.signature = a.signParam(bizParams) + } bizParams["signature"] = a.signature // 序列化 data, err := json.Marshal(bizParams) diff --git a/platformapi/fnpsapi_v3/order_test.go b/platformapi/fnpsapi_v3/order_test.go index 1d743f60..44891f21 100644 --- a/platformapi/fnpsapi_v3/order_test.go +++ b/platformapi/fnpsapi_v3/order_test.go @@ -8,7 +8,7 @@ import ( // 预下单 func TestPreOrder(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691") + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "51658") token, _ := api.GetAccessToken() api.accessToken = token.BusinessDataObj.AccessToken @@ -39,7 +39,7 @@ func TestPreOrder(t *testing.T) { // 正式下单 func TestCreateOrder(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691") + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "51658") token, _ := api.GetAccessToken() api.accessToken = token.BusinessDataObj.AccessToken @@ -70,7 +70,7 @@ func TestCreateOrder(t *testing.T) { // 添加小费 func TestAddTip(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691") + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "51658") token, _ := api.GetAccessToken() api.accessToken = token.BusinessDataObj.AccessToken @@ -85,8 +85,9 @@ func TestAddTip(t *testing.T) { // 获取可用取消订单原因 func TestGetCancelReasonList(t *testing.T) { - api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691") - token, _ := api.GetAccessToken() + api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "DDSdQhSc02m6l4oPVDELgx") + token, err := api.GetAccessToken() + fmt.Println(err) api.accessToken = token.BusinessDataObj.AccessToken data, err := api.GetCancelReasonList(&GetOrderDetailReq{