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