Python|泛微Ecology附件上传接口

在《UiAuto|泛微Ecology系统附件上传插件》中,我通过ecology8的WSDL实现了文件的上传,但在实际运用中需要用账号密码获取session,还要封装docinfo信息才能实现上传和下载。这篇文章我们试下另一种方式的文件上传,并简单测试下流程创建的场景。

参考文档

泛微接口文档》 ,参照的是知识管理-附件上传接口。

源码

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
import requests
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
import os

# RSA加密
def encode_RSA(secret):
public_key = '''-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAulJs+6YSbEQIDAQAB
-----END RSA PUBLIC KEY-----
'''
secret = secret.encode('utf-8')
rsakey = RSA.importKey(public_key)
cipher = Cipher_pkcs1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(secret))
return cipher_text

# 获取token
def getToken(secret):
url = 'http://ip:1234/api/ec/dev/auth/applytoken'
headers = {'appid': 'jictai','secret':secret}
response = requests.post(url, headers=headers )
return response


def uploadFile(token,userid,category,path,filename):
url = r'http://ip:1234/api/doc/upload/uploadFile2Doc'
headers = {
'token': token,
'appid': 'jictai',
'userid' : userid
}
files=[
('file',(filename,open(os.path.join(path,filename),'rb')))
]
data = {
"category" : category
}
response = requests.request("POST", url, headers=headers,data=data,files=files)
return response
if __name__ == '__main__':
secret = '81ab3ed5b33'
secretRSA = encode_RSA(secret)
userid = encode_RSA('683')
response = getToken(secretRSA)
if response.status_code == 200 :
token = response.json()['token']
print(token)
result = uploadFile(token=token,userid=userid,category='91',path=r'C:\Users\admin\Downloads',filename='a.jpg')
print(result.text)

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

支付宝打赏 微信打赏

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

Python|泛微Ecology附件上传接口
http://hncd1024.github.io/2023/09/01/Ecology_apiUpload/
作者
CHEN DI
发布于
2023-09-01
许可协议