Documentation ¶
Overview ¶
==================================
- Name:Jerry
- Tel:18017448610
- DateTime:2019/1/13 14:42
==================================
==================================
- Name:Jerry
- Tel:18017448610
- DateTime:2019/1/16 0:30
==================================
==================================
- Name:Jerry
- DateTime:2019/6/18 19:24
- Desc:
==================================
==================================
- Name:Jerry
- Tel:18017448610
- DateTime:2019/1/13 14:03
==================================
==================================
- Name:Jerry
- DateTime:2019/5/6 13:16
- Desc:
==================================
Index ¶
- Constants
- func DecryptOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr interface{}) (err error)
- func Float32ToString(floatNum float32, prec ...int) (floatStr string)
- func Float64ToString(floatNum float64, prec ...int) (floatStr string)
- func FormatAliPayPublicKey(publickKey string) (pKey string)
- func FormatAliPayURLParam(body BodyMap) (urlParam string)
- func FormatDate(dateStr string) (formatDate string)
- func FormatDateTime(timeStr string) (formatTime string)
- func FormatPrivateKey(privateKey string) (pKey string)
- func GetAppPaySign(appid, partnerid, noncestr, prepayid, signType, timestamp, apiKey string) (paySign string)
- func GetH5PaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string)
- func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string)
- func GetRandomString(length int) string
- func HttpAgent() (agent *gorequest.SuperAgent)
- func Int2String(intNum int) (intStr string)
- func Int642String(intNum int64) (int64Str string)
- func NewAliPayClient(appId, privateKey string, isProd bool) (client *aliPayClient)
- func NewWeChatClient(appId, mchId, apiKey string, isProd bool) (client *weChatClient)
- func PKCS7UnPadding(plainText []byte) []byte
- func ParseDateTime(timeStr string) (datetime time.Time)
- func String2Float(floatStr string) (floatNum float64)
- func String2Int(intStr string) (intNum int)
- func String2Int64(intStr string) (int64Num int64)
- func VerifyAliPayResultSign(aliPayPublicKey string, notifyRsp *AliPayNotifyRequest) (ok bool, sign string)
- func VerifyPayResultSign(apiKey string, signType string, notifyRsp *WeChatNotifyRequest) (ok bool, sign string)
- type AccessToken
- type AliPayAppInfo
- type AliPayNotifyRequest
- type AliPayTradePayAppResponse
- type BodyMap
- type Code2SessionRsp
- type FundBillListInfo
- type PaidUnionId
- type ReturnMessage
- type VoucherDetailListInfo
- type WeChatCloseOrderResponse
- type WeChatMicropayResponse
- type WeChatNotifyRequest
- type WeChatNotifyResponse
- type WeChatQueryOrderResponse
- type WeChatQueryRefundResponse
- type WeChatRefundResponse
- type WeChatReverseResponse
- type WeChatUnifiedOrderResponse
- type WeChatUserInfo
- type WeChatUserPhone
Constants ¶
const ( TimeLayout string = "2006-01-02 15:04:05" DateLayout string = "2006-01-02" //支付类型 TradeType_Mini = "JSAPI" TradeType_JsApi = "JSAPI" TradeType_App = "APP" TradeType_H5 = "MWEB" TradeType_Native = "NATIVE" //签名方式 SignType_MD5 = "MD5" SignType_HMAC_SHA256 = "HMAC-SHA256" //Debug数据 ApiKey = "GFDS8j98rewnmgl45wHTt980jg543wmg" AppID = "wxdaa2ab9ef87b5497" APPSecret = "65f42f625a788ed52f6e2e159304879c" MchID = "1368139502" MchID2 = "1526665601" OpenID = "o0Df70H2Q0fY8JXh1aFPIRyOBgu8" )
const ( SUCCESS = "SUCCESS" FAIL = "FAIL" )
Variables ¶
This section is empty.
Functions ¶
func DecryptOpenDataToStruct ¶ added in v1.0.7
解密开放数据
encryptedData:包括敏感数据在内的完整用户信息的加密数据 iv:加密算法的初始向量 sessionKey:会话密钥 beanPtr:需要解析到的结构体指针
func FormatAliPayPublicKey ¶ added in v1.1.1
格式化秘钥
func FormatAliPayURLParam ¶ added in v1.1.1
格式化请求URL参数
func FormatPrivateKey ¶ added in v1.1.1
格式化秘钥
func GetAppPaySign ¶ added in v1.1.0
func GetAppPaySign(appid, partnerid, noncestr, prepayid, signType, timestamp, apiKey string) (paySign string)
APP支付,统一下单获取支付参数后,再次计算APP支付所需要的的sign
signType:此处签名方式,务必与统一下单时用的签名方式一致
func GetH5PaySign ¶ added in v1.0.5
JSAPI支付,统一下单获取支付参数后,再次计算出微信内H5支付需要用的paySign
func GetMiniPaySign ¶
JSAPI支付,统一下单获取支付参数后,再次计算出小程序用的paySign
func HttpAgent ¶ added in v1.0.6
func HttpAgent() (agent *gorequest.SuperAgent)
func PKCS7UnPadding ¶ added in v1.0.7
解密填充模式(去除补全码) PKCS7UnPadding 解密时,需要在最后面去掉加密时添加的填充byte
func VerifyAliPayResultSign ¶ added in v1.1.2
func VerifyAliPayResultSign(aliPayPublicKey string, notifyRsp *AliPayNotifyRequest) (ok bool, sign string)
支付通知的签名验证和参数签名后的Sign
aliPayPublicKey:支付宝公钥 notifyRsp:利用 gopay.ParseAliPayNotifyResult() 得到的结构体 返回参数ok:是否验证通过 返回参数sign:根据参数计算的sign值,非支付宝返回参数中的Sign
func VerifyPayResultSign ¶ added in v1.0.9
func VerifyPayResultSign(apiKey string, signType string, notifyRsp *WeChatNotifyRequest) (ok bool, sign string)
支付通知的签名验证和参数签名后的Sign
apiKey:API秘钥值 signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5) notifyRsp:利用 gopay.ParseNotifyResult() 得到的结构体 返回参数ok:是否验证通过 返回参数sign:根据参数计算的sign值,非微信返回参数中的Sign
Types ¶
type AccessToken ¶ added in v1.0.7
type AccessToken struct { AccessToken string `json:"access_token"` //获取到的凭证 ExpiresIn int `json:"expires_in"` //SessionKey超时时间(秒) Errcode int `json:"errcode"` //错误码 Errmsg string `json:"errmsg"` //错误信息 }
func GetAccessToken ¶ added in v1.0.6
func GetAccessToken(appId, appSecret string) (accessToken *AccessToken, err error)
获取小程序全局唯一后台接口调用凭据(AccessToken:157字符)
appId:APPID appSecret:AppSecret
type AliPayAppInfo ¶ added in v1.1.1
type AliPayAppInfo struct { Code string `json:"code"` Msg string `json:"msg"` SubCode string `json:"sub_code"` SubMsg string `json:"sub_msg"` OutTradeNo string `json:"out_trade_no"` TradeNo string `json:"trade_no"` TotalAmount string `json:"total_amount"` SellerId string `json:"seller_id"` MerchantOrderNo string `json:"merchant_order_no"` }
type AliPayNotifyRequest ¶ added in v1.1.2
type AliPayNotifyRequest struct { NotifyTime string `json:"notify_time"` NotifyType string `json:"notify_type"` NotifyId string `json:"notify_id"` AppId string `json:"app_id"` Charset string `json:"charset"` Version string `json:"version"` SignType string `json:"sign_type"` Sign string `json:"sign"` TradeNo string `json:"trade_no"` OutTradeNo string `json:"out_trade_no"` OutBizNo string `json:"out_biz_no"` BuyerId string `json:"buyer_id"` BuyerLogonId string `json:"buyer_logon_id"` SellerId string `json:"seller_id"` SellerEmail string `json:"seller_email"` TradeStatus string `json:"trade_status"` TotalAmount string `json:"total_amount"` ReceiptAmount string `json:"receipt_amount"` InvoiceAmount string `json:"invoice_amount"` BuyerPayAmount string `json:"buyer_pay_amount"` PointAmount string `json:"point_amount"` RefundFee string `json:"refund_fee"` Subject string `json:"subject"` Body string `json:"body"` GmtCreate string `json:"gmt_create"` GmtPayment string `json:"gmt_payment"` GmtRefund string `json:"gmt_refund"` GmtClose string `json:"gmt_close"` FundBillList []FundBillListInfo `json:"fund_bill_list"` PassbackParams string `json:"passback_params"` VoucherDetailList []VoucherDetailListInfo `json:"voucher_detail_list"` }
func ParseAliPayNotifyResult ¶ added in v1.1.2
func ParseAliPayNotifyResult(req *http.Request) (notifyRsp *AliPayNotifyRequest, err error)
解析支付宝支付完成后的Notify信息
type AliPayTradePayAppResponse ¶ added in v1.1.1
type AliPayTradePayAppResponse struct { AlipayTradeAppPayResponse AliPayAppInfo `json:"alipay_trade_app_pay_response"` Sign string `json:"sign"` }
type Code2SessionRsp ¶ added in v1.0.6
type Code2SessionRsp struct { SessionKey string `json:"session_key"` //会话密钥 ExpiresIn int `json:"expires_in"` //SessionKey超时时间(秒) Openid string `json:"openid"` //用户唯一标识 Unionid string `json:"unionid"` //用户在开放平台的唯一标识符 Errcode int `json:"errcode"` //错误码 Errmsg string `json:"errmsg"` //错误信息 }
func Code2Session ¶ added in v1.0.6
func Code2Session(appId, appSecret, wxCode string) (sessionRsp *Code2SessionRsp, err error)
获取微信用户的OpenId、SessionKey、UnionId
appId:APPID appSecret:AppSecret wxCode:小程序调用wx.login 获取的code
type FundBillListInfo ¶ added in v1.1.2
type PaidUnionId ¶ added in v1.0.7
type PaidUnionId struct { Unionid string `json:"unionid"` //用户在开放平台的唯一标识符 Errcode int `json:"errcode"` //错误码 Errmsg string `json:"errmsg"` //错误信息 }
func GetPaidUnionId ¶ added in v1.0.6
func GetPaidUnionId(accessToken, openId, transactionId string) (unionId *PaidUnionId, err error)
用户支付完成后,获取该用户的 UnionId,无需用户授权。
accessToken:接口调用凭据 openId:用户的OpenID transactionId:微信支付订单号
type ReturnMessage ¶
type VoucherDetailListInfo ¶ added in v1.1.2
type WeChatCloseOrderResponse ¶
type WeChatCloseOrderResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` Appid string `xml:"appid"` MchId string `xml:"mch_id"` DeviceInfo string `xml:"device_info"` 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"` }
type WeChatMicropayResponse ¶
type WeChatMicropayResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` Appid string `xml:"appid"` MchId string `xml:"mch_id"` DeviceInfo string `xml:"device_info"` 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"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` BankType string `xml:"bank_type"` FeeType string `xml:"fee_type"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` CouponFee int `xml:"coupon_fee"` CashFeeType string `xml:"cash_fee_type"` CashFee int `xml:"cash_fee"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` PromotionDetail string `xml:"promotion_detail"` }
type WeChatNotifyRequest ¶
type WeChatNotifyRequest struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` ResultCode string `xml:"result_code"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` Appid string `xml:"appid"` MchId string `xml:"mch_id"` DeviceInfo string `xml:"device_info"` NonceStr string `xml:"nonce_str"` Sign string `xml:"sign"` SignType string `xml:"sign_type"` Openid string `xml:"openid"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` BankType string `xml:"bank_type"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CouponFee int `xml:"coupon_fee"` CouponCount int `xml:"coupon_count"` CouponType0 string `xml:"coupon_type_0"` CouponId0 string `xml:"coupon_id_0"` CouponFee0 int `xml:"coupon_fee_0"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` }
func ParseNotifyResult ¶
func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err error)
解析支付完成后的Notify信息
type WeChatNotifyResponse ¶
type WeChatNotifyResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` }
func (*WeChatNotifyResponse) ToXmlString ¶
func (this *WeChatNotifyResponse) ToXmlString() (xmlStr string)
返回数据给微信
type WeChatQueryOrderResponse ¶
type WeChatQueryOrderResponse 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"` DeviceInfo string `xml:"device_info"` Openid string `xml:"openid"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` TradeState string `xml:"trade_state"` BankType string `xml:"bank_type"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CouponFee int `xml:"coupon_fee"` CouponCount int `xml:"coupon_count"` CouponType0 string `xml:"coupon_type_0"` CouponId0 string `xml:"coupon_id_0"` CouponFee0 int `xml:"coupon_fee_0"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` TradeStateDesc string `xml:"trade_state_desc"` }
type WeChatQueryRefundResponse ¶
type WeChatQueryRefundResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` ResultCode string `xml:"result_code"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` Appid string `xml:"appid"` MchId string `xml:"mch_id"` NonceStr string `xml:"nonce_str"` Sign string `xml:"sign"` TotalRefundCount int `xml:"total_refund_count"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` RefundCount int `xml:"refund_count"` OutRefundNo0 string `xml:"out_refund_no_0"` RefundId0 string `xml:"refund_id_0"` RefundChannel0 string `xml:"refund_channel_0"` RefundFee0 int `xml:"refund_fee_0"` SettlementRefundFee0 int `xml:"settlement_refund_fee_0"` CouponType00 string `xml:"coupon_type_0_0"` CouponRefundFee0 int `xml:"coupon_refund_fee_0"` CouponRefundCount0 int `xml:"coupon_refund_count_0"` CouponRefundId00 string `xml:"coupon_refund_id_0_0"` CouponRefundFee00 int `xml:"coupon_refund_fee_0_0"` RefundStatus0 string `xml:"refund_status_0"` RefundAccount0 string `xml:"refund_account_0"` RefundRecvAccout0 string `xml:"refund_recv_accout_0"` RefundSuccessTime0 string `xml:"refund_success_time_0"` }
type WeChatRefundResponse ¶
type WeChatRefundResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` ResultCode string `xml:"result_code"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` 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 int `xml:"refund_fee"` SettlementRefundFee int `xml:"settlement_refund_fee"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CashRefundFee int `xml:"cash_refund_fee"` CouponType0 string `xml:"coupon_type_0"` CouponRefundFee int `xml:"coupon_refund_fee"` CouponRefundFee0 int `xml:"coupon_refund_fee_0"` CouponRefundCount int `xml:"coupon_refund_count"` CouponRefundId0 string `xml:"coupon_refund_id_0"` }
type WeChatReverseResponse ¶
type WeChatReverseResponse 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"` Recall string `xml:"recall"` }
type WeChatUnifiedOrderResponse ¶
type WeChatUnifiedOrderResponse struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` Appid string `xml:"appid"` MchId string `xml:"mch_id"` DeviceInfo string `xml:"device_info"` 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"` TradeType string `xml:"trade_type"` PrepayId string `xml:"prepay_id"` CodeUrl string `xml:"code_url"` MwebUrl string `xml:"mweb_url"` }
type WeChatUserInfo ¶ added in v1.0.7
type WeChatUserInfo 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 int `json:"subscribe_time"` //用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间 Unionid string `json:"unionid"` //只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。 Remark string `json:"remark"` //公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注 Groupid int `json:"groupid"` //用户所在的分组ID(兼容旧的用户分组接口) TagidList []int `json:"tagid_list"` //用户被打上的标签ID列表 SubscribeScene string `json:"subscribe_scene"` //返回用户关注的渠道来源,ADD_SCENE_SEARCH 公众号搜索,ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 扫描二维码,ADD_SCENEPROFILE LINK 图文页内名称点击,ADD_SCENE_PROFILE_ITEM 图文页右上角菜单,ADD_SCENE_PAID 支付后关注,ADD_SCENE_OTHERS 其他 QrScene int `json:"qr_scene"` //二维码扫码场景(开发者自定义) QrSceneStr string `json:"qr_scene_str"` //二维码扫码场景描述(开发者自定义) Errcode int `json:"errcode"` //错误码 Errmsg string `json:"errmsg"` //错误信息 }
func GetWeChatUserInfo ¶ added in v1.0.7
func GetWeChatUserInfo(accessToken, openId string, lang ...string) (userInfo *WeChatUserInfo, err error)
获取用户基本信息(UnionID机制)
accessToken:接口调用凭据 openId:用户的OpenID lang:默认为 zh_CN ,可选填 zh_CN 简体,zh_TW 繁体,en 英语