mcommon

package module
v0.1.156 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 56 Imported by: 0

README

mcommon

build blog

目录

背景

开发过程中用到的一些通用的golang函数

  • log.go 日志
  • mysql.go mysql操作

使用说明

go get github.com/Custody-Mongolia/wallet-service/mcommon

维护者

@moremorefun 那些年我们De过的Bug

使用许可

MIT © moremorefun

Documentation

Index

Constants

View Source
const (
	// ErrorSuccess 成功
	ErrorSuccess = 0
	// ErrorSuccessMsg 成功
	ErrorSuccessMsg = "success"

	// ErrorInternal 内部错误
	ErrorInternal = -1
	// ErrorInternalMsg 内部错误
	ErrorInternalMsg = "internal"

	// ErrorBind 输入绑定错误
	ErrorBind = -2
	// ErrorBindMsg 输入绑定错误
	ErrorBindMsg = "input bind"

	ErrorToken    = -1000
	ErrorTokenMsg = "token error"
)

错误码

View Source
const (
	Kuaidi100StateOnTheWay       = 0
	Kuaidi100StateCollect        = 1
	Kuaidi100StateDifficult      = 2
	Kuaidi100StateSignFor        = 3
	Kuaidi100StateReturnSignFor  = 4
	Kuaidi100StateDispatch       = 5
	Kuaidi100StateReturnOnTheWay = 6
	Kuaidi100StateSwitching      = 7
	Kuaidi100StateToBeCleared    = 10
	Kuaidi100StateClearing       = 11
	Kuaidi100StateCleared        = 12
	Kuaidi100StateClearError     = 13
	Kuaidi100StateReject         = 14
)

0 在途 快件处于运输过程中 1 揽收 快件已由快递公司揽收 2 疑难 快递100无法解析的状态,或者是需要人工介入的状态, 比方说收件人电话错误。 3 签收 正常签收 4 退签 货物退回发货人并签收 5 派件 货物正在进行派件 6 退回 货物正处于返回发货人的途中 7 转投 货物转给其他快递公司邮寄 10 待清关 货物等待清关 11 清关中 货物正在清关流程中 12 已清关 货物已完成清关流程 13 清关异常 货物在清关过程中出现异常 14 拒签 收件人明确拒收

View Source
const (
	MySqlGoTypeString  = 1
	MySqlGoTypeInt64   = 2
	MySqlGoTypeBytes   = 3
	MySqlGoTypeFloat64 = 4
	MySqlGoTypeTime    = 5
)

数据库数据类型

View Source
const (
	QueryJoinTypeInner = 1
)

join类型

Variables

View Source
var GinRespInternalErr = GinResp{
	ErrCode: ErrorInternal,
	ErrMsg:  ErrorInternalMsg,
}

GinRespInternalErr 成功返回

View Source
var GinRespSuccess = GinResp{
	ErrCode: ErrorSuccess,
	ErrMsg:  ErrorSuccessMsg,
}

GinRespSuccess 成功返回

View Source
var MysqlTypeToGoMap = map[string]int64{
	"BIT":        1,
	"TEXT":       1,
	"BLOB":       3,
	"DATETIME":   5,
	"DOUBLE":     4,
	"ENUM":       1,
	"FLOAT":      4,
	"GEOMETRY":   1,
	"MEDIUMINT":  2,
	"JSON":       1,
	"INT":        2,
	"LONGTEXT":   1,
	"LONGBLOB":   3,
	"BIGINT":     2,
	"MEDIUMTEXT": 1,
	"MEDIUMBLOB": 3,
	"DATE":       5,
	"DECIMAL":    1,
	"SET":        1,
	"SMALLINT":   2,
	"BINARY":     3,
	"CHAR":       1,
	"TIME":       5,
	"TIMESTAMP":  5,
	"TINYINT":    2,
	"TINYTEXT":   1,
	"TINYBLOB":   3,
	"VARBINARY":  3,
	"VARCHAR":    1,
	"YEAR":       2,
}

MysqlTypeToGoMap 类型转换关系

View Source
var ZapLog *zap.Logger

ZapLog zap日志对象

Functions

func AesDecrypt

func AesDecrypt(cryted string, key string) (string, error)

AesDecrypt aes解密

func AesEncrypt

func AesEncrypt(orig string, key string) (string, error)

AesEncrypt 加密

func DbCreate

func DbCreate(dataSourceName string, showSQL bool) *sqlx.DB

DbCreate 创建数据库链接

func DbDeleteKV

func DbDeleteKV(ctx context.Context, tx DbExeAble, table string, keys []string, values []interface{}) (int64, error)

DbDeleteKV 删除

func DbExecuteCountManyContent

func DbExecuteCountManyContent(ctx context.Context, tx DbExeAble, query string, n int, args ...interface{}) (int64, error)

DbExecuteCountManyContent 返回sql语句并返回执行行数

func DbExecuteCountNamedContent

func DbExecuteCountNamedContent(ctx context.Context, tx DbExeAble, query string, argMap map[string]interface{}) (int64, error)

DbExecuteCountNamedContent 执行sql语句返回执行个数

func DbExecuteLastIDNamedContent

func DbExecuteLastIDNamedContent(ctx context.Context, tx DbExeAble, query string, argMap map[string]interface{}) (int64, error)

DbExecuteLastIDNamedContent 执行sql语句并返回lastID

func DbGetNamedContent

func DbGetNamedContent(ctx context.Context, tx DbExeAble, dest interface{}, query string, argMap map[string]interface{}) (bool, error)

DbGetNamedContent 执行sql查询并返回当个元素

func DbNamedRowsContent

func DbNamedRowsContent(ctx context.Context, tx DbExeAble, query string, argMap map[string]interface{}) ([]gin.H, error)

DbNamedRowsContent 执行sql查询并返回多行

func DbSelectNamedContent

func DbSelectNamedContent(ctx context.Context, tx DbExeAble, dest interface{}, query string, argMap map[string]interface{}) error

DbSelectNamedContent 执行sql查询并返回多行

func DbSetShowSQL

func DbSetShowSQL(b bool)

DbSetShowSQL 设置是否显示sql

func DbStructGetDiff

func DbStructGetDiff(tx DbExeAble, tableNames []string, sqlFilePath string) (string, error)

DbStructGetDiff 获取数据库更新指令

func DbTransaction

func DbTransaction(ctx context.Context, db *sqlx.DB, f func(dbTx DbExeAble) error) error

DbTransaction 执行事物

func DbUpdateKV

func DbUpdateKV(ctx context.Context, tx DbExeAble, table string, updateMap H, keys []string, values []interface{}) (int64, error)

DbUpdateKV 更新

func DecodeHashID

func DecodeHashID(salt string, minLen int, value string) (int, error)

DecodeHashID 解析hash id

func DecodeHashIDs

func DecodeHashIDs(salt string, minLen int, value string) ([]int, error)

DecodeHashIDs 解析hash id

func DecryptAesEcb

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

DecryptAesEcb aes ecb 解密

func EncodeHashID

func EncodeHashID(salt string, minLen, id int) (string, error)

EncodeHashID 获取hash id

func EncodeHashIDs

func EncodeHashIDs(salt string, minLen int, ids []int) (string, error)

EncodeHashIDs 获取hash id

func GetHash

func GetHash(in string) (string, error)

GetHash 获取hash

func GetStringSize

func GetStringSize(str string, fontPath string, fontSize float64, dpi float64) (fixed.Rectangle26_6, fixed.Int26_6, error)

GetStringSize 获取制定字体文字大小

func GetUUIDStr

func GetUUIDStr() string

GetUUIDStr 获取唯一字符串

func GetWriteLinesWidthFont

func GetWriteLinesWidthFont(content string, fontSize float64, width int, fontPath string) ([]string, error)

GetWriteLinesWidthFont 获取行数

func GetWriteSizeFont

func GetWriteSizeFont(content string, fontSize float64, fontPath string) (int, int, error)

GetWriteSizeFont 获取指定字体的文字大小

func GinBodyRepeat

func GinBodyRepeat(r io.Reader) (io.ReadCloser, error)

func GinCors

func GinCors() gin.HandlerFunc

func GinDoEncRespSuccess

func GinDoEncRespSuccess(c *gin.Context, key string, isAll bool, data gin.H)

GinDoEncRespSuccess 返回成功信息

func GinDoRespErr

func GinDoRespErr(c *gin.Context, code int64, msg string, data gin.H)

GinDoRespErr 返回特殊错误

func GinDoRespInternalErr

func GinDoRespInternalErr(c *gin.Context)

GinDoRespInternalErr 返回错误信息

func GinDoRespSuccess

func GinDoRespSuccess(c *gin.Context, data gin.H)

GinDoRespSuccess 返回成功信息

func GinFillBindError

func GinFillBindError(c *gin.Context, err error)

GinFillBindError 检测gin输入绑定错误

func GinMidRepeatReadBody

func GinMidRepeatReadBody(c *gin.Context)

GinMidRepeatReadBody 创建可重复度body

func GinMinTokenToUserID

func GinMinTokenToUserID(tx DbExeAble, getUserIDByToken func(ctx context.Context, tx DbExeAble, token string) (int64, error)) func(*gin.Context)

GinMinTokenToUserID token转换为user_id

func GinMinTokenToUserIDRedis

func GinMinTokenToUserIDRedis(tx DbExeAble, redisClient *redis.Client, getUserIDByToken func(ctx context.Context, tx DbExeAble, redisClient *redis.Client, token string) (int64, error)) func(*gin.Context)

GinMinTokenToUserIDRedis token转换为user_id

func GinMinTokenToUserIDRedisIgnore

func GinMinTokenToUserIDRedisIgnore(tx DbExeAble, redisClient *redis.Client, getUserIDByToken func(ctx context.Context, tx DbExeAble, redisClient *redis.Client, token string) (int64, error)) func(*gin.Context)

GinMinTokenToUserIDRedisIgnore token转换为user_id

func IP2long

func IP2long(ipAddr string) (uint32, error)

IP2long 转换ip

func IntArrToString

func IntArrToString(A []int64, denim string) string

IntArrToString 数组转换

func IsInSlice

func IsInSlice(arr []interface{}, iv interface{}) bool

IsInSlice 数字是否在数组中

func IsIntInSlice

func IsIntInSlice(arr []int64, str int64) bool

IsIntInSlice 数字是否在数组中

func IsStringInSlice

func IsStringInSlice(arr []string, str string) bool

IsStringInSlice 字符串是否在数组中

func LogSetLevel

func LogSetLevel(level zapcore.Level) error

LogSetLevel 设置日志等级

func LogSetToProd

func LogSetToProd() error

LogSetToProd 设置为生产环境

func ModelRowInterfaceToStruct

func ModelRowInterfaceToStruct(m map[string]interface{}, v interface{}) error

ModelRowInterfaceToStruct 填充结构体

func ModelRowToInterface

func ModelRowToInterface(m map[string]string, intCols []string, floatCols []string) (map[string]interface{}, error)

ModelRowToInterface 填充结构体

func ModelRowToStruct

func ModelRowToStruct(m map[string]string, v interface{}) error

ModelRowToStruct 填充结构体

func ModelRowsInterfaceToStruct

func ModelRowsInterfaceToStruct(rows []map[string]interface{}, v interface{}) error

ModelRowsInterfaceToStruct 填充结构体

func ModelRowsToInterface

func ModelRowsToInterface(ms []map[string]string, intCols []string, floatCols []string) ([]map[string]interface{}, error)

ModelRowsToInterface 填充结构体

func ModelRowsToStruct

func ModelRowsToStruct(rows []map[string]string, v interface{}) error

ModelRowsToStruct 填充结构体

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blocksize int) []byte

PKCS7Padding 补码

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding 去码

func QiniuGetDownloadURL

func QiniuGetDownloadURL(ctx context.Context, access string, secret string, domain string, fileKey string, deadline int64) string

QiniuGetDownloadURL 获取私有下载链接

func QiniuTokenFrom

func QiniuTokenFrom(ctx context.Context, access string, secret string, bucket string) string

QiniuTokenFrom 获取上传token

func QiniuUploadImg

func QiniuUploadImg(ctx context.Context, access string, secret string, bucket string, fileKey string, img image.Image) error

QiniuUploadImg 上传到qiniu

func QueryDelete

func QueryDelete(table string) *deleteData

QueryDelete 创建删除

func QueryInsert

func QueryInsert(into string) *insertData

QueryInsert 创建搜索

func QueryJoin

func QueryJoin(joinType int64, obj string) *joinData

QueryJoin 链接

func QuerySelect

func QuerySelect(columns ...QueryMaker) *selectData

QuerySelect 创建搜索

func QueryUpdate

func QueryUpdate(table string) *updateData

QueryUpdate 创建更新

func RedisCreate

func RedisCreate(address string, password string, dbIndex int) *redis.Client

RedisCreate 创建数据库

func RedisGet

func RedisGet(ctx context.Context, client *redis.Client, key string) (string, error)

RedisGet 获取

func RedisRm

func RedisRm(ctx context.Context, client *redis.Client, key string) error

RedisRm 删除

func RedisSet

func RedisSet(ctx context.Context, client *redis.Client, key, value string, du time.Duration) error

RedisSet 设置

func RedisSetBaseKey

func RedisSetBaseKey(v string)

RedisSetBaseKey 设置基础key

func RsaSign

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

RsaSign 签名

func SQLRedisGetWxToken

func SQLRedisGetWxToken(c context.Context, tx DbExeAble, redisClient *redis.Client, appID string,
	funcSQLGetToken func(context.Context, DbExeAble, string) (string, string, int64, error),
	funcSQLSetToken func(context.Context, DbExeAble, string, string, string, int64) error,
) (string, error)

SQLRedisGetWxToken 获取小程序token

func SQLRedisRestWxToken

func SQLRedisRestWxToken(c context.Context, tx DbExeAble, redisClient *redis.Client, appID string,
	funcSQLResetToken func(context.Context, DbExeAble, string) error,
)

SQLRedisRestWxToken 重置小程序token

func TencenSms

func TencenSms(sdkID, sdkKey, appID, sign, templateID string, tels []string, templateParam []string) error

TencenSms 发送短信

func TimeGetMillisecond

func TimeGetMillisecond() int64

TimeGetMillisecond 获取毫秒

func UploadToQiniu

func UploadToQiniu(ctx context.Context, access string, secret string, zone *storage.Zone, bucket string, fileKey string, bs []byte) error

UploadToQiniu 上传到qiniu

func WechatCheckSign

func WechatCheckSign(appSecret string, paramsMap gin.H) bool

WechatCheckSign 检查签名

func WechatGetPrepay

func WechatGetPrepay(appID, mchID, mchKey, payBody, outTradeNo, clientIP, cbURL, tradeType, openID string, timeExpire, totalFee int64) (gin.H, error)

WechatGetPrepay 获取预支付信息

func WechatGetSign

func WechatGetSign(appSecret string, paramsMap gin.H) string

WechatGetSign 获取签名

func WriteOnImageFont

func WriteOnImageFont(target *image.NRGBA, content string, fontSize float64, x int, y int, color color.RGBA, fontPath string) error

WriteOnImageFont 根据指定字体写入图片

func WriteOnImageLinesFontWithGap

func WriteOnImageLinesFontWithGap(target *image.NRGBA, lines []string, fontSize float64, x int, y int, color color.RGBA, fontPath string, gap float64) error

WriteOnImageLinesFontWithGap 写入多行文字到图片

func WxPayV3CheckSign

func WxPayV3CheckSign(header map[string][]string, body []byte, cerStr string) error

WxPayV3CheckSign v3签名验证

func WxPayV3Decrype

func WxPayV3Decrype(key string, cipherStr, nonce, associatedData string) (string, error)

WxPayV3Decrype 解密

func WxPayV3GetHeaderByKey

func WxPayV3GetHeaderByKey(header map[string][]string, key string) (string, error)

WxPayV3GetHeaderByKey 获取头

func WxPayV3GetPrepay

func WxPayV3GetPrepay(keySerial string, key *rsa.PrivateKey, appID, mchID, openID, payBody, outTradeNo, cbURL string, totalFee int64, expireAt time.Time) (gin.H, string, error)

WxPayV3GetPrepay 获取预支付信息

func WxPayV3Sign

func WxPayV3Sign(mchid, keySerial string, key *rsa.PrivateKey, req *gorequest.SuperAgent) (*gorequest.SuperAgent, error)

WxPayV3Sign v3签名

func WxPayV3SignPrepayid

func WxPayV3SignPrepayid(key *rsa.PrivateKey, appID, prepayid string) (gin.H, error)

WxPayV3SignPrepayid 签名prepayid

func WxPayV3SignStr

func WxPayV3SignStr(key *rsa.PrivateKey, cols []string) (string, error)

WxPayV3SignStr 获取签名结果

func XMLWalk

func XMLWalk(bs []byte) (map[string]interface{}, error)

XMLWalk 遍历xml

Types

type DbExeAble

type DbExeAble interface {
	Rebind(string) string
	Get(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	Select(dest interface{}, query string, args ...interface{}) error
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

	QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
}

DbExeAble 数据库接口

type GinResp

type GinResp struct {
	ErrCode int64  `json:"error"`
	ErrMsg  string `json:"error_msg"`
	Data    gin.H  `json:"data,omitempty"`
}

GinResp 通用返回

func GinFillSuccessData

func GinFillSuccessData(data gin.H) GinResp

GinFillSuccessData 填充返回数据

type H

type H map[string]interface{}

H 通用map

type LoggerAble

type LoggerAble interface {
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})
}

LoggerAble 日志对象接口

var Log LoggerAble

Log 对外服务的日志对象

type QueryAs

type QueryAs QueryKvStr

QueryAs k AS v

func (QueryAs) ToSQL

func (o QueryAs) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryAsc

type QueryAsc string

QueryAsc k ASC

func (QueryAsc) ToSQL

func (o QueryAsc) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryColumn

type QueryColumn string

QueryColumn 查询字段

func (QueryColumn) ToSQL

func (o QueryColumn) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryDesc

type QueryDesc string

QueryDesc k DESC

func (QueryDesc) ToSQL

func (o QueryDesc) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryDuplicateValue

type QueryDuplicateValue string

QueryDuplicateValue k=VALUES(k)

func (QueryDuplicateValue) ToSQL

func (o QueryDuplicateValue) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryEq

type QueryEq QueryKv

QueryEq k=:k

func (QueryEq) ToSQL

func (o QueryEq) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryEqRaw

type QueryEqRaw QueryKvStr

QueryEqRaw k=v

func (QueryEqRaw) ToSQL

func (o QueryEqRaw) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryGt

type QueryGt QueryKv

QueryGt k>:k

func (QueryGt) ToSQL

func (o QueryGt) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryKv

type QueryKv struct {
	K string
	V interface{}
}

QueryKv kv结构

type QueryKvStr

type QueryKvStr struct {
	K string
	V string
}

QueryKvStr kv字符串

type QueryLt

type QueryLt QueryKv

QueryLt k<:k

func (QueryLt) ToSQL

func (o QueryLt) ToSQL() ([]byte, map[string]interface{}, error)

ToSQL 生成语句和参数

type QueryMaker

type QueryMaker interface {
	ToSQL() ([]byte, map[string]interface{}, error)
}

QueryMaker sql语句生成接口

type StKuaidi100CbBody

type StKuaidi100CbBody struct {
	Message    string `json:"message"`
	ComOld     string `json:"comOld"`
	Status     string `json:"status"`
	LastResult struct {
		Nu        string `json:"nu"`
		Message   string `json:"message"`
		Ischeck   string `json:"ischeck"`
		Com       string `json:"com"`
		Condition string `json:"condition"`
		Status    string `json:"status"`
		State     string `json:"state"`
		Data      []struct {
			Time     string `json:"time"`
			AreaName string `json:"areaName,omitempty"`
			Status   string `json:"status"`
			AreaCode string `json:"areaCode,omitempty"`
			Context  string `json:"context"`
			Ftime    string `json:"ftime"`
		} `json:"data"`
	} `json:"lastResult"`
	ComNew     string `json:"comNew"`
	Billstatus string `json:"billstatus"`
	AutoCheck  string `json:"autoCheck"`
}

StKuaidi100CbBody 回调

type StKuaidi100GetResp

type StKuaidi100GetResp struct {
	Message string `json:"message"`
	Nu      string `json:"nu"`
	Ischeck string `json:"ischeck"`
	Com     string `json:"com"`
	Status  string `json:"status"`
	Data    []struct {
		Time     string `json:"time"`
		Context  string `json:"context"`
		Ftime    string `json:"ftime"`
		AreaCode string `json:"areaCode"`
		AreaName string `json:"areaName"`
		Status   string `json:"status"`
	} `json:"data"`
	State     string `json:"state"`
	Condition string `json:"condition"`
	RouteInfo struct {
		From struct {
			Number string `json:"number"`
			Name   string `json:"name"`
		} `json:"from"`
		Cur struct {
			Number string `json:"number"`
			Name   string `json:"name"`
		} `json:"cur"`
		To struct {
			Number string `json:"number"`
			Name   string `json:"name"`
		} `json:"to"`
	} `json:"routeInfo"`
	IsLoop bool `json:"isLoop"`
}

StKuaidi100GetResp 获取

func Kuaidi100Query

func Kuaidi100Query(customer, key, company, number, tel string) (*StKuaidi100GetResp, error)

Kuaidi100Query 获取快递信息

type StKuaidi100PollResp

type StKuaidi100PollResp struct {
	Result     bool   `json:"result"`
	ReturnCode string `json:"returnCode"`
	Message    string `json:"message"`
}

StKuaidi100PollResp 推送

func Kuaidi100Poll

func Kuaidi100Poll(key, company, number, tel, callbackurl string) (*StKuaidi100PollResp, error)

Kuaidi100Poll 订阅邮件推送

type StRefundRespXML

type StRefundRespXML struct {
	XMLName           xml.Name `xml:"xml"`
	Text              string   `xml:",chardata"`
	ReturnCode        string   `xml:"return_code"`
	ReturnMsg         string   `xml:"return_msg"`
	Appid             string   `xml:"appid"`
	MchID             string   `xml:"mch_id"`
	NonceStr          string   `xml:"nonce_str"`
	Sign              string   `xml:"sign"`
	ResultCode        string   `xml:"result_code"`
	TransactionID     string   `xml:"transaction_id"`
	OutTradeNo        string   `xml:"out_trade_no"`
	OutRefundNo       string   `xml:"out_refund_no"`
	RefundID          string   `xml:"refund_id"`
	RefundChannel     string   `xml:"refund_channel"`
	RefundFee         int64    `xml:"refund_fee"`
	CouponRefundFee   int64    `xml:"coupon_refund_fee"`
	TotalFee          int64    `xml:"total_fee"`
	CashFee           int64    `xml:"cash_fee"`
	CouponRefundCount int64    `xml:"coupon_refund_count"`
	CashRefundFee     int64    `xml:"cash_refund_fee"`
}

StRefundRespXML 回复内容

func WechatRefund

func WechatRefund(cer tls.Certificate, appID, mchID, mchKey, transactionID, outRefundNo, cbURL string, totalFee, refundFee int64) (*StRefundRespXML, error)

WechatRefund 申请退款

type StWeChatCbBody

type StWeChatCbBody struct {
	XMLName       xml.Name `xml:"xml"`
	Text          string   `xml:",chardata"`
	Appid         string   `xml:"appid"`
	Attach        string   `xml:"attach"`
	BankType      string   `xml:"bank_type"`
	FeeType       string   `xml:"fee_type"`
	IsSubscribe   string   `xml:"is_subscribe"`
	MchID         string   `xml:"mch_id"`
	NonceStr      string   `xml:"nonce_str"`
	Openid        string   `xml:"openid"`
	OutTradeNo    string   `xml:"out_trade_no"`
	ResultCode    string   `xml:"result_code"`
	ReturnCode    string   `xml:"return_code"`
	Sign          string   `xml:"sign"`
	TimeEnd       string   `xml:"time_end"`
	TotalFee      string   `xml:"total_fee"`
	CouponFee     string   `xml:"coupon_fee"`
	CouponCount   string   `xml:"coupon_count"`
	CouponType    string   `xml:"coupon_type"`
	CouponID      string   `xml:"coupon_id"`
	TradeType     string   `xml:"trade_type"`
	TransactionID string   `xml:"transaction_id"`
}

StWeChatCbBody 回调信息

func WechatCheckCb

func WechatCheckCb(mchKey string, body []byte) (*StWeChatCbBody, error)

WechatCheckCb 验证回调

type StWxPayRawResp

type StWxPayRawResp struct {
	ID           string    `json:"id"`
	CreateTime   time.Time `json:"create_time"`
	ResourceType string    `json:"resource_type"`
	EventType    string    `json:"event_type"`
	Summary      string    `json:"summary"`
	Resource     struct {
		OriginalType   string `json:"original_type"`
		Algorithm      string `json:"algorithm"`
		Ciphertext     string `json:"ciphertext"`
		AssociatedData string `json:"associated_data"`
		Nonce          string `json:"nonce"`
	} `json:"resource"`
}

StWxPayRawResp 回复

type StWxPayResp

type StWxPayResp struct {
	Mchid          string    `json:"mchid"`
	Appid          string    `json:"appid"`
	OutTradeNo     string    `json:"out_trade_no"`
	TransactionID  string    `json:"transaction_id"`
	TradeType      string    `json:"trade_type"`
	TradeState     string    `json:"trade_state"`
	TradeStateDesc string    `json:"trade_state_desc"`
	BankType       string    `json:"bank_type"`
	Attach         string    `json:"attach"`
	SuccessTime    time.Time `json:"success_time"`
	Payer          struct {
		Openid string `json:"openid"`
	} `json:"payer"`
	Amount struct {
		Total         int    `json:"total"`
		PayerTotal    int    `json:"payer_total"`
		Currency      string `json:"currency"`
		PayerCurrency string `json:"payer_currency"`
	} `json:"amount"`
}

StWxPayResp 回复

func WxPayV3DecodePayResp

func WxPayV3DecodePayResp(v3Key string, body []byte, mchid, appid string) (*StWxPayResp, error)

WxPayV3DecodePayResp 解析支付回调

type StWxRefundCb

type StWxRefundCb struct {
	XMLName             xml.Name `xml:"root"`
	Text                string   `xml:",chardata"`
	OutRefundNo         string   `xml:"out_refund_no"`
	OutTradeNo          string   `xml:"out_trade_no"`
	RefundAccount       string   `xml:"refund_account"`
	RefundFee           string   `xml:"refund_fee"`
	RefundID            string   `xml:"refund_id"`
	RefundRecvAccout    string   `xml:"refund_recv_accout"`
	RefundRequestSource string   `xml:"refund_request_source"`
	RefundStatus        string   `xml:"refund_status"`
	SettlementRefundFee string   `xml:"settlement_refund_fee"`
	SettlementTotalFee  string   `xml:"settlement_total_fee"`
	SuccessTime         string   `xml:"success_time"`
	TotalFee            string   `xml:"total_fee"`
	TransactionID       string   `xml:"transaction_id"`
}

StWxRefundCb 回调

func WxPayCheckRefundCb

func WxPayCheckRefundCb(mchKey string, body []byte) (*StWxRefundCb, error)

WxPayCheckRefundCb 验证回调

type StWxV3RefundCb

type StWxV3RefundCb struct {
	ID           string    `json:"id"`
	CreateTime   time.Time `json:"create_time"`
	ResourceType string    `json:"resource_type"`
	EventType    string    `json:"event_type"`
	Summary      string    `json:"summary"`
	Resource     struct {
		OriginalType   string `json:"original_type"`
		Algorithm      string `json:"algorithm"`
		Ciphertext     string `json:"ciphertext"`
		AssociatedData string `json:"associated_data"`
		Nonce          string `json:"nonce"`
	} `json:"resource"`
}

type StWxV3RefundCbContent

type StWxV3RefundCbContent struct {
	Mchid         string    `json:"mchid"`
	OutTradeNo    string    `json:"out_trade_no"`
	TransactionID string    `json:"transaction_id"`
	OutRefundNo   string    `json:"out_refund_no"`
	RefundID      string    `json:"refund_id"`
	RefundStatus  string    `json:"refund_status"`
	SuccessTime   time.Time `json:"success_time"`
	Amount        struct {
		Total       int `json:"total"`
		Refund      int `json:"refund"`
		PayerTotal  int `json:"payer_total"`
		PayerRefund int `json:"payer_refund"`
	} `json:"amount"`
	UserReceivedAccount string `json:"user_received_account"`
}

func WxPayV3DecodeRefundsCb

func WxPayV3DecodeRefundsCb(v3Key string, body []byte) (*StWxV3RefundCbContent, error)

WxPayV3DecodeRefundsCb 解析退款回调

type StWxV3RefundResp

type StWxV3RefundResp struct {
	Amount struct {
		Currency         string `json:"currency"`
		DiscountRefund   int    `json:"discount_refund"`
		PayerRefund      int    `json:"payer_refund"`
		PayerTotal       int    `json:"payer_total"`
		Refund           int    `json:"refund"`
		SettlementRefund int    `json:"settlement_refund"`
		SettlementTotal  int    `json:"settlement_total"`
		Total            int    `json:"total"`
	} `json:"amount"`
	Channel             string        `json:"channel"`
	CreateTime          time.Time     `json:"create_time"`
	FundsAccount        string        `json:"funds_account"`
	OutRefundNo         string        `json:"out_refund_no"`
	OutTradeNo          string        `json:"out_trade_no"`
	PromotionDetail     []interface{} `json:"promotion_detail"`
	RefundID            string        `json:"refund_id"`
	Status              string        `json:"status"`
	TransactionID       string        `json:"transaction_id"`
	UserReceivedAccount string        `json:"user_received_account"`
	Code                string        `json:"code"`
	Message             string        `json:"message"`
}

func WxPayV3Refunds

func WxPayV3Refunds(keySerial string, key *rsa.PrivateKey, mchID, transactionID, outRefundNo, cbURL string, totalFee, refundFee int64) (*StWxV3RefundResp, error)

WxPayV3Refunds 退款

type WxAppCodeResp

type WxAppCodeResp struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	Openid       string `json:"openid"`
	Scope        string `json:"scope"`
	ErrCode      int64  `json:"errcode"`
}

WxAppCodeResp jscode回复

func WxAppCode

func WxAppCode(appID, appSecret, code string) (*WxAppCodeResp, error)

WxAppCode app登录

type WxAppUserInfoResp

type WxAppUserInfoResp struct {
	Openid     string `json:"openid"`
	Nickname   string `json:"nickname"`
	Sex        int64  `json:"sex"`
	Province   string `json:"province"`
	City       string `json:"city"`
	Country    string `json:"country"`
	Headimgurl string `json:"headimgurl"`
	Unionid    string `json:"unionid"`
	ErrCode    int64  `json:"errcode"`
}

WxAppUserInfoResp userinfo回复

func WxAppUserInfo

func WxAppUserInfo(accessToken, openID string) (*WxAppUserInfoResp, error)

WxAppUserInfo 用户信息

type WxJsCodeResp

type WxJsCodeResp struct {
	OpenID     string `json:"openid"`
	SessionKey string `json:"session_key"`
	Unionid    string `json:"unionid"`
	Errcode    int64  `json:"errcode"`
	Errmsg     string `json:"errmsg"`
}

WxJsCodeResp jscode回复

func WxJsCode

func WxJsCode(appID, appSecret, code string) (*WxJsCodeResp, error)

WxJsCode js登录

type XMLNode

type XMLNode struct {
	XMLName xml.Name
	Content string    `xml:",chardata"`
	Nodes   []XMLNode `xml:",any"`
}

XMLNode xml结构

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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