1,安装suds库,用于方便的调用WebServices。
2,以用户名和密码访问A8的验证服务获取token。此token有效期为15分钟分钟,每一次有效请求延长 10分钟, 最长 15分钟。
3,以token访问所需服务。以BPMService(业务单据流程集成服务)为例,提供以下方法:
getAllFormCollIdsByDateTime(xs:string token, xs:string beginDateTime, xs:string endDateTime, )
getAllFormCollIdsByDateTimeAndState(xs:string token, xs:string beginDateTime, xs:string endDateTime, xs:int[] state, )
getFlowState(xs:string token, xs:long flowId, )
getFormApprovalState(xs:string token, xs:long id, )
getFormCollIdsByDateTime(xs:string token, xs:string[] templateCode, xs:string beginDateTime, xs:string endDateTime, )
getTemplateDefinition(xs:string token, xs:string templateCode, )
launchFormCollaboration(xs:string token, xs:string senderLoginName, xs:string templateCode, xs:string subject,
xs:string data, xs:long[] attachments, xs:string param, )
launchHtmlCollaboration(xs:string token, xs:string senderLoginName, xs:string templateCode, xs:string subject,
xs:string bodyContent, xs:long[] attachments, )
sendFormCollaboration(xs:string token, xs:string senderLoginName, xs:string templateCode, xs:string subject,
xs:string data, xs:string attachments, xs:string param, )
具体操作如下:
#!usr/bin/env python
#coding: utf-8
from suds.client import Client
'''验证服务
authenticate(xs:string userName, xs:string password, )
'''
authority_url = 'http://{host}:{port}/seeyon/services/authorityService?wsdl' # host和port换成部署A8系统的
client = Client(authority_url)
token = client.service.authenticate('admin', 'passwd') # 获取令牌
print token
'''
连接BPMservice
'''
form_url = 'https://{host}:{port}/seeyon/services/BPMService?wsdl'
client = Client(form_url)
print client
'''
获取模板(template)定义对象的XML组合,依次是[FlowExport, FormExport]
'''
template_export = client.service.getTemplateDefinition(token.id, "template") # template是在A8系统上设定的模板的名称
flowXml = template_export[0]
print flowXml
print "************************************************"
formXml = template_export[1]
print formXml
print "************************************************"
'''
发起表单流程
'''
attachments = []
response = client.service.launchFormCollaboration(token = token.id, senderLoginName = 'admin',
templateCode = 'test1', subject = 'form_test1',
date = '', attachments = attachments, param = '0')
print response
print "************************************************"
'''
按时间段查询多个表单模板已经审批通过和结束的流程
'''
templates = ['template']
flowId = client.service.getFormCollIdsByDateTime(token.id, templates, '2012-08-24 00:00:00', '2012-09-13 24:00:00')
print flowId
print "************************************************"
'''
获取某流程的流转状态
'''
state = client.service.getFlowState(token.id, flowId)
print state
A8服务列表: