icbc_go

package module
v1.5.12 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

README

icbc go lib

封装的功能包括,自动加签,验签,加密,解密 aesutil.go:aes加解密文件 icbc_client_go.go:api请求文件 icbc_uiclient_go.go:ui请求文件 icbcSign.go :签名验签文件 myconst.go:常量文件 rsa.go:rsa相关文件 webUtils.go:请求相关

use mod config

require github.com/goodboycyt/icbc_go v1.4.4 or go get -u github.com/goodboycyt/icbc_client_go

useage

    var icbc IcbcClient
	icbc.New("1211111", "ddsad+sadsa+RMWK3Ci+sad+YaeH/Qm/r/Topq3lABw==","RSA","UTF-8","json","MIGfMA0GCSqGSIb3DQEBwIDAQAB","","")
	request_b := map[string]interface{}{"serviceUrl":"https://url","method":"POST","isNeedEncrypt":false,"extraParams":""}
	request_b["biz_content"] = map[string]interface{}{"corp_no":"123213","trx_acc_date":"2020-12-14"}
	resP,err :=icbc.execute(&request_b, "202012241521929252" , "")
	if err!=nil {
        fmt.printLn(err)
    }   


    var icbc IcbcClientUi
    icbc.New("11", "=","RSA","UTF-8","json","MIB","","")
    request_b := map[string]interface{}{"serviceUrl":"https://1.1.com.cn/ui/1/ui/1/1/1/V1","method":"POST","isNeedEncrypt":false,"extraParams":""}
    request_b["biz_content"] = map[string]interface{}{"121":"12121"}
    resP,err :=icbc.BuildPostForm(&request_b, "202012241521929252" , "")
    if err!=nil {
            fmt.printLn(err)
    } 

Documentation

Overview

* 工行api请求

icbc签名文件

* 工行ui请求

常量文件

* rsa 处理程序

* 请求处理,参数处理,参数拼接

Index

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

func AesDecrypt(data []byte, key []byte) ([]byte, error)

AesDecrypt 解密

func AesEncrypt added in v1.4.5

func AesEncrypt(data []byte, key []byte) ([]byte, error)

AesEncrypt 加密

func BuildForm

func BuildForm(url string, bodyParams map[string]interface{}) string

* build form

func BuildGetUrl

func BuildGetUrl(serviceUrl string, urlQueryParams map[string]interface{}, charset string) string

build get url

func BuildOrderedSignStr

func BuildOrderedSignStr(path string, params map[string]interface{}, signStr *string)

* generete string before to sign

func DecryptByAes added in v1.4.5

func DecryptByAes(data string, key string) ([]byte, error)

DecryptByAes Aes 解密

func DoGet

func DoGet(serviceUrl string, params map[string]interface{}, charset string, resStr *string) error

* get request

func DoPost

func DoPost(serviceUrl string, params map[string]interface{}, charset string, resStr *string) error

* 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

func EncryptByAes(data []byte, PwdKey []byte) (string, error)

EncryptByAes Aes加密 后 base64 再加

func FormatPrivateKey

func FormatPrivateKey(privateKey string) string

私钥格式化

func FormatPublicKey

func FormatPublicKey(pulicKey string) string

公钥格式化

func IsNil added in v1.4.9

func IsNil(i interface{}) bool

func ParsePrivateKey

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

私钥转换

func ParsePublicKey

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

公钥转换

func RsaSign

func RsaSign(signContent string, privateKey string, hash crypto.Hash) (string, error)

加签

func RsaVerifySign

func RsaVerifySign(signContent string, publicKey string, hash crypto.Hash, sign string) error

验签

func Sign

func Sign(strToSign string, signType string, privateKey string, charset string, signStr *string) error

签名

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

func (*IcbcClientUi) New

func (icbc *IcbcClientUi) New(appid string, privateKey string, signType string, charset string, format string, icbcPulicKey string, encryptKey string, encryptType string) error

* 初始化icbc对象

Jump to

Keyboard shortcuts

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