第三方连接
更新时间: 2024-02-05 浏览次数: {{ hits }}

连接

1、前往插件中心,在第三方连接,新增连接(代码),配置连接编码和url

2、前往表单,调用InvokeApi

H3.BizBus.BizStructureSchema contextSchema = new H3.BizBus.BizStructureSchema();
        contextSchema.Add(new H3.BizBus.ItemSchema("time", "时间", H3.Data.BizDataType.TimeSpan, null));
        contextSchema.Add(new H3.BizBus.ItemSchema("desc", "说明", H3.Data.BizDataType.String, null));

        H3.BizBus.BizStructureSchema msgSchema = new H3.BizBus.BizStructureSchema();
        msgSchema.Add(new H3.BizBus.ItemSchema("context", "内容数组", H3.Data.BizDataType.BizStructureArray, contextSchema));
        msgSchema.Add(new H3.BizBus.ItemSchema("state", "状态", H3.Data.BizDataType.String, null));
        msgSchema.Add(new H3.BizBus.ItemSchema("com", "公司", H3.Data.BizDataType.String, null));
        msgSchema.Add(new H3.BizBus.ItemSchema("status", "状态", H3.Data.BizDataType.String, null));
        msgSchema.Add(new H3.BizBus.ItemSchema("_support_from", "支持方式", H3.Data.BizDataType.String, null));


        H3.BizBus.BizStructureSchema structureSchema = new H3.BizBus.BizStructureSchema();
        structureSchema.Add(new H3.BizBus.ItemSchema("status", "返回码", H3.Data.BizDataType.Int, null));
        structureSchema.Add(new H3.BizBus.ItemSchema("msg", "返回内容", H3.Data.BizDataType.BizStructure, msgSchema));

        Dictionary<string, string> headers=new Dictionary<string, string>();
        Dictionary<string, object> bodys=new Dictionary<string, object>();
        Dictionary<string, string> querys=new Dictionary<string, string>();
        querys.Add("com", "zhongtong");
        querys.Add("src", "543504132797");
        headers.Add("Authorization", "APPCODE fc5fa66a3ad8459a9692d7e11d8ec1a7");
        //调用Invoke接口,系统底层访问第三方WebService接口的Invoke方法
        H3.BizBus.InvokeResult InResult = this.Engine.BizBus.InvokeApi(H3.Organization.User.SystemUserId, H3.BizBus.AccessPointType.ThirdConnection, "chenbing20210224", "POST", "application/x-www-form-urlencoded;charset=UTF-8",headers, querys, bodys,structureSchema);
        if(InResult != null)
        {
            int Code = InResult.Code; //调用是否成功
            if(Code == 0)
            {
                //获取返回数据
                H3.BizBus.BizStructure Obj = InResult.Data;
                H3.BizBus.BizStructure msgObj =Obj["msg"] as H3.BizBus.BizStructure;
                H3.BizBus.BizStructure[] contextObj =msgObj["context"] as H3.BizBus.BizStructure[];
                string codee=contextObj[0]["desc"] as string;
                this.Request.BizObject["F0000002"]=codee;
            }
            else
            {
                //获取错误信息
                string ErrorMessage = InResult.Message;
            }
        }


账户

第三方需要验证连接者身份,确定连接者是否有权限访问什么资源,再决定是否把用户请求的资源返给他,鉴权是这么一种安全机制。账户用于存储鉴权信息,也就是身份验证信息。建议不要直接将敏感信息展示在代码中,用账户存储,再前往表单用代码调用账户信息。

  • 百度AI开放平台:支持调用access_token,调用时判断有效期,过期更新

  • 阿里云API市场:支持调用AppCode

  • 百度云API市场:支持调用AppCode

  • 第三方平台企业内部应用:支持调用access_token,调用时判断有效期,过期更新

  • 用友U8:支持代码调用token,调用时判断有效期,过期自动更新

  • Basic Authentication:支持调用所有自定义参数,例如阿里云API市场


1、前往插件中心->第三方连接->账户,新建账户,选择第三方,填写账户编码,以及第三方所需信息。

2、前往表单,调用账户

H3.BizBus.BizStructureSchema structureSchema = new H3.BizBus.BizStructureSchema();
        structureSchema.Add(new H3.BizBus.ItemSchema("token", "授权令牌", H3.Data.BizDataType.String, null));

        //调用Invoke接口,系统底层访问第三方WebService接口的Invoke方法
        H3.BizBus.InvokeResult InResult = this.Engine.BizBus.InvokeApi(H3.Organization.User.SystemUserId, H3.BizBus.AccessPointType.ThirdAuthToken, "ZHUMW", null, null, null, null, null, structureSchema);
        if(InResult != null)
        {
            int Code = InResult.Code; //调用是否成功
            if(Code == 0)
            {
                //获取返回数据
                H3.BizBus.BizStructure Obj = InResult.Data;
                string token = Obj["token"] as string;
                this.Request.BizObject["F0000001"] = token;
            }
            else
            {
                //获取错误信息
                string ErrorMessage = InResult.Message;             
                this.Request.BizObject["F0000002"] = ErrorMessage;
            }
        }


加密算法

通过第三方连接调用淘宝京东商家抖店快手电商等开放平台接口,为了防止API在调用过程中被恶意者拦截随意篡改,第三方要求调用API时需要携带签名参数,第三方服务端会根据请求参数对签名进行验证,签名不合法的请求将会被拒绝。

加密算法:MD5、SHA1、HMAC (HMACSHA1、HMACSHA256、HMACSHA384、HMACSHA512)

加密算法类:对数据进行加密,返回base64编码结果

  • H3.Security.Cryptography.MD5

  • H3.Security.Cryptography.SHA1

  • H3.Security.Cryptography.HMAC

示例1

将 abc123 进行MD5加密,编码格式为UTF8,返回结果为6ZoYxCjLONXyYIU2eJIuAw==

var result = H3.Security.Cryptography.MD5.MD5Encrypt("abc123",System.Text.Encoding.UTF8);

示例2

将 abc123 进行HmacSHA256加密,编码格式为UTF8,返回结果为NBaoyFtWd7xebliBvxq/Pfmw070Ju/ETPJxfnu1S0g8=

var result = H3.Security.Cryptography.HMAC.HMACSHA256Encrypt("abc123",System.Text.Encoding.UTF8);