Documentation ¶
Index ¶
- Constants
- func CheckNotify(signature, timestamp, nonce, token string) bool
- type APIClient
- type APIConfig
- type AppPayment
- type CardMemberField
- type CardMemberInfo
- type CardService
- func (s *CardService) GetMemberByCode(cardCode string) (*CardMemberInfo, error)
- func (s *CardService) GetMemberByOpenid(openid string) (*CardMemberInfo, error)
- func (s *CardService) GetUseSubmitParam(encryptCode, openid, activateTicket string) (*CardMemberInfo, error)
- func (s *CardService) SetActivateFlag() error
- func (s *CardService) SetActivateJump(submitURL, levelURL, couponURL string) error
- type CustomerService
- type H5Payment
- type JSConfigService
- type JsSDKConfig
- type LinkArticleParam
- type OAuthService
- type OAuthUser
- type PayAppUnifiedorderParam
- type PayNotifyParam
- type PayOrderQueryParam
- type PayQueryOrderResp
- type PayService
- func (s *PayService) AppUnifiedOrder(outTradeNo string, totalFee int32, spbillCreateIP string, tradeType string, ...) (*PayAppUnifiedorderParam, *PayUnifyOrderResp, error)
- func (s *PayService) CloseOrder(outTradeNo string) error
- func (s *PayService) GetAppPayment(prepayID string) *AppPayment
- func (s *PayService) GetH5Payment(prepayID string) *H5Payment
- func (s *PayService) GetTradeStateLabel(tradeState string) string
- func (s *PayService) QueryOrder(orderID string) (*PayOrderQueryParam, *PayQueryOrderResp, error)
- func (s *PayService) RefundOrder(outTradeNo string, outRefundNo string, totalFee int32, refundFee int32) (*RefundOrderQueryParam, *RefundOrderResp, error)
- func (s *PayService) UnifiedOrder(outTradeNo string, totalFee int32, spbillCreateIP string, tradeType string, ...) (*PayUnifiedorderParam, *PayUnifyOrderResp, error)
- type PayUnifiedorderParam
- type PayUnifyOrderResp
- type QRCodeService
- type RefundOrderQueryParam
- type RefundOrderResp
- type UserService
- type WXUserInfo
Constants ¶
const ( // TradeTypeJsapi 公众号支付 TradeTypeJsapi = "JSAPI" // TradeTypeNative 原生扫码支付 TradeTypeNative = "NATIVE" // TradeTypeApp app支付 TradeTypeApp = "APP" // TradeTypeMicropay 刷卡支付,刷卡支付有单独的支付接口,不调用统一下单接口 TradeTypeMicropay = "MICROPAY" // TradeStateSUCCESS 支付成功 TradeStateSUCCESS = "SUCCESS" // TradeStateREFUND 转入退款 TradeStateREFUND = "REFUND" // TradeStateNOTPAY 未支付 TradeStateNOTPAY = "NOTPAY" // TradeStateCLOSED 已关闭 TradeStateCLOSED = "CLOSED" // TradeStateREVOKED 已撤销(刷卡支付) TradeStateREVOKED = "REVOKED" // TradeStateUSERPAYING 用户支付中 TradeStateUSERPAYING = "USERPAYING" // TradeStatePAYERROR 支付失败(其他原因,如银行返回失败) TradeStatePAYERROR = "PAYERROR" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIClient ¶
type APIClient struct { AppID string // 公众号AppID AppSecret string // 公众号AppSecret MchID string // 商户ID MchSecret string // 商户Secret PayNotityURL string // 支付通知地址 MemberCardID string // 会员卡ID User *UserService // 与微信公众平台服务的用户管理相关接口 Card *CardService // 与微信公众平台服务的微信卡券相关接口 Pay *PayService // 与微信商户平台服务的微信支付相关接口 OAuth *OAuthService // 与微信公众平台服务的网页授权相关接口 Customer *CustomerService // 客服服务 QRCode *QRCodeService // 二维码服务 JSConfig *JSConfigService // 网页JS配置 ApplicationID string // 应用ID,用于APP // contains filtered or unexported fields }
APIClient 的所有变量
func (*APIClient) GetAccessToken ¶
GetAccessToken 获取 access token
func (*APIClient) GetJSAPITicket ¶
GetJSAPITicket 获取jsapi ticket
func (*APIClient) RefreshAccessToken ¶
RefreshAccessToken token已失效,需要刷新后返回
type APIConfig ¶
type APIConfig struct { AppID string // 公众号AppID AppSecret string // 公众号AppSecret MchID string // 商户ID MchSecret string // 商户Secret PayNotityURL string // 支付通知地址 MemberCardID string // 会员卡ID WechatCacher string // 公众号token等中心缓存库地址,只需要传中心库根路径,为空值时,默认认为不需要用到access_token P12Path string // Cert文件地址 PemPath string // Cert文件地址 Password string // Cert文件密码 ApplicationID string // 应用ID,用于APP }
APIConfig 调用微信Api的配置参数
type AppPayment ¶
type AppPayment struct { AppID string `sign:"appid" json:"appID"` // 公众号id PartnerID string `sign:"partnerid" json:"partnerID"` PrepayID string `sign:"prepayid" json:"prepayID"` Package string `sign:"package" json:"packageStr"` // 订单详情扩展字符串 NonceStr string `sign:"noncestr" json:"nonceStr"` // 随机字符串 TimeStamp string `sign:"timestamp" json:"timeStamp"` // 时间戳 Sign string `json:"sign"` // 签名 }
AppPayment App支付参数
type CardMemberField ¶
type CardMemberField struct { Name string `json:"name"` // 会员信息类目名称 Value string `json:"value"` // 会员卡信息类目值,比如等级值等 }
CardMemberField 卡会员的参数
type CardMemberInfo ¶
type CardMemberInfo struct { CardID string Openid string Unionid string CardCode string Nickname string MobileNumber string Gender string RealName string Birthday time.Time MemberStatus string Baby1 string Baby2 string }
CardMemberInfo 微信会员卡的会员信息
type CardService ¶
type CardService service
CardService 处理与卡券相关的API,包括会员卡和优惠券
func (*CardService) GetMemberByCode ¶
func (s *CardService) GetMemberByCode(cardCode string) (*CardMemberInfo, error)
GetMemberByCode 通过会员卡号获取会员信息
func (*CardService) GetMemberByOpenid ¶
func (s *CardService) GetMemberByOpenid(openid string) (*CardMemberInfo, error)
GetMemberByOpenid 通过openid获取会员信息
func (*CardService) GetUseSubmitParam ¶
func (s *CardService) GetUseSubmitParam(encryptCode, openid, activateTicket string) (*CardMemberInfo, error)
GetUseSubmitParam 获取微信指定用户提交的激活信息
func (*CardService) SetActivateFlag ¶
func (s *CardService) SetActivateFlag() error
SetActivateFlag 设置微信一键激活参数
当前需要必填 姓名、性别、电话、生日、小孩数量 type activateCardURL struct { Name string `json:"name"` URL string `json:"url"` } type activateCard struct { CardID string `json:"card_id"` ServiceStatement activateCardURL `json:"service_statement"` // 服务声明,用于放置商户会员卡守则 BindOldCard activateCardURL `json:"bind_old_card"` // 绑定老会员链接 RequiredForm fieldForm `json:"required_form"` // 会员卡激活时的必填选项 OptionalForm fieldForm `json:"optional_form"` // 会员卡激活时的选填项 }
func (*CardService) SetActivateJump ¶
func (s *CardService) SetActivateJump(submitURL, levelURL, couponURL string) error
SetActivateJump 设置微信激活后跳转连接
type CustomerService ¶
type CustomerService service
CustomerService 处理与客服相关的API,主要包括客服消息
func (*CustomerService) SendImage ¶
func (s *CustomerService) SendImage(openID string, mediaID string) error
SendImage 发送图片消息
func (*CustomerService) SendLinkArticle ¶
func (s *CustomerService) SendLinkArticle(openID string, param LinkArticleParam) error
SendLinkArticle 发送外链图文消息,尽管微信允许发送最多8条外链的图文,但为了体验优化,仅允许发送一条
func (*CustomerService) SendText ¶
func (s *CustomerService) SendText(openID string, content string) error
SendText 发送文本消息
type H5Payment ¶
type H5Payment struct { AppID string `sign:"appId" json:"appID"` // 公众号id TimeStamp string `sign:"timeStamp" json:"timeStamp"` // 时间戳 NonceStr string `sign:"nonceStr" json:"nonceStr"` // 随机字符串 Package string `sign:"package" json:"package"` // 订单详情扩展字符串 SignType string `sign:"signType" json:"signType"` // 签名方式 PaySign string `json:"paySign"` // 签名 }
H5Payment H5支付参数
type JSConfigService ¶
type JSConfigService service
JSConfigService 网页JS的配置服务
func (*JSConfigService) GetJSConfig ¶
func (s *JSConfigService) GetJSConfig(url string) (*JsSDKConfig, error)
GetJSConfig 获取JSSDK的配置
type JsSDKConfig ¶
type JsSDKConfig struct { AppID string `json:"appId"` Timestamp int64 `json:"timestamp"` NonceStr string `json:"nonceStr"` Signature string `json:"signature"` }
JsSDKConfig 微信JsSDKConfig
type LinkArticleParam ¶
LinkArticleParam 外链图文消息的发送参数
type OAuthService ¶
type OAuthService service
OAuthService 在微信客户端中访问第三方网页,利用微信网页授权机制, 来获取用户基本信息
func (*OAuthService) GetUserByAccessToken ¶
func (s *OAuthService) GetUserByAccessToken(accessToken, openID string) (*OAuthUser, error)
GetUserByAccessToken 当scope为snsapi_userinfo时,通过access_token和openid拉取用户信息
func (*OAuthService) GetUserByCode ¶
func (s *OAuthService) GetUserByCode(code string) (*OAuthUser, error)
GetUserByCode 直接通过code获取OAuthUser
func (*OAuthService) Link ¶
func (s *OAuthService) Link(landingPage, from string) string
Link 生成微信网页授权的页面地址,这个地址中的redirect_uri参数 是在用户同意微信授权之后,重定向到第三方网站的页面,因此landingPage是一个形如: https://www.abc.com/login的地址 这个地址会接收到微信提供的code参数,如果想要回到授权前的页面,应传入from参数, 在正确使用code拉取用户信息之后,回到from这个页面
type OAuthUser ¶
type OAuthUser struct { Openid string `json:"openid"` Nickname string `json:"nickname"` Sex int `json:"sex"` //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 Province string `json:"province"` City string `json:"city"` Country string `json:"country"` HeadImgURL string `json:"headimgurl"` UnionID string `json:"unionid"` }
OAuthUser 通过微信网页授权拉取的用户信息 此用户信息只有在scope为snsapi_userinfo时 通过access_token和openid拉取
type PayAppUnifiedorderParam ¶
type PayAppUnifiedorderParam struct { XMLName xml.Name `xml:"xml"` AppID string `sign:"appid" xml:"appid"` Body string `sign:"body" xml:"body"` MchID string `sign:"mch_id" xml:"mch_id"` NonceStr string `sign:"nonce_str" xml:"nonce_str"` NotifyURL string `sign:"notify_url" xml:"notify_url"` TradeType string `sign:"trade_type" xml:"trade_type"` SpbillCreateIP string `sign:"spbill_create_ip" xml:"spbill_create_ip"` TotalFee int32 `sign:"total_fee" xml:"total_fee"` OutTradeNo string `sign:"out_trade_no" xml:"out_trade_no"` Sign string `xml:"sign"` }
PayAppUnifiedorderParam 微信APP统一下单请求参数
type PayNotifyParam ¶
type PayNotifyParam struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` Appid string `xml:"appid"` MchID string `xml:"mch_id"` Nonce string `xml:"nonce_str"` Sign string `xml:"sign"` ResultCode string `xml:"result_code"` Openid string `xml:"openid"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` BankType string `xml:"bank_type"` TotalFee int `xml:"total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` TransactionID string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` }
PayNotifyParam 支付通知参数
type PayOrderQueryParam ¶
type PayOrderQueryParam struct { XMLName xml.Name `xml:"xml"` AppID string `sign:"appid" xml:"appid"` MchID string `sign:"mch_id" xml:"mch_id"` OutTradeNo string `sign:"out_trade_no" xml:"out_trade_no"` NonceStr string `sign:"nonce_str" xml:"nonce_str"` Sign string `xml:"sign"` }
PayOrderQueryParam 微信订单查询参数
type PayQueryOrderResp ¶
type PayQueryOrderResp struct { 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"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` OpenID string `xml:"openid"` TradeType string `xml:"trade_type"` TradeState string `xml:"trade_state"` BankType string `xml:"bank_type"` TotalFee int `xml:"total_fee"` CashFee int `xml:"cash_fee"` TransactionID string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` TimeEnd string `xml:"time_end"` TradeStateDesc string `xml:"trade_state_desc"` }
PayQueryOrderResp 查询微信支付状态的返回参数
type PayService ¶
type PayService service
PayService 订单支付服务
func (*PayService) AppUnifiedOrder ¶
func (s *PayService) AppUnifiedOrder(outTradeNo string, totalFee int32, spbillCreateIP string, tradeType string, openid string, body string) (*PayAppUnifiedorderParam, *PayUnifyOrderResp, error)
AppUnifiedOrder APP统一下单
func (*PayService) CloseOrder ¶
func (s *PayService) CloseOrder(outTradeNo string) error
CloseOrder 关闭订单
func (*PayService) GetAppPayment ¶
func (s *PayService) GetAppPayment(prepayID string) *AppPayment
GetAppPayment 获取App支付参数
func (*PayService) GetH5Payment ¶
func (s *PayService) GetH5Payment(prepayID string) *H5Payment
GetH5Payment 获取公众号支付参数
func (*PayService) GetTradeStateLabel ¶
func (s *PayService) GetTradeStateLabel(tradeState string) string
GetTradeStateLabel 获取支付状态名称
func (*PayService) QueryOrder ¶
func (s *PayService) QueryOrder(orderID string) (*PayOrderQueryParam, *PayQueryOrderResp, error)
QueryOrder 查询微信支付订单的状态
func (*PayService) RefundOrder ¶
func (s *PayService) RefundOrder(outTradeNo string, outRefundNo string, totalFee int32, refundFee int32) (*RefundOrderQueryParam, *RefundOrderResp, error)
RefundOrder 退款
func (*PayService) UnifiedOrder ¶
func (s *PayService) UnifiedOrder(outTradeNo string, totalFee int32, spbillCreateIP string, tradeType string, openid string, body string) (*PayUnifiedorderParam, *PayUnifyOrderResp, error)
UnifiedOrder 统一下单
type PayUnifiedorderParam ¶
type PayUnifiedorderParam struct { XMLName xml.Name `xml:"xml"` AppID string `sign:"appid" xml:"appid"` Openid string `sign:"openid" xml:"openid"` Body string `sign:"body" xml:"body"` MchID string `sign:"mch_id" xml:"mch_id"` NonceStr string `sign:"nonce_str" xml:"nonce_str"` NotifyURL string `sign:"notify_url" xml:"notify_url"` TradeType string `sign:"trade_type" xml:"trade_type"` SpbillCreateIP string `sign:"spbill_create_ip" xml:"spbill_create_ip"` TotalFee int32 `sign:"total_fee" xml:"total_fee"` OutTradeNo string `sign:"out_trade_no" xml:"out_trade_no"` Sign string `xml:"sign"` }
PayUnifiedorderParam 微信统一下单请求参数
type PayUnifyOrderResp ¶
type PayUnifyOrderResp struct { 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"` PrepayID string `xml:"prepay_id"` TradeType string `xml:"trade_type"` }
PayUnifyOrderResp 微信统一下单返回参数
type QRCodeService ¶
type QRCodeService service
QRCodeService 处理与客服相关的API,主要包括客服消息
func (*QRCodeService) GetTempQRCode ¶
func (s *QRCodeService) GetTempQRCode(param int) (string, error)
GetTempQRCode 获取临时参数二维码,返回这个参数二维码的地址
type RefundOrderQueryParam ¶
type RefundOrderQueryParam struct { XMLName xml.Name `xml:"xml"` AppID string `sign:"appid" xml:"appid"` MchID string `sign:"mch_id" xml:"mch_id"` NonceStr string `sign:"nonce_str" xml:"nonce_str"` OutTradeNo string `sign:"out_trade_no" xml:"out_trade_no"` OutRefundNo string `sign:"out_refund_no" xml:"out_refund_no"` TotalFee int32 `sign:"total_fee" xml:"total_fee"` RefundFee int32 `sign:"refund_fee" xml:"refund_fee"` Sign string `xml:"sign"` }
RefundOrderQueryParam 微信订单退款参数
type RefundOrderResp ¶
type RefundOrderResp struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` ResultCode string `xml:"result_code"` Appid string `xml:"appid"` MchID string `xml:"mch_id"` NonceStr string `xml:"nonce_str"` Sign string `xml:"sign"` TransactionID string `xml:"transaction_id"` // 微信订单号 OutTradeNo string `xml:"out_trade_no"` // 商户订单号 OutRefundNo string `xml:"out_refund_no"` // 商户退款单号 RefundID string `xml:"refund_id"` // 微信退款单号 RefundFee int32 `xml:"refund_fee"` // 退款金额 TotalFee int32 `xml:"total_fee"` // 标价金额 CashFee int32 `xml:"cash_fee"` // 现金支付金额 PrepayID string `xml:"prepay_id"` TradeType string `xml:"trade_type"` ErrCodeDes string `xml:"err_code_des"` }
RefundOrderResp 微信订单退款返回参数
type UserService ¶
type UserService service
UserService 处理与用户相关的API,包括用户授权登录和获取、更新用户资料
func (*UserService) GetUserInfoByOpenid ¶
func (s *UserService) GetUserInfoByOpenid(openid string) (*WXUserInfo, error)
GetUserInfoByOpenid 通过openid获取用户基本信息
type WXUserInfo ¶
type WXUserInfo struct { Subscribe int `json:"subscribe"` // 用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。 Openid string `json:"openid"` // 用户的标识,对当前公众号唯一 Nickname string `json:"nickname"` // 用户的昵称 Sex int `json:"sex"` // 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 Language string `json:"language"` // 用户的语言,简体中文为zh_CN City string `json:"city"` // 用户所在城市 Province string `json:"province"` // 用户所在省份 Country string `json:"country"` // 用户所在国家 Headimgurl string `json:"headimgurl"` // 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。 SubscribeTime int64 `json:"subscribe_time"` // 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间 Unionid string `json:"unionid"` // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段 Remark string `json:"remark"` // 公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注 Groupid int64 `json:"groupid"` // 用户所在的分组ID(兼容旧的用户分组接口) TagidList []int64 `json:"tagid_list"` // 用户被打上的标签ID列表 Errcode int `json:"errcode"` Errmsg string `json:"errmsg"` }
WXUserInfo 微信用户基本信息