UiAuto|泛微Ecology系统附件上传插件

  此次场景需求是上传文件到公司内网门户系统(泛微Ecology),通过UIAUTO的键盘鼠标功能模拟登录后再上传虽然也是可以的。但不高级,也不高效,而且执行时对服务器界面也有一定要求。这里我通过调用泛微Ecology的接口从后台实现了文件的上传,测试效果十分稳定。插件源码如下:

package.json

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
"id": "zjtEcologyFileUpload",
"name": "zjfwfileupload",
"description": "泛微ecology9系统接口对接功能",
"version": "1.0.0",
"author": "chendi",
"language": "python",
"license": "Official",
"main": "index.py",
"uiauto_config": {
"attribution_id": "file_operation",
"attribution_name": "文件处理",
"operations": [
{
"category_id": "ecology",
"category_name": "ecology",
"operation_id": "uploadToEcology",
"operation_name": "附件上传",
"method": "uploadToEcology",
"type": "Convention",
"input": [
{
"name": "必填属性",
"id": "required_params",
"properties": [
{
"id": "urlip",
"name": "泛微系统IP",
"type": "text",
"required": true,
"value": ""
},
{
"id": "pcip",
"name": "本机IP",
"type": "text",
"required": true,
"value": ""
},
{
"id": "userName",
"name": "登陆用户",
"type": "text",
"required": true,
"value": ""
},
{
"id": "pwd",
"name": "登陆密码",
"type": "password",
"required": true,
"value": ""
},
{
"id": "typeid",
"name": "目录ID",
"type": "inputNumber",
"required": true,
"value": ""
},
{
"id": "filename",
"name": "附件名(含后缀)",
"type": "text",
"required": true,
"value": ""
},
{
"id": "filetitle",
"name": "附件标题",
"type": "text",
"required": true,
"value": ""
},
{
"id": "path",
"name": "文件路径",
"type": "path",
"required": true,
"value": "",
"options":{
"select_type":"openDirectory"
}
}
]
}
],
"output": {
"is_allow_global_use": true,
"description": "文件上传结果",
"value": ""
}
}
]
}
}

index.py

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
# -*- encoding:utf-8 -*-
'''
@description: 上传附件至泛微Ecology9系统中
@Time : 2023-06-02
@Author : CHENDI
@Version : 1.0.0
@Contact : henanchendi@163.com
'''

import base64
import datetime
import os
from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import
import time

# 根据关键字检索word内容
def uploadToEcology(params):
# 获取参数
urlip = params.get('urlip')
pcip = params.get('pcip')
userName = params.get('userName')
pwd = params.get('pwd')
filename = params.get('filename')
filetitle = params.get('filetitle')
path = params.get('path')
typeid = params.get('typeid')

# 访问接口,获取session
imp = Import('http://localhost/services/DocService')
doctor = ImportDoctor(imp)
url = 'http://{}/services/DocService?wsdl'.format(urlip)
client = Client(url,doctor=doctor)
# 获取session
result = client.service.login(userName,pwd,0,pcip)

# 封装
# DocAttachment信息
ArrayOfDocAttachment = client.factory.create('ns2:ArrayOfDocAttachment')
docinfo = client.factory.create('ns2:DocInfo')
DocAttach = client.factory.create('ns2:DocAttachment')
DocAttach.filename = filename #文件名称
base64_data =base64.b64encode(open(os.path.join(path,filename),'rb').read())
DocAttach.filecontent=base64_data.decode('utf-8')
DocAttach.docImageFileId = 1
DocAttach.docid = int(time.time())
ArrayOfDocAttachment.DocAttachment.append(DocAttach)
docinfo.docSubject = filetitle #发文标题'测试标题8'
docinfo.attachments = ArrayOfDocAttachment
docinfo.docType=1
docinfo.doccreatedate = datetime.date.today()
docinfo.doccreatetime = '17:00:00'
docinfo.seccategory = typeid
docinfo.maincategory = typeid
docinfo.seccategory = typeid
docinfo.subcategory = typeid
client.service.createDoc(docinfo,result)

if __name__ == '__main__':
pass

商业转载请联系作者获得授权,非商业转载请注明出处。

支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

UiAuto|泛微Ecology系统附件上传插件
http://hncd1024.github.io/2023/06/02/UiAuto_ecologyFileUpload/
作者
CHEN DI
发布于
2023-06-02
许可协议