cores

package
v0.0.0-...-1038186 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FunCodePayment           = &FunCode{Code: "6001", Name: "payment"}             // function code for payment
	FunCodePaymentQuery      = &FunCode{Code: "6002", Name: "payment_query"}       // function code for payment query
	FunCodeBalanceQuery      = &FunCode{Code: "6003", Name: "balance_query"}       // function code for balance query
	FunCodeSyncFaceAuth      = &FunCode{Code: "6008", Name: "sync_face_auth"}      // function code for sync face recognition record
	FunCodeFaceAuth          = &FunCode{Code: "6009", Name: "face_auth"}           // function code for face recognition authentication
	FunCodeSignContract      = &FunCode{Code: "6010", Name: "sign_contract"}       // function code for contract signing
	FunCodeSignContractQuery = &FunCode{Code: "6011", Name: "sign_contract_query"} // function code for contract status query
)

Function codes

View Source
var (
	ErrInvalidConfig      = fmt.Errorf("invalid configuration")
	ErrEncryptionFailed   = fmt.Errorf("encryption failed")
	ErrDecryptionFailed   = fmt.Errorf("decryption failed")
	ErrSignatureFailed    = fmt.Errorf("signature generation failed")
	ErrVerificationFailed = fmt.Errorf("signature verification failed")
	ErrRequestFailed      = fmt.Errorf("request failed")
	ErrInvalidResponse    = fmt.Errorf("invalid response")
	ErrInvalidKey         = fmt.Errorf("invalid key format")
)

Common SDK errors

View Source
var (
	ErrApiSuccess                      = NewAPIError("0000", "当前请求处理成功")
	ErrApiUnknown                      = NewAPIError("6000", "当前请求处理未明,请核实")
	ErrApiParamError                   = NewAPIError("6001", "参数错误")
	ErrApiInvalidAmount                = NewAPIError("6002", "无效交易金额")
	ErrApiCustomerNotFound             = NewAPIError("6003", "客户信息不存在")
	ErrApiCustomerStatusNotOpen        = NewAPIError("6004", "客户状态未开通")
	ErrApiCustomerKeyEmpty             = NewAPIError("6005", "客户秘钥为空")
	ErrApiSignVerifyFailed             = NewAPIError("6006", "请求数据验签失败")
	ErrApiDecryptFailed                = NewAPIError("6007", "请求数据解密失败")
	ErrApiMerchantBlacklisted          = NewAPIError("6008", "商户在黑名单不允许交易")
	ErrApiNoRiskControlInfo            = NewAPIError("6009", "无客户风控信息")
	ErrApiAccountInvalid               = NewAPIError("6010", "无客户账户信息或账户状态无效")
	ErrApiIPNotWhitelisted             = NewAPIError("6011", "客户请求地址未配置白名单")
	ErrApiBatchNoDuplicate             = NewAPIError("6012", "客户批次号重复,请确认批次信息")
	ErrApiAmountLimitExceeded          = NewAPIError("6013", "付款金额超限")
	ErrApiSaveFailed                   = NewAPIError("6014", "信息入库失败")
	ErrApiFeeCalculationError          = NewAPIError("6015", "计算客户手续费出错或客户手续费率不存在")
	ErrApiAlreadySigned                = NewAPIError("6016", "该用户信息已经做过签约")
	ErrApiPaymentMethodNotConfigured   = NewAPIError("6017", "客户付款方式未配置")
	ErrApiPermissionDenied             = NewAPIError("6018", "客户未开通该权限")
	ErrApiInsufficientBalance          = NewAPIError("6019", "商户余额不足")
	ErrApiOrderNotFound                = NewAPIError("6020", "未查询到订单")
	ErrApiNotSignedWithServiceCompany  = NewAPIError("6021", "客户未签约此落地服务公司")
	ErrApiSignAuthFailed               = NewAPIError("6022", "签约信息鉴权失败")
	ErrApiBillFileNotFound             = NewAPIError("6023", "对账文件不存在")
	ErrApiNameEmpty                    = NewAPIError("6024", "姓名不能为空")
	ErrApiIdCardEmpty                  = NewAPIError("6025", "身份证号不能为空")
	ErrApiServiceIdEmpty               = NewAPIError("6026", "服务商 Id 不能为空")
	ErrApiNotSignedWithServiceProvider = NewAPIError("6027", "用户未在该服务商签约")
	ErrApiPlatformProviderNotFound     = NewAPIError("6028", "未查询到对应的平台服务商")
	ErrApiPlatformProviderUnavailable  = NewAPIError("6029", "该平台服务商不可用")
	ErrApiCustomerIdEmpty              = NewAPIError("6030", "客户id不能为空")
	ErrApiBatchNoEmpty                 = NewAPIError("6031", "客户批次号不能为空")
	ErrApiBatchNoNotFound              = NewAPIError("6032", "该客户批次号不存在")
	ErrApiOrderNoNotFound              = NewAPIError("6033", "客户订单号或者订单流水号不存在")
	ErrApiTotalCountMismatch           = NewAPIError("6034", "付款总笔数和明细不一致")
	ErrApiTotalAmountMismatch          = NewAPIError("6035", "付款总金额和明细不一致")
	ErrApiMultiServiceProviders        = NewAPIError("6036", "批量付款只能选择一个服务商")
	ErrApiSigningInProgress            = NewAPIError("6037", "该用户签约中")
	ErrApiApiSigningNotSupported       = NewAPIError("6038", "该客户不支持API接口签约")
	ErrApiIdCardImagesRequired         = NewAPIError("6039", "服务商需要上传身份证正反面图片")
	ErrApiTaskCodeRequired             = NewAPIError("6040", "服务商需要上传任务编码")
	ErrApiTaskNotFound                 = NewAPIError("6041", "不存在该任务")
	ErrApiRequestTooFrequent           = NewAPIError("6042", "请求频繁请稍后再试")
	ErrApiThreeElementAuthFailed       = NewAPIError("6043", "三要素认证失败")
	ErrApiNotSignedWithProvider        = NewAPIError("6044", "该客户未签约此服务商")
	ErrApiInvoiceCategoryNotFound      = NewAPIError("6045", "未查询到可开票类目信息")
	ErrApiInvoiceInfoNotFound          = NewAPIError("6046", "未查询到该客户在该服务商开票信息")
	ErrApiRiskAuditRequired            = NewAPIError("6047", "该客户订单需要待风控审核后才能下发")
	ErrApiRiskAuditFailed              = NewAPIError("6048", "风控审核未通过")
	ErrApiRecordNotFound               = NewAPIError("6049", "未查询到符合条件的记录")
	ErrApiTaskStatusError              = NewAPIError("6050", "任务状态有误")
	ErrApiOrderNoDuplicate             = NewAPIError("6051", "客户订单号重复,请确认订单信息")
	ErrApiApiNotSupported              = NewAPIError("6052", "该客户不支持 API 接口")
	ErrApiFeeRateNotConfigured         = NewAPIError("6053", "该客户费率未配置")
	ErrApiRechargeOrderNoDuplicate     = NewAPIError("6054", "充值订单号重复,请确认充值信息")
	ErrApiRechargeAmountNotFound       = NewAPIError("6055", "未查询到可充值金额")
	ErrApiRechargeAccountMismatch      = NewAPIError("6056", "充值账号与平台不一致")
	ErrApiRechargeAmountExceeded       = NewAPIError("6057", "充值金额大于可充值金额")
	ErrApiMultiPaymentMethods          = NewAPIError("6058", "批量付款只能选择一种代付方式")
	ErrApiManagementFeeModeMismatch    = NewAPIError("6059", "客户管理费扣费方式与服务商不一致")
	ErrApiManagementFeeRateMismatch    = NewAPIError("6060", "客户管理费费率方式与服务商不一致")
	ErrApiSignConfigNotFound           = NewAPIError("6062", "未查询到签约要素配置")
	ErrApiProviderConfigIncomplete     = NewAPIError("6063", "服务商配置未完成,请联系运营")
	ErrApiEnterpriseApiNotSupported    = NewAPIError("6064", "该企业不支持API,请联系运营")
	ErrApiChannelNotSupported          = NewAPIError("6065", "暂不支持该通道余额查询和分账")
	ErrApiMerchantPublicKeyError       = NewAPIError("6067", "商户公钥格式错误")
	ErrApiOneClickPaymentNotEnabled    = NewAPIError("6093", "未开通一键下发功能,请联系运营")
	ErrApiManualConfirmRequired        = NewAPIError("6100", "个人需手动确认收款,请在app或小程序发起")
	ErrApiVerifySignOrTaskFailed       = NewAPIError("6101", "校验签约,任务领取单等信息失败")
	ErrApiRequestTimeout               = NewAPIError("6102", "请求超时,请重试")
	ErrApiOrderCannotBeCancelled       = NewAPIError("6103", "非待确认订单不可撤销")
	ErrApiSettleTimeError              = NewAPIError("6104", "当前时间不可结算,请稍后重试")
	ErrApiSignTimeError                = NewAPIError("6105", "当前时间不可签约,请稍后重试")
	ErrApiNoElectronicReceipt          = NewAPIError("6220", "暂无电子回单")
	ErrApiFaceAuthRecordExists         = NewAPIError("6323", "已存在人脸认证记录")
)

API Business Errors

Functions

func DecryptDES

func DecryptDES(ciphertext, key string) (string, error)

DecryptDES decrypts Hex-encoded ciphertext using DES-ECB mode. Returns plaintext after removing PKCS5 padding.

func EncryptDES

func EncryptDES(plaintext, key string) (string, error)

EncryptDES encrypts plaintext using DES-ECB mode with PKCS5 padding. Returns Hex-encoded ciphertext (uppercase).

func ParsePrivateKey

func ParsePrivateKey(pemKey string) (*rsa.PrivateKey, error)

ParsePrivateKey parses RSA private key from PEM format (PKCS8) or raw base64.

func ParsePublicKey

func ParsePublicKey(pemKey string) (*rsa.PublicKey, error)

ParsePublicKey parses RSA public key from PEM format or raw base64.

func Sign

func Sign(data string, privateKey *rsa.PrivateKey) (string, error)

Sign signs data using RSA-SHA1 and returns Base64-encoded signature.

func Verify

func Verify(data, signatureStr string, publicKey *rsa.PublicKey) error

Verify verifies RSA-SHA1 signature.

Types

type APIError

type APIError struct {
	Code    string
	Message string
}

APIError represents an error returned by the ServiceShare API.

func NewAPIError

func NewAPIError(code, message string) *APIError

NewAPIError creates a new APIError.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is checks if the target error is an APIError with the same code.

type AuthChannel

type AuthChannel string

AuthChannel represents the face authentication channel type.

const (
	AuthChannelBaidu     AuthChannel = "01" // 百度云
	AuthChannelAliyun    AuthChannel = "02" // 阿里云
	AuthChannelTencent   AuthChannel = "03" // 腾讯云
	AuthChannelFadada    AuthChannel = "04" // 法大大
	AuthChannelAlipay    AuthChannel = "05" // 支付宝
	AuthChannelVolcano   AuthChannel = "06" // 火山引擎
	AuthChannelHuawei    AuthChannel = "07" // 华为云
	AuthChannelSensetime AuthChannel = "08" // 商汤科技
	AuthChannelMegvii    AuthChannel = "09" // 旷世Face++
	AuthChannelJDCloud   AuthChannel = "10" // 京东智联云
	AuthChannelWechatPay AuthChannel = "11" // 微信支付
	AuthChannelOther     AuthChannel = "12" // 其他活体通道
)

Auth channel constants

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the ServiceShare API client.

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient creates a new ServiceShare API client.

func (*Client) Do

func (c *Client) Do(funCode *FunCode, reqData interface{}) (string, error)

Do executes an API request with encryption and signing. Returns decrypted response data as JSON string.

func (*Client) VerifyAndDecryptNotification

func (c *Client) VerifyAndDecryptNotification(body []byte) (string, error)

VerifyAndDecryptNotification verifies the signature and decrypts the notification data. It accepts the raw JSON body of the notification request.

type Config

type Config struct {
	BaseURL           string        //  the API endpoint URL
	MerchantID        string        // the merchant identifier assigned by the platform
	Version           string        // the API version (default: "V1.0")
	DesKey            string        // the DES encryption key (uses first 8 bytes)
	PrivateKey        string        // the merchant's RSA private key in PEM format
	PlatformPublicKey string        // the platform's RSA public key in PEM format
	Timeout           time.Duration // the HTTP request timeout (default: 60 seconds)
	TaskID            int64         // the task identifier for the request
}

Config holds the configuration for the ServiceShare API client.

func NewConfig

func NewConfig(baseURL, merchantID, desKey, privateKey, platformPublicKey string, taskID int64) *Config

NewConfig creates a new Config with default values.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

type FaceAuthState

type FaceAuthState string

FaceAuthState represents the face authentication state.

const (
	FaceAuthStateUnAuth  FaceAuthState = "UN_AUTH" // 未认证
	FaceAuthStateProcess FaceAuthState = "PROCESS" // 认证中
	FaceAuthStateSuccess FaceAuthState = "SUCCESS" // 认证成功
	FaceAuthStateFailed  FaceAuthState = "FAILED"  // 认证失败
	FaceAuthStateExpired FaceAuthState = "EXPIRED" // 认证过期
)

Face auth state constants

func (FaceAuthState) Desc

func (s FaceAuthState) Desc() string

type FunCode

type FunCode struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

type PaymentType

type PaymentType string

PaymentType represents the payment method type.

const (
	PaymentTypeBankCard PaymentType = "0" // bank card payment
	PaymentTypeAlipay   PaymentType = "1" // Alipay payment
	PaymentTypeWeChat   PaymentType = "2" // WeChat payment
)

Payment type constants

type RequestMessage

type RequestMessage struct {
	ReqId   string `json:"reqId"`   // Unique request identifier
	FunCode string `json:"funCode"` // Function/operation code
	MerId   string `json:"merId"`   // Merchant ID
	Version string `json:"version"` // API version
	ReqData string `json:"reqData"` // DES-encrypted business data (Hex)
	Sign    string `json:"sign"`    // RSA signature (Base64)
}

RequestMessage represents the API request envelope.

func (*RequestMessage) ToJSON

func (r *RequestMessage) ToJSON() ([]byte, error)

ToJSON marshals the RequestMessage to JSON.

type ResponseMessage

type ResponseMessage struct {
	ReqId   string `json:"reqId"`   // Echo of request identifier
	FunCode string `json:"funCode"` // Function/operation code
	MerId   string `json:"merId"`   // Merchant ID
	Version string `json:"version"` // API version
	ResData string `json:"resData"` // DES-encrypted response data (Hex)
	ResCode string `json:"resCode"` // Response code ("0000" = success)
	ResMsg  string `json:"resMsg"`  // Human-readable response message
	Sign    string `json:"sign"`    // RSA signature (Base64)
}

ResponseMessage represents the API response envelope.

func ParseResponseMessage

func ParseResponseMessage(data []byte) (*ResponseMessage, error)

ParseResponseMessage parses JSON into ResponseMessage.

func (*ResponseMessage) GetError

func (r *ResponseMessage) GetError() error

GetError returns an APIError if the response is not successful.

func (*ResponseMessage) IsSuccess

func (r *ResponseMessage) IsSuccess() bool

IsSuccess checks if the response indicates success.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL