基于Python的Webservice开发(四)-泛微OA的SOAP接口

时间:2023-03-09 09:03:31
基于Python的Webservice开发(四)-泛微OA的SOAP接口

一、功能需求

泛微e-cology可以在流程中调用Webservice接口实现与其他系统的联动等复杂功能。但是目前泛微文档中仅提供了调用的方法,但是没有关于接口的相关开发信息。

本次案例是用Python开发一个泛微e-cology 可以调用的Webservice接口。

二、所需要的库

pip install spyne

对于Python3

pip install spyne==2.13.4a1

三、代码实现

from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from spyne import Application,rpc,ServiceBase,Integer,Unicode,String class HelloWorldService(ServiceBase):
#rpc内包含了传入参数以及传出参数的类型。
#前半部分是传入参数,参数类型必须是String,传入参数可以定义多个。参数名一定要与OA中待传入的参数名一致。这里调用的是requestid
#_returns=String是传出参数,用以判断运行是否成功。
@rpc(String,_returns=String)
def say_hello(ctx,requestid ):
print(requestid )
return 'Succeed'
application = Application([HelloWorldService],
#命名空间 tns
tns='spyne.examples.hello',
#传入类型Soap11(),千万不要验证,encodingStyle是不被支持的。
in_protocol=Soap11(),
#传出类型Soap11()
out_protocol=Soap11()
)
#本地测试运行,生产环境还是挂在Django下的
if __name__ == '__main__':
# You can use any Wsgi server. Here, we chose
# Python's built-in wsgi server but you're not
# supposed to use it in production.
from wsgiref.simple_server import make_server
wsgi_app = WsgiApplication(application)
server = make_server('0.0.0.0', 8000, wsgi_app)
server.serve_forever()

四、泛微OA中的设置

1、注册Webservice接口

基于Python的Webservice开发(四)-泛微OA的SOAP接口

2、绑定表单与接口

入口点:集成中心--流程流传集成

参数值可以点击主表、明细表中字段 获取。但是参数值的名字,如此处的$requestid$必须和参数名requestid一致。

返回值必须与函数的返回值一致,这里设置的Succeed。

基于Python的Webservice开发(四)-泛微OA的SOAP接口

3、流程节点中附加操作

可以在节点前或者节点后附加操作

基于Python的Webservice开发(四)-泛微OA的SOAP接口

4、测试提交流程

流程提交至下一个节点说明接口运行成功。

如果运行失败会提示接口运行失败,不会提交到下一个节点。