修签名
This commit is contained in:
@@ -51,7 +51,6 @@ func New(appID, appSecret, merchantId, code string, config ...*platformapi.APICo
|
||||
appID: appID,
|
||||
merchantId: merchantId,
|
||||
signature: "",
|
||||
timestamp: time.Now().Unix() * 1000,
|
||||
accessToken: "",
|
||||
version: "1.0",
|
||||
appSecret: appSecret,
|
||||
@@ -78,9 +77,8 @@ 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) {
|
||||
if a.signature == "" {
|
||||
a.signature = a.signParam(bizParams)
|
||||
}
|
||||
bizParams["timestamp"] = utils.Int64ToStr(time.Now().Unix() * 1000)
|
||||
bizParams["signature"] = a.signParam(bizParams)
|
||||
// 序列化
|
||||
data, err := json.Marshal(bizParams)
|
||||
if err != nil {
|
||||
@@ -130,7 +128,6 @@ func (a *API) GetAccessToken() (tokenInfo *TokenInfo, err error) {
|
||||
parameter["code"] = a.code
|
||||
parameter["app_id"] = a.appID
|
||||
parameter["merchant_id"] = a.merchantId
|
||||
parameter["timestamp"] = utils.Int64ToStr(a.timestamp)
|
||||
|
||||
result, err := a.AccessAPI(TokenURL, "", RequestPost, parameter)
|
||||
if err != nil {
|
||||
|
||||
@@ -14,7 +14,7 @@ func Init() {
|
||||
}
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu")
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "iCN2gIftF1Ia9nG7720nyn")
|
||||
token, err := api.GetAccessToken()
|
||||
api.accessToken = token.BusinessDataObj.AccessToken
|
||||
fmt.Println("token===", token.BusinessDataObj.AccessToken)
|
||||
@@ -23,7 +23,7 @@ func TestClient(t *testing.T) {
|
||||
|
||||
// 创建门店,
|
||||
func TestCreateStore(t *testing.T) {
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "51658", "DDSdQhSc02m6l4oPVDELgx")
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu")
|
||||
token, _ := api.GetAccessToken()
|
||||
api.accessToken = token.BusinessDataObj.AccessToken
|
||||
err := api.CreateStore(&CreateStoreBaseInfo{
|
||||
@@ -93,9 +93,8 @@ func TestUpdataStore(t *testing.T) {
|
||||
|
||||
// 查询单个门店
|
||||
func TestQueryOneStore(t *testing.T) {
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "51658", "DDSdQhSc02m6l4oPVDELgx")
|
||||
token, err := api.GetAccessToken()
|
||||
fmt.Println("err1==========", err)
|
||||
api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "iCN2gIftF1Ia9nG7720nyn")
|
||||
token, _ := api.GetAccessToken()
|
||||
api.accessToken = token.BusinessDataObj.AccessToken
|
||||
data, err := api.GetStore("637910")
|
||||
fmt.Println(data)
|
||||
|
||||
@@ -43,7 +43,6 @@ func New(appID, appSecret, merchantId, code string, config ...*platformapi.APICo
|
||||
appID: appID,
|
||||
merchantId: merchantId,
|
||||
signature: "",
|
||||
timestamp: time.Now().Unix() * 1000,
|
||||
accessToken: "",
|
||||
version: "1.0",
|
||||
appSecret: appSecret,
|
||||
@@ -76,8 +75,6 @@ func (a *API) GetAccessToken() (tokenInfo *TokenInfo, err error) {
|
||||
parameter["code"] = a.code
|
||||
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 {
|
||||
@@ -96,10 +93,8 @@ 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) {
|
||||
if a.signature == "" {
|
||||
a.signature = a.signParam(bizParams)
|
||||
}
|
||||
bizParams["signature"] = a.signature
|
||||
bizParams["timestamp"] = utils.Int64ToStr(time.Now().Unix() * 1000)
|
||||
bizParams["signature"] = a.signParam(bizParams)
|
||||
// 序列化
|
||||
data, err := json.Marshal(bizParams)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user