Documentation ¶
Overview ¶
* 工行api请求
icbc签名文件
* 工行ui请求
常量文件
* rsa 处理程序
* 请求处理,参数处理,参数拼接
Index ¶
- Constants
- func AesDecrypt(data []byte, key []byte) ([]byte, error)
- func AesEncrypt(data []byte, key []byte) ([]byte, error)
- func BuildForm(url string, bodyParams map[string]interface{}) string
- func BuildGetUrl(serviceUrl string, urlQueryParams map[string]interface{}, charset string) string
- func BuildOrderedSignStr(path string, params map[string]interface{}, signStr *string)
- func DecryptByAes(data string, key string) ([]byte, error)
- func DoGet(serviceUrl string, params map[string]interface{}, charset string, ...) error
- func DoPost(serviceUrl string, params map[string]interface{}, charset string, ...) error
- func EncryptByAes(data []byte, PwdKey []byte) (string, error)
- func FormatPrivateKey(privateKey string) string
- func FormatPublicKey(pulicKey string) string
- func IsNil(i interface{}) bool
- func ParsePrivateKey(privateKey string) (*rsa.PrivateKey, error)
- func ParsePublicKey(pulicKey string) (*rsa.PublicKey, error)
- func RsaSign(signContent string, privateKey string, hash crypto.Hash) (string, error)
- func RsaVerifySign(signContent string, publicKey string, hash crypto.Hash, sign string) error
- func Sign(strToSign string, signType string, privateKey string, charset string, ...) error
- type IcbcClient
- type IcbcClientUi
Constants ¶
View Source
const ( SIGN_TYPE = "sign_type" SIGN_TYPE_RSA = "RSA" SIGN_TYPE_RSA2 = "RSA2" APP_ID = "app_id" CHARSET = "charset" FORMAT = "format" TIMESTAMP = "timestamp" SIGN = "sign" ENCRYPT_TYPE = "encrypt_type" BIZ_CONTENT_KEY = "biz_content" MSG_ID = "msg_id" PEM_BEGIN = "-----BEGIN PRIVATE KEY-----\n" PEM_END = "\n-----END PRIVATE KEY-----" PPEM_BEGIN = "-----BEGIN PUBLIC KEY-----\n" PPEM_END = "\n-----END PUBLIC KEY-----" EMPTY = "" )
Variables ¶
This section is empty.
Functions ¶
func AesDecrypt ¶ added in v1.4.5
AesDecrypt 解密
func AesEncrypt ¶ added in v1.4.5
AesEncrypt 加密
func BuildGetUrl ¶
build get url
func BuildOrderedSignStr ¶
* generete string before to sign
func DecryptByAes ¶ added in v1.4.5
DecryptByAes Aes 解密
func DoPost ¶
* post request
func DoPost(serviceUrl string,params map[string]interface{},charset string, resStr *string) error{ client := &http.Client{ Transport: &http.Transport{ Dial: func(netw, addr string) (net.Conn, error) { conn, err := net.DialTimeout(netw, addr, time.Second*1) //设置建立连接超时 if err != nil { return nil, err } conn.SetDeadline(time.Now().Add(time.Second * 30)) //设置发送接受数据超时 return conn, nil }, ResponseHeaderTimeout: time.Second * 30, }, } q := url.Values{} for k, v := range params { switch v.(type) { case string: q.Add(k, v.(string)) case int: q.Add(k, strconv.FormatInt(int64(v.(int)), 10)) case int64: q.Add(k, strconv.FormatInt(v.(int64), 10)) case float64: q.Add(k, strconv.FormatFloat(v.(float64), 'f', -1, 64)) case float32: q.Add(k, strconv.FormatFloat(float64(v.(float32)), 'f', -1, 64)) } } req, err := http.NewRequest(http.MethodPost, serviceUrl, strings.NewReader(q.Encode())) if err != nil { return err } // 添加请求头 req.Header.Add("content-type", "application/x-www-form-urlencoded;charset="+charset) req.Header.Add("APIGW-VERSION", "bg-go-v1") //加入get参数 resp, derr := client.Do(req) if derr != nil { return derr } if resp.StatusCode != 200 { return errors.New("response status code is not valid. status code:"+string(resp.StatusCode)) } defer resp.Body.Close() var buffer [512]byte result := bytes.NewBuffer(nil) for { n, err := resp.Body.Read(buffer[0:]) result.Write(buffer[0:n]) if err != nil && err == io.EOF { break } else if err != nil { return err } } *resStr = result.String() return nil }
func EncryptByAes ¶ added in v1.4.5
EncryptByAes Aes加密 后 base64 再加
func RsaVerifySign ¶
验签
Types ¶
type IcbcClient ¶
type IcbcClient struct {
// contains filtered or unexported fields
}
func (*IcbcClient) Execute ¶ added in v1.4.2
func (icbc *IcbcClient) Execute(request *map[string]interface{}, msgId string, auToken string) (string, error)
* 请求执行程序
func (*IcbcClient) New ¶
func (icbc *IcbcClient) New(appid string, privateKey string, signType string, charset string, format string, icbcPulicKey string, encryptKey string, encryptType string) error
* 初始化icbc对象
func (*IcbcClient) NotifyVerifySign ¶ added in v1.4.9
func (icbc *IcbcClient) NotifyVerifySign(request *url.Values, path string) error
type IcbcClientUi ¶
type IcbcClientUi struct {
// contains filtered or unexported fields
}
func (*IcbcClientUi) BuildPostForm ¶
func (icbc *IcbcClientUi) BuildPostForm(request map[string]interface{}, msgId string, appAuthToken string) (string, error)
* build url
Click to show internal directories.
Click to hide internal directories.