主题
上传附件
上传附件,返回附件id
接口说明
请求URL:http[s]://{网关地址}/mp/restful/v2/attachment/add
请求方式: POST
请求内容类型: application/json
响应内容类型: application/json
请求说明
请求体
| 字段名 | 参数名 | 必填 | 类型 | 描述 |
|---|---|---|---|---|
| 学校编码 | schoolCode | M | string | 学校编码 |
| 签名 | sign | M | string | md5(accessToken+schoolCode)) |
| 文件名字 | name | M | string | 文件名字带后缀 |
| 附件类型 | type | M | int | 文件类型0图片(2M) 1其他附件 |
| 附件大小 | size | M | int | 附件大小 |
| 文件内容 | bytes | M | byte[] | 附件字节数组 |
请求示例
json
{"schoolCode":"code",
"sign":"6927a0fbc730e07a4b4af66c9db308ef",
"name":"pic.png",
"type":1,
"size":10000,
"bytes":[-119,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,50,0,0,0,50,8,6,0,0,0,30,63,
-120,-79,0,0,0,1,115,82,71,66,0,-82,-50,28,-23,0,0,5,67,73,68,65,84,104,5,-35,90,75,108,
27,69,24,-98,89,-101,-60,46,10,68,-76,46,20,-39,92,8,18,23,14,72,73,33,60,68,35,-15,74,
43,-95,-10,-64,-127,3,-36,-24,1,-127,-124,-124,56,0,13,-78,-44,22,14,-120,-121,4,2,9,
110,-27,-64,-127,67,43,36,8,47,-55,32,30,41,77,111,92,-112,40,23,108,81,-38,40,40,16,
41,47,-30,29,-2,111,-56,-65,-103,-75,119,-67,51,-101,-75,-99,116,36,123,118,103,-2,-1,
-33,-17,-37,121,-1,-1,74,-111,113,106,76,-34,81,-106,-1,-6,-73,42,95,-36,34,-108,24,86,
74,92,-125,71,72,41,-2,17,82,44,72,79,-4,-86,-82,-14,126,41,79,-1,-44,-56,-14,-47,114,
-85,-58,84,-75,-22,-3,-15,-19,-25,-29,74,54,-113,-8,74,29,38,-16,55,91,-39,-108,-30,55,
79,-54,51,82,-27,78,-33,120,-33,-61,51,-78,90,-11,-83,-12,98,-124,82,19,-103,123,-24,-34,
125,43,-85,-53,47,42,41,31,21,74,93,31,99,-33,-82,88,-54,75,82,-87,-113,11,-125,-59,87,74,
95,124,119,-47,78,41,44,-27,76,100,-18,-111,-69,-121,86,23,-41,-98,87,66,61,71,-35,102,87,
-40,-36,-42,-18,-88,-5,45,73,33,95,31,28,26,120,-83,-12,-55,15,-117,46,-42,-100,-120,52,38,
-58,-114,42,33,-114,43,-91,-10,-70,60,-60,85,86,74,121,-103,-128,77,-107,107,-77,-17,-37,
-22,90,17,81,-109,-109,-125,-115,-107,-7,15,-108,-14,31,-73,53,-100,-123,-100,-108,-34,
-121,-27,-62,-18,39,-27,-12,-12,106,-110,-67,68,34,-105,15,-114,-35,-80,-70,36,78,83,87,
-70,51,-55,88,55,-22,-87,-85,-99,29,-36,37,-114,-20,-3,108,-10,-49,78,-10,59,18,-87,-33,
63,126,-101,88,95,-1,-108,72,84,58,25,-23,118,29,-111,-87,-117,124,-2,80,-27,-21,-103,-97,
-29,-98,21,75,100,-93,37,-50,-11,-101,4,3,39,50,13,106,-103,-79,-72,-106,-15,88,-48,-52,49,38,
54,-70,83,95,91,34,-124,73,-88,-78,-58,68,-40,-52,114,-66,-114,36,-94,7,118,-97,-58,4,3,-117,
-54,49,78,-127,45,-86,-82,-115,-120,-98,98,123,60,59,69,1,-117,43,-61,-52,9,-116,-83,-11,-95,
49,-126,-59,110,101,113,-19,66,-73,-41,-119,86,16,-82,-9,88,103,10,67,3,35,-26,-94,25,106,17,
-67,98,119,121,-79,115,5,29,37,-113,23,13,-84,102,93,-48,34,122,-17,-76,-74,76,-83,-111,-19,
-74,-61,124,88,-106,-41,-40,-50,20,6,-118,35,-68,55,11,90,68,111,0,29,73,120,-41,14,-117,-21,
94,-88,-118,-46,27,-17,-119,-62,-40,-72,51,78,-24,64,23,54,96,-53,37,-31,-123,3,51,-21,104,
34,-40,-118,-21,93,44,-105,90,-26,-61,79,61,43,-82,126,-16,-112,40,-36,62,42,-10,-68,-6,-90,
40,78,60,96,-87,41,-76,44,116,-96,11,27,-80,-27,-102,-128,25,-40,-95,-89,-1,46,126,63,125,87,
-102,-83,120,-82,-76,-71,123,-105,-71,-100,-40,-3,-46,113,43,50,32,12,89,-24,112,50,109,113,89,
98,78,-57,7,-100,-123,32,-89,-119,-8,-66,127,56,81,41,66,96,-15,-93,83,66,53,-101,65,-115,13,
-103,40,18,-80,1,91,105,18,14,116,-48,-5,-97,8,78,118,41,-46,-54,-20,-116,-104,63,57,101,77,38,
-114,4,108,-64,86,-102,-92,79,-91,-92,40,113,-58,-10,-105,-101,-11,52,70,88,-89,19,-64,-27,-38,
87,90,-52,70,-122,-19,-71,-26,94,49,87,-55,-61,81,-32,-86,-40,42,15,-80,-13,84,104,-10,123,-18,
102,40,71,50,-21,112,-113,-18,-124,-106,96,-94,40,75,-101,-64,33,-81,-67,29,105,45,24,122,-79,
100,-114,-99,-48,82,-46,-45,-67,88,95,103,73,2,6,-63,-63,-125,-53,70,91,-49,-32,79,-109,105,29,
51,68,-96,-101,36,52,108,-30,-32,-79,-33,41,3,30,-38,68,64,-58,111,-9,-18,40,42,-53,-86,59,-103,
120,-63,97,-77,-67,-51,-102,29,120,77,62,50,-14,0,102,-104,-126,-39,-55,24,19,108,30,93,-52,118,
-47,100,29,-101,28,28,-88,3,-117,5,27,97,27,-103,-128,-124,-79,98,-93,59,-31,-57,-119,103,51,-56,
102,-106,-120,-125,7,95,108,22,6,35,73,96,-118,61,113,76,-1,92,119,0,46,-104,-64,33,15,-121,-78,
88,-33,-36,102,-72,24,96,-39,88,18,-58,58,-47,105,-99,-39,-22,90,2,14,-6,60,-14,-5,-60,-24,5,
107,-25,51,-93,-33,-56,109,72,-80,-118,-117,44,-21,36,-26,-28,12,-65,-87,118,126,68,-49,90,-16,
-118,39,42,68,8,-32,60,-31,-78,98,7,83,115,-60,70,51,-51,121,6,-112,24,-69,38,2,-41,126,4,-50,
-60,-94,-95,-57,-98,8,109,-59,109,86,108,-112,-7,-21,-28,-53,109,27,77,-40,74,-109,24,-69,38,
-126,-8,4,69,98,46,-71,26,106,-50,109,-86,-40,-112,96,-5,75,-75,47,-37,118,-51,-90,45,-106,75,
-52,9,-77,-58,78,-126,-63,-103,-67,126,96,-12,109,-14,-76,63,-99,-88,108,8,-32,120,-118,-109,
29,14,69,56,79,-72,110,-59,-47,-99,-48,18,32,-79,-16,-18,91,-62,-1,-37,109,37,32,-16,-17,84,
-66,57,-1,12,32,5,68,-26,16,-72,-71,18,-100,15,37,-118,20,33,-56,98,-68,-16,109,125,9,-84,-64,
-52,32,67,123,45,68,-118,-32,-4,-30,-54,-19,-102,3,35,-80,-102,-8,66,68,-32,-71,-93,-66,54,
101,10,108,-57,107,96,52,-67,-116,-64,24,-116,17,19,112,125,98,-1,-87,94,71,-89,-52,-25,119,
-70,70,20,-85,82,59,-41,54,87,-121,90,-124,13,-24,112,23,69,-118,-8,126,-69,-28,52,46,-50,2,91,
20,-98,-56,22,-127,-32,70,-96,103,-106,92,-7,-27,40,-59,94,-105,17,-119,58,5,122,-10,59,5,122,
0,82,43,-28,-13,7,-55,64,-90,95,40,-92,121,1,26,3,-123,-34,-30,72,-64,102,100,-41,-30,-121,33,
102,-121,112,23,-102,-108,-53,122,-99,-29,-39,-64,-48,41,126,8,76,29,-119,64,0,111,-95,92,-36
,115,0,-125,12,-9,-67,76,58,60,77,-49,-18,-44,18,-116,39,118,-116,-80,-128,-103,-17,-8,15,6,76,
50,87,-60,39,28,33,66,59,-3,-93,26,-109,12,-82,17,-97,64,88,2,30,-3,52,-97,57,121,-98,119,102,
-33,61,-109,63,-10,-19,51,-89,86,66,124,-33,-81,15,-49,-2,3,-60,27,-97,123,116,0,38,57,0,0,0,0,
73,69,78,68,-82,66,96,-126]}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
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
响应说明
响应体`
| 字段名 | 参数名 | 必填 | 类型 | 描述 | |
|---|---|---|---|---|
| 状态 | status | 是 | int | 200请求成功 |
| 字段名 | 参数名 | 必填 | 类型 | 描述 |
| 附件id | attachmentId | 是 | long | 附件id |
响应示例
{
"attachmentId": 1559115106002923521,
"msg": "success",
"status": 200
}1
2
3
4
5
2
3
4
5
错误码
| 错误码 | 描述 |
|---|---|
| 200 | 请求成功 |
| 其他 | 失败 |
Demo
java
File file = new File("/Users/jszhang/Documents/20240701151343.jpg");
Client client = new DefaultClient(BASE_URL, APP_ID, APP_SECRET);
AddAttachmentRequest request = new AddAttachmentRequest();
byte[] bytes = IOUtils.readToBytes(new FileInputStream(file));
request.setBytes(bytes);
request.setName("20240701151343.jpg");
request.setSchoolCode("test");
request.setSign("test");
request.setSize((int)file.length());
request.setType(AttachmentType_Constants.IMAGE);
AddAttachmentResponse execute = client.execute(request);
if (execute.isSuccess()) {
System.out.println(JSONObject.toJSONString(execute));
} else {
throw new Exception("上传附件异常:" + JSONObject.toJSONString(execute));
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

