qqenvelop

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 7 Imported by: 0

README

qqenvelop-qq红包

Build Status Go Report Card codecov

开发者中心

引入方式

go get github.com/birjemin/qqenvelop

接口列表

使用方式


cert, err := tls.LoadX509KeyPair("client.crt", "client.key")
if err != nil {
    panic(err)
}

cTLS := &utils.HTTPClient{
    Client: &http.Client{
        Timeout: 5 * time.Second,
        Transport: &http.Transport{
            TLSClientConfig: &tls.Config{
                Certificates: []tls.Certificate{
                    cert,
                },
            },
        },
    },
}

// 发送红包
sendObj := SendQPayHb{
    MchID:       "商户号",
    MchName:     "商户名称",
    AppSecret:   "app_secret",
    HTTPRequest: cTLS,
}

params := ParamsSendQPayHb{
    TotalAmount: 1,
    Wishing:     "新年好",
    ActName:     "新年活动",
    IconID:      23,
}

// success
ret, err := sendObj.SendQPayHb("open_id", params)
if err != nil {
    panic(err)
}
log.Print("ret: ", ret)

// 查看详情
c := &utils.HTTPClient{
    Client: &http.Client{
        Timeout: 5 * time.Second,
    },
}

obj := QPayHbDetail{
    MchID:       "mch_id",
    AppSecret:   "app_secret",
    HTTPRequest: c,
}

params := ParamsQPayHbDetail{
    ListID: "101000000502201506300000100001",
}

// success
ret, err := obj.GetDetail(params)
if err != nil {
    panic(err)
}
log.Print("ret: ", ret)

// 获取下载链接URL(使用cTLS,或者自定义下载即可)
notify := DownloadQPayHb{
    AppSecret: "app_secret",
}

downloadURL := notify.GetDownloadURL(20210109)

// 处理回调校验
ret, err := notify.Parse(data)
if err != nil {
    panic(err.Error())
}
check := notify.CheckSign(ret)
log.Print("ret: ", check, ret)

测试

  • 测试
    go test
    
  • 格式化代码
    golint
    
  • 覆盖率
    go test -cover
    go test -coverprofile=coverage.out 
    go tool cover -html=coverage.out
    

备注

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DownloadQPayHb added in v1.2.0

type DownloadQPayHb struct {
	MchID     string
	AppSecret string
}

DownloadQPayHb notify

func (*DownloadQPayHb) GetDownloadURL added in v1.2.0

func (d *DownloadQPayHb) GetDownloadURL(date int) string

GetDownloadURL get download's url

func (*DownloadQPayHb) GetParams added in v1.2.0

func (d *DownloadQPayHb) GetParams(date int) map[string]string

GetParams params

type NotifyQPayHb

type NotifyQPayHb struct {
	AppSecret string
}

NotifyQPayHb notify

func (*NotifyQPayHb) CheckSign added in v1.2.0

func (n *NotifyQPayHb) CheckSign(params *ParseNotify) bool

CheckSign check sign

func (*NotifyQPayHb) Parse

func (n *NotifyQPayHb) Parse(b []byte) (*ParseNotify, error)

Parse parse notify params

func (*NotifyQPayHb) Response

func (n *NotifyQPayHb) Response(code, msg string) string

Response response

type ParamsQPayHbDetail added in v1.2.0

type ParamsQPayHbDetail struct {
	ListID    string
	SendType  int    // default 0
	SubMchID  string // default empty
	MchBillNo string // default empty
}

ParamsQPayHbDetail params of envelop

type ParamsSendQPayHb

type ParamsSendQPayHb struct {
	TotalAmount int
	Wishing     string
	ActName     string
	IconID      int
	TotalNum    int // default 1
	BannerID    int // default empty
	NotSendMsg  int // default 0
	MinValue    int // default TotalAmount
	MaxValue    int // default TotalAmount
}

ParamsSendQPayHb params of envelop

type ParseNotify

type ParseNotify struct {
	AppID         string `xml:"appid"`
	MchID         string `xml:"mch_id"`
	OutTradeNo    string `xml:"out_trade_no"`
	TransactionID string `xml:"transaction_id"`
	OpenID        string `xml:"openid"`
	TotalFee      int    `xml:"total_fee"`
	ListID        string `xml:"listid"`
	RecvUin       string `xml:"recv_uin"`
	TimeEnd       string `xml:"time_end"`
	State         int    `xml:"state"`
	Sign          string `xml:"sign"`
	SignType      string `xml:"sign_type"`
	Attach        string `xml:"attach"`
}

ParseNotify parse

type QPayHbDetail added in v1.2.0

type QPayHbDetail struct {
	MchID       string
	AppSecret   string
	HTTPRequest *utils.HTTPClient
}

QPayHbDetail detail

func (*QPayHbDetail) GetDetail added in v1.2.0

func (q *QPayHbDetail) GetDetail(attributes ParamsQPayHbDetail) (*RespQPayHbDetail, error)

GetDetail get red envelop detail Doc: https://mp.qpay.tenpay.com/buss/wiki/221/2174

type RespQPayHbDetail added in v1.2.0

type RespQPayHbDetail struct {
	RetCode     string                 `json:"retcode"`
	RetMsg      string                 `json:"retmsg"`
	ListID      string                 `json:"listid"`
	State       string                 `json:"state"`
	TotalNum    string                 `json:"total_num"`
	RecvNum     string                 `json:"recv_num"`
	TotalAmount string                 `json:"total_amount"`
	RecvAmount  string                 `json:"recv_amount"`
	RecvDetails []RespQPayHbRecvDetail `json:"recv_details"`
}

RespQPayHbDetail response

type RespQPayHbRecvDetail added in v1.2.0

type RespQPayHbRecvDetail struct {
	CreateTime string `json:"create_time"`
	Uin        string `json:"uin"`
}

RespQPayHbRecvDetail detail

type RespSendQPayHb

type RespSendQPayHb struct {
	RetCode    string `json:"retcode"`
	RetMsg     string `json:"retmsg"`
	ReturnCode string `json:"return_code"`
	ReturnMsg  string `json:"return_msg"`
	ListID     string `json:"listid"`
}

RespSendQPayHb response

type SendQPayHb

type SendQPayHb struct {
	MchID       string
	MchName     string
	AppSecret   string
	HTTPRequest *utils.HTTPClient
	QqAppID     string // default empty
	NotifyURL   string // default empty
	Charset     int    // default utf8
}

SendQPayHb model

func (*SendQPayHb) SendQPayHb

func (s *SendQPayHb) SendQPayHb(OpenID string, attributes ParamsSendQPayHb) (*RespSendQPayHb, error)

SendQPayHb send red envelop Doc: https://mp.qpay.tenpay.com/buss/wiki/221/1220

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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