更新时间:2023-11-02 GMT+08:00
分享

创建SparkPackERP连接器

  1. 登录集成工作台-连接器-我的连接器-创建我的连接器

    采用自定义认证,使用函数,创建函数。

    编辑源码,输入Python代码。

    # -*- coding:utf-8 -*-
    import json
    import base64
    import requests
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    def login(body, mssiAuthData):
        url = mssiAuthData.get("host") + "/b1s/v1/Login"
        headers = {'Content-Type': 'application/json'}
        if body.get("Language"):
            data = {
                "CompanyDB": body["CompanyDB"],
                "UserName": body["UserName"],
                "Password": body["Password"],
                "Language": int(body["Language"])
            }
        else:
            data = {
                "CompanyDB": body["CompanyDB"],
                "UserName": body["UserName"],
                "Password": body["Password"],
            }
        session = requests.Session()
        session.post(url, json=data, headers=headers, verify=False)
        _cookies = []
        for k, v in session.cookies.get_dict().items():
            _cookies.append(k + "=" + v)
        return {'Cookie': ';'.join(_cookies)}
    def extractRequestParam(rawValue, encoded, defaultValue):
        if encoded and rawValue:
            rawValue = str(base64.b64decode(rawValue), "utf-8")
        return json.loads(rawValue) if rawValue else defaultValue
    ## 请勿对下面的函数做修改
    def handler(event, context):
        """
        函数是方法的入口
        :param event: 执行事件(event), 包含用户定义的函数参数以及所选择的的连接器认证相关参数
        :param context: Runtime提供的函数执行上下文
        :return:
        """
        isBase64Encoded = event.get('isBase64Encoded', False)
        inputData = extractRequestParam(event.get('body'), isBase64Encoded, {})  # 用户定义的函数参数数据
        mssiAuthData = extractRequestParam(event.get('mssiAuthData'), isBase64Encoded, {})  # 连接器认证数据
        mssiAuthData["securityToken"] = context.getToken()
        dataExtendConfig = extractRequestParam(event.get('dataExtendConfig'), isBase64Encoded, {})  # 流步骤扩展参数
        result = login(inputData, mssiAuthData)
        return json.dumps(result)

    连接器配置如下。

相关文档