A Go SDK specifically designed for seamless interaction with YOP (YeePay Open Platform) APIs.
This SDK provides a convenient way to integrate YeePay payment and other services into your Go applications. It handles request signing, signature verification, and API communication, allowing you to focus on your application logic.
Key Features:
Use Cases:
Install this package using Go modules:
go get cnb.cool/1024hub/yop-go-sdk
YOP Go SDK configuration is primarily set through the YopRequest object. Here are the main configuration items:
The SDK supports the following certificate types:
// Defined in the request package
const (
RSA2048 = "RSA2048" // RSA2048 algorithm
)
var priKey = &request.IsvPriKey{Value: "Your private key content", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/api/path")
yopRequest.AppId = "Your AppId"
yopRequest.IsvPriKey = priKey
yopRequest.Timeout = 15 // Set timeout to 15 seconds (optional)
import (
"cnb.cool/1024hub/yop-go-sdk/yop/client"
"cnb.cool/1024hub/yop-go-sdk/yop/constants"
"cnb.cool/1024hub/yop-go-sdk/yop/request"
"cnb.cool/1024hub/yop-go-sdk/yop/utils"
)
var priKey = &request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc")
yopRequest.AppId = "appId"
yopRequest.IsvPriKey = priKey
yopRequest.AddParam("paramName", "paramValue")
yopResp, err := client.DefaultClient.Request(yopRequest)
if nil != err{
// request failed
}
//yopResp.Result is the request result
var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc")
yopRequest.AppId = "appId"
yopRequest.IsvPriKey = priKey
yopRequest.AddParam("paramName", "paramValue")
yopResp, err := client.DefaultClient.Request(yopRequest)
if nil != err{
// request failed
}
//yopResp.Result is the request result
var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc")
yopRequest.AppId = "appId"
yopRequest.IsvPriKey = priKey
// Set JSON request payload
var params = map[string]any{}
params["merchantId"] = "1595815987915711"
params["requestId"] = "requestId"
result.Content = utils.ParseToJsonStr(params)
yopResp, err := client.DefaultClient.Request(yopRequest)
if nil != err{
// request failed
}
//yopResp.Result is the request result
var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc")
yopRequest.AppId = "appId"
yopRequest.IsvPriKey = priKey
result.AddFile("file", f)
yopResp, err := client.DefaultClient.Request(yopRequest)
if nil != err{
// request failed
}
// yopResp.Result is the upload request result
var priKey = request.IsvPriKey{Value: "isvPriKey", CertType: request.RSA2048}
var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD, "/rest/v1.0/test/product-query/query-for-doc")
yopRequest.AppId = "appId"
yopRequest.IsvPriKey = priKey
yopRequest.AddParam("paramName", "paramValue")
yopResp, err := client.DefaultClient.Request(yopRequest)
if nil != err{
// request failed
}
// yopResp.Content is the file content
//utils.DecryptCallback
var callback = "Ars6jASSiylO70_VJDQ5SFU1zQwaI36kG5WhlSKHjkGdU3fEVEkkbhvAxKjOTUiw9vF7RMnmGKQQWAuV8jCKaOpMNjIEMHehBaPASwTiEE946CcbOeoNILGHf0o20xj2gqqvkQToFXEMNiic7bcYbfi0PxIrR6loBZnW-m5bqzB5RXLibiSjGlmr5CDnxV4tZXmYlkkeN2BcT4msWjfCtuaTMK_fN77WJcCMlW7ffqiN5yIOeqB4QBb5lOnClTRW4DThKPOMkXupAM2AnPxTkDp4n9lh-SK56zLuafk1bQhWUNcS9L4YEKZGJIjP7DY20TAWEr3yXo8w0w0VtB13Ig$Xf6fETKWcLTudBh2HluGSQTqhBRJa6EXHhXlMryWW8Y384RjVwIfpQm19RmTgkoqRc2tNcTWxRIW6itIS62DrzixlqRa099jx21uGqt8FCpvdWwnwlC16SgkeU_5NnrpjA_WQ0XW9RhNxzuQmwfxHGbtnth4vNXWswcSm23j3KQaXFjVP5Ws1uYVCxYSLMxqJE7a56DNWONGcGJJsc0KTCc7cdfr8n24emAaPCNteIG2RM8F17pRxY5yVnguTSZPXmhBlyI25xS7rciWzKZLp2Kfh_JCivABbA-_5Vf3VWPmjITs-TR5HlGVFbnT0eOUMUepXUemjjP8R0f8cBeH2NKej6QjQL99tvlrrxg_QfmezE0WTCITCNDBhpbHiq90lFyLjwlWNDTRo8rhjouSlMA9Ae_b-B4eZorDRVxw3BWywdyo2FzNk-dUDeBVaIth9YsaMGsq9XivGjlnnx3YEVfEtuVSvEm1xBdYsTHcM02nMwZb8Ze2WL1kIFo8IFM0$AES$SHA256"
// This is test data, please use the real platform public key for production
var platformPubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7LqdMV7ZeOWUwVp0duSucTr4VwUNHtYLlWEUWlBtDQDEPhx0WZZdw2DxEbQqMQM5BjXZACYlhEdPt0HicDthOIUeUt8JNcvgq06vIE958RzgVBa5z3zvMLYWJIZaUyxsxC7Us06eNiB+du0rEBxUckru41ZSu/DX9jssFC+l5459b3WWELNf2fXqJyfb4f8GuGk8enXgJdxBUcmwgaEQxJjWkPqhzSiRy9GKjcXBdCkzCYR4xmLkHe6K0YFiBxax7lOni3zVOsvHC9XdhbepwB9fMkHbZXS/LJf5aS5ltendObpVrAD9kck7bIQzsrM49/SG/dYmbtm139I6ygsCzQIDAQAB"
var isvPriKey = "<Private Key Text>"
content, err := utils.DecryptCallback(platformPubKey, isvPriKey, callback)
if nil != err {
//"decrypt failed"
}
//utils.RsaSignBase64
// This is test data, please use the real private key for production
var priKey = "<Private Key Text>"
var content = "a=123!@#¥%……Chinese"
signature, error := utils.RsaSignBase64(content, priKey, crypto.SHA256)
if nil != error {
//sign error
}
//utils.VerifySign
// This is test data
var pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwRwXR20F7D0/hKQISwPZNkOTvBiwgFBS1mAee1IXOGTWtmFIY60xbxWTBULjI2lYHZhRk76nxmFEAUZXRxYX/ZLl3+Sz2/ptASf0eQFgsk3F+wx6LqBjgzH8ZAma4piC8GFg5MIWEx6+YRFefJxkULRziFQeWuIv8uGdb719TCIwPvDid86WsVypI/uOjrX5o5aFDxhUs8/q6q0UbTKmHjy5FmdCfgpiFzNSsJf5IGFKv2BkmMvUOb06IzfVgSs5O3rjqAnLFrUawUMrHcjN8gz144Z18extJ4dO4UlIfqzA2e2bLdJVUKJf+5D18zcIenlJkRmPZX67iDEuZINcnQIDAQAB"
var signature = "glTZg6lLl6oV4Ho15fAUegcVILlTwYJkbZO_Iz8AYUKTZ_1JP4AqAqSdm3GqjaukoNrDkxPGv2WW8plxYxtzsXjkzWiCMth5aShHgA7a9SXW0jfo365KPyVj0zFO2QIV9odHEnY1apwcAxvr54j4d5SHoC3vKUczZ20txTsNjcG9ifi1AoJhblILxKL2NO0tdIzTMQCRaBdOXUOdnL7RgP1qPew5yJT4e1QdtTjkirCKJurm4SumOA3Uroz-G-9MUZgiTkU4RXrEvu-rJPlqfJPsITYoWLsuPy1Gfne_5j-IgChXpoHacI0s-NlzKmyjsFt3-5aUYDd0cFw58ErUXw"
var data = "{\"result\":{\"requestId\":\"requestId\",\"errorMsg\":\"exception.record.not.found.transferDomesticOrder|merchantId:[null],requestId:[requestId]\",\"status\":\"FAILED\"}}"
if !utils.VerifySign(data, signature, pubKey, crypto.SHA256) {
//verify failed
}
YopRequest is the main object for initiating YOP API requests.
AppId: Application identifierIsvPriKey: Application private keyTimeout: Request timeout (seconds)Content: Request content (for JSON requests)NewYopRequest(httpMethod, apiUri string): Create a new request objectAddParam(paramName, paramValue string): Add request parameterAddFile(paramName string, file *os.File): Add upload fileYopResponse is the encapsulation of YOP API responses.
State: Response statusResult: Request resultError: Error informationContent: Response content (for file downloads)utils.DecryptCallback(platformPubKey, isvPriKey, callback string) (string, error): Decrypt callback contentutils.RsaSignBase64(content, priKey string, hash crypto.Hash) (string, error): Generate signatureutils.VerifySign(data, signature, pubKey string, hash crypto.Hash) bool: Verify signatureContributions are welcome! If you find any issues or have suggestions for improvements, please submit an issue or pull request.
This SDK follows the Apache License 2.0 open source license agreement.
We are committed to providing an excellent developer experience. If you encounter any issues or have any suggestions during use, please feel free to contact us through official channels.