LiveBos的WSDL模式下有通用的接口
execBizProcess(xs:string sessionId, xs:string bizProcessName, xs:string id, lbParameter[] params, lbParameter[] variables, )
但是上述接口的params变量无法在Python中实现,只能采用RESTFul形式,传递的参数一定要用JSON格式,如
requestdata_json = json.dumps(requestdata, separators=(',', ':'))
实例:
# -*- coding: utf-8 -*- """ @desc: SMS Sending though LiveBos of Apexsoft @author: Bionw @contact: wangheng@tjotc.com.cn @version: v0.1 """ import requests, json, sys, getopt, time # from urllib import request # URL = 'http://192.168.1.1:8101/service/LBREST' # Test enviroment URL = 'http://192.168.1.4:8101/service/LBREST' # Production enviroment login_URL = URL + '/userService/login' exec_URL = URL + '/biz/execProcess' service_user_id = 'webservice' service_user_password = '000000' """ Get User SessionId """ def get_session(): login_data = dict(userId=service_user_id, password=service_user_password) r = requests.get(login_URL, login_data) r.encoding = 'utf-8' r_json = r.json() sessionID = r_json['sessionId'] return sessionID """ Send Sms """ def send_sms(phone_number,message): # 短信核心参数 interface_name = 'TXXFS_XZDX' # 接口名称 message_type = 1 # 1|短信;2|邮件 XXLX message = message # XXNR 信息内容 phone_number = phone_number # JSR 接收人 sender = 'NAGIOS_SYS' # FSR 发送人 send_date = time.strftime("%Y/%m/%d") # PREFSRQ 预定发送日期 send_time = time.strftime("%H:%M:%S") # PREFSSJ 预定发送时间 params = { 'XXLX': message_type, 'XXNR': message, 'FSR': sender, 'JSR': phone_number, 'PREFSRQ': send_date } requestdata = { 'bizProcessName': interface_name, 'params': params } requestdata_json = json.dumps(requestdata, separators=(',', ':')) SMS_content = { # post数据集 'sessionId': get_session(), 'requestData': requestdata_json } # print(SMS_content) r = requests.post(exec_URL, SMS_content) r.encoding = 'utf-8' r_json = r.json() if r_json['result'] == 1: return '发送成功' else: return '发送失败' def main(argv): # phone_number = '' # message_content = '' try: opts, args = getopt.getopt(argv, "hp:m:", ["phone=", "message="]) except getopt.GetoptError: print('request.py -p <phone number> -m <message>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('request.py -p <phone number> -m <message>') sys.exit() elif opt in ("-p", "--phone"): phone_number = arg elif opt in ("-m", "--message"): message_content = arg print('输入的号码为:', phone_number) print('发送的内容为:', message_content) print(send_sms(phone_number,message_content)) if __name__ == '__main__': main(sys.argv[1:])