forked from baidu/smartapp-openapi-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteMaterial.go
63 lines (55 loc) · 1.78 KB
/
deleteMaterial.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package openapi
import (
"fmt"
)
// DeleteMaterialRequest 请求结构体
type DeleteMaterialRequest struct {
AccessToken string // 接口调用凭证
AppID int64 // app_id
ID int64 // 物料 id ,添加物料时返回 id
Path string // 智能小程序内页链接,取值为添加物料时返回的 path
}
// 响应结构体
type DeleteMaterialResponse struct {
Data bool `json:"data"` // true:代表修改成功,false:代码修改失败
Errno int64 `json:"errno"` // 错误码
ErrMsg string `json:"msg"` // 错误信息
ErrorCode int64 `json:"error_code"` // openapi 错误码
ErrorMsg string `json:"error_msg"` // openapi 错误信息
}
// DeleteMaterial
func DeleteMaterial(params *DeleteMaterialRequest) (bool, error) {
var (
err error
defaultRet bool
)
respData := &DeleteMaterialResponse{}
client := NewHTTPClient().
SetContentType(ContentTypeForm).
SetConverterType(ConverterTypeJSON).
SetMethod("POST").
SetScheme(SCHEME).
SetHost(OPENAPIHOST).
SetPath("/rest/2.0/smartapp/articlemount/material/delete")
client.AddGetParam("access_token", params.AccessToken)
client.AddGetParam("sp_sdk_ver", SDKVERSION)
client.AddGetParam("sp_sdk_lang", SDKLANG)
client.AddPostParam("app_id", fmt.Sprintf("%v", params.AppID))
client.AddPostParam("id", fmt.Sprintf("%v", params.ID))
client.AddPostParam("path", params.Path)
err = client.Do()
if err != nil {
return defaultRet, err
}
err = client.Convert(respData)
if err != nil {
return defaultRet, err
}
if respData.ErrorCode != 0 {
return defaultRet, &OpenAPIError{respData.ErrorCode, respData.ErrorMsg, respData}
}
if respData.Errno != 0 {
return defaultRet, &APIError{respData.Errno, respData.ErrMsg, respData}
}
return respData.Data, nil
}