• Python 调用定点软件LiveBos 接口


    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:])
  • 相关阅读:
    [NOIP模拟赛][贪心]奶牛晒衣服.
    BZOJ3750: [POI2015]Piecz
    BZOJ2348 [Baltic 2011]Plagiarism
    高精度乘法【高乘高
    codevs 1215 迷宫
    变量交换
    a+b问题与圆柱体表面积的计算
    算数表达式的练习
    [bzoj1070][SCOI2007]修车[ 网络流]
    [bzoj2502]清理雪道[上下界网络流]
  • 原文地址:https://www.cnblogs.com/bionexit/p/13300825.html
Copyright © 2020-2023  润新知