wechat

package
v0.0.0-...-5bb0c7b Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WxRefundURL = "https://api.mch.weixin.qq.com/secapi/pay/refund"
)
View Source
var (
	WxUnifiedOrderUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder"
)

Functions

func SignXmlMd5

func SignXmlMd5(v interface{}, apikey string) (string, bool)

Types

type AccessTokenResult

type AccessTokenResult struct {
	Errcode int    `json:"errcode,omitempty" bson:"-"`
	Errmsg  string `json:"errmsg,omitempty" bson:"-"`

	AccessToken string `json:"access_token,omitempty" bson:"accessToken,omitempty"`
	ExpiresIn   int    `json:"expires_in,omitempty" bson:"expiresIn,omitempty"`
	RfreshToken string `json:"rfresh_token,omitempty" bson:"rfreshToken,omitempty"`

	OpenId string `json:"openid,omitempty" bson:"openid,omitempty"`
	Scope  string `json:"scope,omitempty" bson:"scope,omitempty"`
}

type JsApiRequest

type JsApiRequest struct {
	XMLName xml.Name `xml:"xml" json:"-"`

	AppId     string `xml:"appId" json:"appId"`         //公众号id	appId	是	String(16)	wx8888888888888888	商户注册具有支付权限的公众号成功后即可获得
	NonceStr  string `xml:"nonceStr" json:"nonceStr"`   //随机字符串	nonceStr	是	String(32)	5K8264ILTKCH16CQ2502SI8ZNMTM67VS	随机字符串,不长于32位。推荐随机数生成算法
	Package   string `xml:"package" json:"package"`     //订单详情扩展字符串	package	是	String(128)	prepay_id=123456789	统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
	SignType  string `xml:"signType" json:"signType"`   //签名方式	signType	是	String(32)	MD5	签名算法,暂支持MD5
	TimeStamp string `xml:"timeStamp" json:"timeStamp"` //时间戳	timeStamp	是	String(32)	1414561699	当前的时间,其他详见时间戳规则

	PaySign string `xml:"-" json:"paySign"` //最终请求串
}

func (*JsApiRequest) SignMd5

func (v *JsApiRequest) SignMd5(appKey string) bool

type NotifyData

type NotifyData struct {
	XMLName xml.Name `xml:"xml"`
	// Coupon_batch_id_$n   string `xml:"coupon_batch_id_$n,omitempty"`
	// Coupon_count   string `xml:"coupon_count,omitempty"`
	// Coupon_fee   string `xml:"coupon_fee,omitempty"`
	// Coupon_fee_$n   string `xml:"coupon_fee_$n,omitempty"`
	// Coupon_id_$n   string `xml:"coupon_id_$n,omitempty"`
	AppId         xmlHelper.CData `xml:"appid"` //must
	Attach        xmlHelper.CData `xml:"attach,omitempty"`
	BankType      xmlHelper.CData `xml:"bank_type"`
	CashFee       xmlHelper.CData `xml:"cash_fee"`
	CashFeeType   xmlHelper.CData `xml:"cash_fee_type,omitempty"`
	DeviceInfo    xmlHelper.CData `xml:"device_info,omitempty"` //maybe
	ErrCode       xmlHelper.CData `xml:"err_code,omitempty"`
	ErrCodeDes    xmlHelper.CData `xml:"err_code_des,omitempty"`
	FeeType       xmlHelper.CData `xml:"fee_type,omitempty"`
	IsSubscribe   xmlHelper.CData `xml:"is_subscribe"`
	MchId         xmlHelper.CData `xml:"mch_id"`    //must
	NonceStr      xmlHelper.CData `xml:"nonce_str"` //must
	OpenId        xmlHelper.CData `xml:"openid"`
	OutTradeNo    xmlHelper.CData `xml:"out_trade_no"`
	ResultCode    xmlHelper.CData `xml:"result_code"`
	ReturnCode    xmlHelper.CData `xml:"return_code"`
	ReturnMsg     xmlHelper.CData `xml:"return_msg"`
	Sign          xmlHelper.CData `xml:"sign"`     //must
	TimeEnd       xmlHelper.CData `xml:"time_end"` //支付完成时间
	TotalFee      xmlHelper.CData `xml:"total_fee"`
	TradeType     xmlHelper.CData `xml:"trade_type"`
	TransactionId xmlHelper.CData `xml:"transaction_id"`

	XML string `xml:"-"` //结果串
}

type NotifyResponse

type NotifyResponse struct {
	XMLName    xml.Name        `xml:"xml"`
	ReturnCode xmlHelper.CData `xml:"return_code"`
	ReturnMsg  xmlHelper.CData `xml:"return_msg"`
	XML        string          `xml:"-"` //最终请求串
}

func (*NotifyResponse) Xml

func (v *NotifyResponse) Xml() error

type RefundReponse

type RefundReponse struct {
	XMLName    xml.Name `xml:"xml"`
	ReturnCode string   `xml:"return_code"`
	ReturnMsg  string   `xml:"return_msg"`

	//以下字段在return_code为SUCCESS的时候有返回
	AppId             string `xml:"appid"`                          //must
	MchId             string `xml:"mch_id"`                         //must
	DeviceInfo        string `xml:"device_info,omitempty"`          //maybe
	NonceStr          string `xml:"nonce_str"`                      //must
	Sign              string `xml:"sign"`                           //must
	TransactionId     string `xml:"transaction_id"`                 //must
	OutTradeNo        string `xml:"out_trade_no"`                   //must
	OutRefundNo       string `xml:"out_refund_no"`                  //must
	RefundId          string `xml:"refund_id"`                      //must
	RefundFee         string `xml:"refund_fee"`                     //must
	RefundFeeType     string `xml:"refund_fee_type,omitempty"`      //must
	TotalFee          string `xml:"total_fee"`                      //must
	FeeType           string `xml:"fee_type,omitempty"`             //must
	CashFee           string `xml:"cash_fee"`                       //must
	CashFeeType       string `xml:"cash_fee_type,omitempty"`        //must
	CashRefundFee     string `xml:"cash_refund_fee,omitempty"`      //must
	CashRefundFeeType string `xml:"cash_refund_fee_type,omitempty"` //must

	ResultCode string `xml:"result_code"`
	ErrCode    string `xml:"err_code,omitempty"`
	ErrCodeDes string `xml:"err_code_des,omitempty"`

	XML string `xml:"-"` //结果串
}

type RefundRequest

type RefundRequest struct {
	XMLName       xml.Name `xml:"xml"`
	AppId         string   `xml:"appid"`                     //must
	DeviceInfo    string   `xml:"device_info,omitempty"`     //maybe
	MchId         string   `xml:"mch_id"`                    //must
	NonceStr      string   `xml:"nonce_str"`                 //must
	OpUserId      string   `xml:"op_user_id"`                //maybe
	OutRefundNo   string   `xml:"out_refund_no"`             //must
	OutTradeNo    string   `xml:"out_trade_no"`              //must
	RefundFee     string   `xml:"refund_fee"`                //must
	RefundFeeType string   `xml:"refund_fee_type,omitempty"` //maybe
	Sign          string   `xml:"sign"`                      //must
	TotalFee      string   `xml:"total_fee"`                 //must
	TransactionId string   `xml:"transaction_id"`            //maybe
	RequestXML    string   `xml:"-"`                         //最终请求串
}

func (*RefundRequest) Xml

func (v *RefundRequest) Xml() error

type Req

type Req struct {
	ActName      string `json:"act_name" xml:"act_name"`             //act_name        活动名称
	ClientIP     string `json:"client_ip" xml:"client_ip"`           //client_ip       IP地址
	ConsumeMchID string `json:"consume_mch_id" xml:"consume_mch_id"` //consume_mch_id  资金授权商户号
	MchBillno    string `json:"mch_billno" xml:"mch_billno"`         //mch_billno      商户订单号
	MchID        string `json:"mch_id" xml:"mch_id"`                 //mch_id          商户号
	NonceStr     string `json:"nonce_str" xml:"nonce_str"`           //nonce_str       随机字符串
	ReOpenid     string `json:"re_openid" xml:"re_openid"`           //re_openid       用户openid
	Remark       string `json:"remark" xml:"remark"`                 //remark          备注
	RiskInfo     string `json:"risk_info" xml:"risk_info"`           //risk_info       活动信息
	SceneID      string `json:"scene_id" xml:"scene_id"`             //scene_id        场景id
	SendName     string `json:"send_name" xml:"send_name"`           //send_name       商户名称
	Sign         string `json:"sign" xml:"sign"`                     //sign            签名
	TotalAmount  string `json:"total_amount" xml:"total_amount"`     //total_amount    付款金额
	TotalNum     string `json:"total_num" xml:"total_num"`           //total_num       红包发放总人数
	Wishing      string `json:"wishing" xml:"wishing"`               //wishing         红包祝福语
	Wxappid      string `json:"wxappid" xml:"wxappid"`               //wxappid         公众账号appid
}

type Resp

type Resp struct {
	ErrCode     string `json:"err_code" xml:"err_code"`         //err_code 错误代码
	ErrCodeDes  string `json:"err_code_des" xml:"err_code_des"` //err_code_des 错误代码描述
	MchBillno   string `json:"mch_billno" xml:"mch_billno"`     //mch_billno 商户订单号
	MchID       string `json:"mch_id" xml:"mch_id"`             //mch_id 商户号
	ReOpenid    string `json:"re_openid" xml:"re_openid"`       //re_openid 用户openid
	ResultCode  string `json:"result_code" xml:"result_code"`   //result_code 业务结果
	ReturnCode  string `json:"return_code" xml:"return_code"`   //return_code 返回状态码
	ReturnMsg   string `json:"return_msg" xml:"return_msg"`     //return_msg 返回信息
	SendListid  string `json:"send_listid" xml:"send_listid"`   //send_listid 微信单号
	Sign        string `json:"sign" xml:"sign"`                 //sign 签名
	TotalAmount string `json:"total_amount" xml:"total_amount"` //total_amount 付款金额
	Wxappid     string `json:"wxappid" xml:"wxappid"`           //wxappid 公众账号appid
}

type SubscribeMessage

type SubscribeMessage struct {
	ToUser     string               `json:"touser"`
	TemplateID string               `json:"template_id"`
	Page       string               `json:"page,omitempty"`
	Data       SubscribeMessageData `json:"data"`
}

type SubscribeMessageData

type SubscribeMessageData map[string]SubscribeMessageDataValue

SubscribeMessageData 订阅消息模板数据

type SubscribeMessageDataValue

type SubscribeMessageDataValue struct {
	Value string `json:"value"`
}

type SubscribeMessageResponse

type SubscribeMessageResponse struct {
	ErrCode int    `json:"errcode"` // 	错误码
	ErrMSG  string `json:"errmsg"`  // 	错误描述
}

type TicketInfo

type TicketInfo struct {
	Ticket    string `json:"ticket"`
	ExpiresIn int64  `json:"expires_in"` // seconds
}

type UnifiedOrderRequest

type UnifiedOrderRequest struct {
	XMLName        xml.Name `xml:"xml"`
	AppId          string   `xml:"appid"`                 //公众账号ID	appid	是	String(32)	wxd678efh567hg6787	微信分配的公众账号ID(企业号corpid即为此appId)
	Attach         string   `xml:"attach,omitempty"`      //附加数据	attach	否	String(127)	深圳分店	附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
	Body           string   `xml:"body"`                  //商品描述	body	是	String(128)	Ipad mini  16G  白色	商品或支付单简要描述
	Detail         string   `xml:"detail,omitempty"`      //商品详情	detail	否	String(8192)	Ipad mini  16G  白色	商品名称明细列表
	DeviceInfo     string   `xml:"device_info,omitempty"` //设备号	device_info	否	String(32)	013467007045764	终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB"
	FeeType        string   `xml:"fee_type,omitempty"`    //货币类型	fee_type	否	String(16)	CNY	符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
	GoodsTag       string   `xml:"goods_tag,omitempty"`   //商品标记	goods_tag	否	String(32)	WXG	商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
	LimitPay       string   `xml:"limit_pay,omitempty"`   //指定支付方式	limit_pay	否	String(32)	no_credit	no_credit--指定不能使用信用卡支付
	MchId          string   `xml:"mch_id"`                //商户号	mch_id	是	String(32)	1230000109	微信支付分配的商户号
	NonceStr       string   `xml:"nonce_str"`             //随机字符串	nonce_str	是	String(32)	5K8264ILTKCH16CQ2502SI8ZNMTM67VS	随机字符串,不长于32位。推荐随机数生成算法
	NotifyURL      string   `xml:"notify_url"`            //通知地址	notify_url	是	String(256)	http://www.weixin.qq.com/wxpay/pay.php	接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
	Openid         string   `xml:"openid,omitempty"`      //用户标识	openid	否	String(128)	oUpF8uMuAJO_M2pxb1Q9zNjWeS6o	trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。openid如何获取,可参考【获取openid】。企业号请使用【企业号OAuth2.0接口】获取企业号内成员userid,再调用【企业号userid转openid接口】进行转换
	OutTradeNo     string   `xml:"out_trade_no"`          //商户订单号	out_trade_no	是	String(32)	20150806125346	商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
	ProductId      string   `xml:"product_id,omitempty"`  //商品ID	product_id	否	String(32)	12235413214070356458058	trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
	Sign           string   `xml:"sign"`                  //签名	sign	是	String(32)	C380BEC2BFD727A4B6845133519F3AD6	签名,详见签名生成算法
	SpbillCreateIp string   `xml:"spbill_create_ip"`      //终端IP	spbill_create_ip	是	String(16)	123.12.12.123	APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
	TimeExpire     string   `xml:"time_expire,omitempty"` //交易结束时间	time_expire	否	String(14)	20091227091010

	TimeStart string `xml:"time_start,omitempty"` //交易起始时间	time_start	否	String(14)	20091225091010
	// 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
	TotalFee  string `xml:"total_fee"`  //总金额	total_fee	是	Int	888	订单总金额,单位为分,详见支付金额
	TradeType string `xml:"trade_type"` //交易类型	trade_type	是	String(16)	JSAPI	取值如下:JSAPI,NATIVE,APP,详细说明见参数规定

	XML string `xml:"-"`
}

func (*UnifiedOrderRequest) Xml

func (v *UnifiedOrderRequest) Xml() error

type UnifiedOrderResponse

type UnifiedOrderResponse struct {
	XMLName    xml.Name        `xml:"xml"`
	ReturnCode xmlHelper.CData `xml:"return_code"`
	ReturnMsg  xmlHelper.CData `xml:"return_msg"`

	AppId      xmlHelper.CData `xml:"appid"`
	MchId      xmlHelper.CData `xml:"mch_id"`
	DeviceInfo xmlHelper.CData `xml:"device_info,omitempty"`
	NonceStr   xmlHelper.CData `xml:"nonce_str"`
	Sign       xmlHelper.CData `xml:"sign"`
	ResultCode xmlHelper.CData `xml:"result_code"`
	ErrCode    xmlHelper.CData `xml:"err_code,omitempty"`
	ErrCodeDes xmlHelper.CData `xml:"err_code_des,omitempty"`

	TradeType xmlHelper.CData `xml:"trade_type,omitempty"`
	PrepayId  xmlHelper.CData `xml:"prepay_id,omitempty"`
	CodeURL   xmlHelper.CData `xml:"code_url,omitempty"`

	ResponseXML string `xml:"-"`
}

type UserInfoResult

type UserInfoResult struct {
	Errcode    int      `json:"errcode,omitempty" xml:"errcode,omitempty" bson:"-"`
	Errmsg     string   `json:"errmsg,omitempty" xml:"errmsg,omitempty" bson:"-"`
	City       string   `json:"city" bson:"city" xml:"city"`
	Country    string   `json:"country" bson:"country" xml:"country"`
	HeadImgURL string   `json:"headimgurl" bson:"headImgURL" xml:"headimgurl"`
	Language   string   `json:"language" bson:"language" xml:"language"`
	Nickname   string   `json:"nickname" bson:"nickname" xml:"nickname"`
	Openid     string   `json:"openid" bson:"openId" xml:"openid"`
	Privilege  []string `json:"privilege" bson:"privilege" xml:"privilege"`
	Province   string   `json:"province" bson:"province" xml:"province"`
	Sex        int      `json:"sex" bson:"sex" xml:"sex"`
}

type Wechat

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

func NewWechat

func NewWechat(cah cache.Cache, config *config.Config) *Wechat

func (*Wechat) Exit

func (wx *Wechat) Exit() error

func (*Wechat) GetAccessTokenByClient

func (wx *Wechat) GetAccessTokenByClient(appId, appSecret string) (*AccessTokenResult, error)

func (*Wechat) GetAccessTokenByCode

func (wx *Wechat) GetAccessTokenByCode(code string) (*AccessTokenResult, error)

func (*Wechat) GetAuthURL

func (wx *Wechat) GetAuthURL(redirectUri, scope string) (string, error)

func (*Wechat) GetJSTicket

func (wx *Wechat) GetJSTicket(appId, appSecret string) (string, error)

func (*Wechat) GetShortURL

func (wx *Wechat) GetShortURL(longURL string) (string, error)

func (*Wechat) GetUserInfo

func (wx *Wechat) GetUserInfo(openId, accessTtoken string) (*UserInfoResult, error)

func (*Wechat) GetWxAcodeUnlimit

func (wx *Wechat) GetWxAcodeUnlimit(scene, page string, appId, appSecret string) ([]byte, error)

func (*Wechat) MinipUnifiedOrder

func (wx *Wechat) MinipUnifiedOrder(appId, mchId, apiKey,
	productId, productName, orderId string,
	expire int64, openId string,
	totalFee int, tradeType WxTradeType, clientIp, notifyURL string) (prepayId string, nonce string, timestamp int64, signStr string, err error)

针对小程序的统一下单

func (*Wechat) Refund

func (wx *Wechat) Refund(orderId string, openId string, totalFee int) error

func (*Wechat) SendRedPack

func (wx *Wechat) SendRedPack(extId, actName, remark, wishing, openId string, amount int) (*Resp, error)

func (*Wechat) SendSubscribeMessage

func (wx *Wechat) SendSubscribeMessage(
	appID, appSecret string,
	templateID string,
	toOpenID string,
	page string,
	data SubscribeMessageData,
) (*SubscribeMessageResponse, error)

func (*Wechat) SendTemplateMsg

func (wx *Wechat) SendTemplateMsg(param interface{}) error

func (*Wechat) UnifiedOrder

func (wx *Wechat) UnifiedOrder(
	appId, mchId, apiKey string,
	productId, productName, orderId string,
	expire int64, openId string,
	totalFee int, tradeType WxTradeType,
	clientIp string, notifyURL string) (prepayId string, err error)

type WxTradeType

type WxTradeType string
const (
	WxTradeTypeJSAPI  WxTradeType = "JSAPI"
	WxTradeTypeNATIVE WxTradeType = "NATIVE"
	WxTradeTypeAPP    WxTradeType = "APP"
)

Jump to

Keyboard shortcuts

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