开放平台sdk
介绍
开放平台go版本sdk
安装教程
-
在go.mod中 增加 require gitee.com/yycloudopen/yonyou-openapi-sdk v1.0.0
-
在go调用文件中导入类库 示例如下
import (
openApiSdk "gitee.com/yycloudopen/yonyou-openapi-sdk/yonbip/open/api/sdk"
eventSdk "gitee.com/yycloudopen/yonyou-openapi-sdk/yonbip/open/event/sdk"
)
-
使用openSdk 或eventSdk调用业务方法即可
使用说明
- openApiSdk 提供了基于自建应用,生态应用的post、get请求方式,内部封装了accessToken的获取 ,使用方能直接使用业务数据进行接口访问,不需要关注接口请求细节
- eventSdk 提供了回调参数的解密功能,内部封装了验签和业务数据的解密,业务方调用后会直接返回业务数据结果,不需关注验签、解密等细节
openAPI调用示例
requestUrT := "https://bip-daily.yyuap.com"
//自建应用token配置
tokenSelfInfo := map[string]string{"appKey": "2231c234d3194f709b02ab99d157e4bd", "appSecret": "b569999441514b80a0c6ecb174173dfc"}
//生态应用token配置
tokenSuiteInfo := map[string]string{"suiteKey": "a814cc80f6f74a33a487c733179df330", "suiteSecret": "d620d5db26bc4f4ca73c175cc0a9b39b",
"tenantId": "cdy8mgyu"}
header:=make(map[string]string)
params:=map[string]string{
}
data:=map[string]interface{}{
"pageIndex": "1", "pageSize": "10",
}
dataUrl := "/yonbip/digitalModel/bankdot/list"
//自建应用接口调用
selfPostResult:= openSdk.OptSelfRequest("Post",requestUrT,dataUrl, params, header,data, tokenSelfInfo)
//生态应用接口调用
suitePostResult:= openSdk.OptSuiteRequest("Post",requestUrT,dataUrl, params, header,data, tokenSuiteInfo)
fmt.Println(selfPostResult)
fmt.Println(suitePostResult)
sdk 事件解密示例
web服务接收到回调请求时候,对于接收到的数据如下处理
//使用map方式 这里需要先把时间戳转为字符串
holderT := map[string]string{"signature": "nQn5A7f6kfSSSn/pHXKRPXMDVB6EulyYgsOLrOBVbUk=",
"timestamp": "1664331198154",
"nonce": "TBXxcwor6r7UEsnN",
"encrypt": "xJHi2lbl502Jjtp/GGCZgqa/kZaIEP/qIvvulD+53f/LSIOsmTrYfVgjn+iNKtxfKZv3tWNFJyB+NBFDY7GjnIxdxbjxD3JgGcyp1j19eje+DyKjVv+v5sXg+iOJx4ScV4l6DWa1YiLQAPhg0AU2gFN/sgCpFkVgjBFWKeiPuuTkwM5XOX7+25NakY/lQGqYP3GeqQea1fYwMCpN6aztfK4sHLu+tM4AuL2/gHCRR9jVTm6b8dvML9s3NVxZRbzyfpWgt88d4ycDuK/3v83Hzu3vZc8ZdFO6xjAZuV7T3Aw=",
}
//使用struts方式
holderT1 := eventSdk.EncryptStruts{
Nonce: "TBXxcwor6r7UEsnN",
Encrypt: "xJHi2lbl502Jjtp/GGCZgqa/kZaIEP/qIvvulD+53f/LSIOsmTrYfVgjn+iNKtxfKZv3tWNFJyB+NBFDY7GjnIxdxbjxD3JgGcyp1j19eje+DyKjVv+v5sXg+iOJx4ScV4l6DWa1YiLQAPhg0AU2gFN/sgCpFkVgjBFWKeiPuuTkwM5XOX7+25NakY/lQGqYP3GeqQea1fYwMCpN6aztfK4sHLu+tM4AuL2/gHCRR9jVTm6b8dvML9s3NVxZRbzyfpWgt88d4ycDuK/3v83Hzu3vZc8ZdFO6xjAZuV7T3Aw=",
Timestamp: 1664331198154,
Signature: "nQn5A7f6kfSSSn/pHXKRPXMDVB6EulyYgsOLrOBVbUk=",
}
plain_info1 := eventSdk.DecryptEventEncryptFromStruts("d59640fc3891476abed61978ca4ea6d2", holderT1)
plain_info := eventSdk.DecryptEventEncrypt("d59640fc3891476abed61978ca4ea6d2", holderT)
println("解密结果:")
println(plain_info1)
print(plain_info)
参与贡献
特技