gopay

package module
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 30 Imported by: 0

README

Logo was Loading Faild!

GoPay

English Document

微信和支付宝的Golang版本SDK

Author Golang Godoc GitHub release (latest by date) Travis (.org) License

微信Client
  • client := gopay.NewWeChatClient() => 初始化微信支付客户端
微信支付API
  • 统一下单:client.UnifiedOrder()
    • JSAPI - JSAPI支付(或小程序支付)
    • NATIVE - Native支付
    • APP - app支付
    • MWEB - H5支付
  • 提交付款码支付:client.Micropay()
  • 查询订单:client.QueryOrder()
  • 关闭订单:client.CloseOrder()
  • 撤销订单:client.Reverse()
  • 申请退款:client.Refund()
  • 查询退款:client.QueryRefund()
  • 下载对账单:client.DownloadBill()
  • 下载资金账单:client.DownloadFundFlow()
  • 拉取订单评价数据:client.BatchQueryComment()
  • 企业向微信用户个人付款:client.Transfer()
微信公共API
  • gopay.GetWeChatParamSign() => 获取微信支付所需参数里的Sign值(通过支付参数计算Sign值)
  • gopay.GetWeChatSanBoxParamSign() => 获取微信支付沙箱环境所需参数里的Sign值(通过支付参数计算Sign值)
  • gopay.GetMiniPaySign() => 获取微信小程序支付所需要的paySign
  • gopay.GetH5PaySign() => 获取微信内H5支付所需要的paySign
  • gopay.GetAppPaySign() => 获取APP支付所需要的paySign
  • gopay.ParseWeChatNotifyResultToBodyMap() => 解析微信支付异步通知的参数到BodyMap
  • gopay.ParseWeChatNotifyResult() => 解析微信支付异步通知的参数
  • gopay.ParseWeChatRefundNotifyResult() => 解析微信退款异步通知的参数
  • gopay.VerifyWeChatSign() => 微信同步返回参数验签或异步通知参数验签
  • gopay.Code2Session() => 登录凭证校验:获取微信用户OpenId、UnionId、SessionKey
  • gopay.GetWeChatAppletAccessToken() => 获取微信小程序全局唯一后台接口调用凭据
  • gopay.GetWeChatAppletPaidUnionId() => 微信小程序用户支付完成后,获取该用户的 UnionId,无需用户授权
  • gopay.GetWeChatUserInfo() => 微信公众号:获取用户基本信息(UnionID机制)
  • gopay.DecryptWeChatOpenDataToStruct() => 加密数据,解密到指定结构体
  • gopay.DecryptWeChatOpenDataToBodyMap() => 加密数据,解密到 BodyMap
  • gopay.GetOpenIdByAuthCode() => 授权码查询openid
  • gopay.GetAppWeChatLoginAccessToken() => App应用微信第三方登录,code换取access_token
  • gopay.RefreshAppWeChatLoginAccessToken() => 刷新App应用微信第三方登录后,获取的 access_token
  • gopay.DecryptRefundNotifyReqInfo() => 解密微信退款异步通知的加密数据

支付宝Client
  • client := gopay.NewAliPayClient() => 初始化支付宝支付客户端
支付宝支付API
  • 手机网站支付接口2.0(手机网站支付):client.AliPayTradeWapPay()
  • 统一收单下单并支付页面接口(电脑网站支付):client.AliPayTradePagePay()
  • APP支付接口2.0(APP支付):client.AliPayTradeAppPay()
  • 统一收单交易支付接口(商家扫用户付款码):client.AliPayTradePay()
  • 统一收单交易创建接口(小程序支付):client.AliPayTradeCreate()
  • 统一收单线下交易查询:client.AliPayTradeQuery()
  • 统一收单交易关闭接口:client.AliPayTradeClose()
  • 统一收单交易撤销接口:client.AliPayTradeCancel()
  • 统一收单交易退款接口:client.AliPayTradeRefund()
  • 统一收单退款页面接口:client.AliPayTradePageRefund()
  • 统一收单交易退款查询:client.AliPayTradeFastPayRefundQuery()
  • 统一收单交易结算接口:client.AliPayTradeOrderSettle()
  • 统一收单线下交易预创建(用户扫商品收款码):client.AliPayTradePrecreate()
  • 单笔转账到支付宝账户接口(商户给支付宝用户转账):client.AlipayFundTransToaccountTransfer()
  • 换取授权访问令牌(获取access_token,user_id等信息):client.AliPaySystemOauthToken()
  • 支付宝会员授权信息查询接口(App支付宝登录):client.AlipayUserInfoShare()
  • 换取应用授权令牌(获取app_auth_token,auth_app_id,user_id等信息):client.AliPayOpenAuthTokenApp()
  • 获取芝麻信用分:client.ZhimaCreditScoreGet()
  • 身份认证初始化服务:client.AliPayUserCertifyOpenInit()
  • 身份认证开始认证(获取认证链接):client.AliPayUserCertifyOpenCertify()
  • 身份认证记录查询:client.AliPayUserCertifyOpenQuery()
支付宝公共API
  • gopay.GetCertSN() => 获取证书SN号(app_cert_sn、alipay_cert_sn、alipay_root_cert_sn>
  • gopay.AliPaySystemOauthToken() => 换取授权访问令牌(得到access_token,user_id等信息)
  • gopay.FormatPrivateKey() => 格式化应用私钥
  • gopay.FormatAliPayPublicKey() => 格式化支付宝公钥
  • gopay.ParseAliPayNotifyResult() => 解析支付宝支付异步通知的参数到Struct
  • gopay.ParseAliPayNotifyResultToBodyMap() => 解析支付宝支付异步通知的参数到BodyMap
  • gopay.VerifyAliPaySign() => 支付宝异步通知参数验签
  • gopay.VerifyAliPaySyncSign() => 支付宝同步返回参数验签
  • gopay.DecryptAliPayOpenDataToStruct() => 支付宝小程序敏感加密数据解析到结构体

一、安装

$ go get -u github.com/extvos/gopay
package main

import (
    "fmt"
    "github.com/extvos/gopay"
)

func main() {
    fmt.Println("GoPay Version: ", gopay.Version)
}

二、文档说明

  • GoDoc
  • 所有方法,如有问题,请仔细查看 examples
  • 有问题请加QQ群(加群验证答案:gopay)。在此,非常感谢那些加群后,提出意见和反馈问题的同志们!

QQ群: 微信(加好友后拉进群):


1、初始化GoPay客户端并做配置(HTTP请求均设置tls.Config{InsecureSkipVerify: true})

  • 微信客户端,如无需更改Appid、Mchid和ApiKey等参数,可在init()方法中初始化,全局适用

微信官方文档:官方文档

// 初始化微信客户端
//    appId:应用ID
//    mchId:商户ID
//    apiKey:API秘钥值
//    isProd:是否是正式环境
client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", mchId, apiKey, false)

// 设置国家:不设置默认 中国国内
//    gopay.China:中国国内
//    gopay.China2:中国国内备用
//    gopay.SoutheastAsia:东南亚
//    gopay.Other:其他国家
client.SetCountry(gopay.China)

// 添加微信证书 Byte 数组
//    certFile:apiclient_cert.pem byte数组
//    keyFile:apiclient_key.pem byte数组
//    pkcs12File:apiclient_cert.p12 byte数组
client.AddCertFileByte()

// 添加微信证书 Path 路径
//    certFilePath:apiclient_cert.pem 路径
//    keyFilePath:apiclient_key.pem 路径
//    pkcs12FilePath:apiclient_cert.p12 路径
//    返回err
client.AddCertFilePath()

  • 支付宝,如无需更改Appid和PrivateKey等参数,可在init()方法中初始化,全局适用

支付宝官方文档:官方文档

支付宝RSA秘钥生成文档:生成 RSA 密钥

沙箱环境使用说明:文档地址

//初始化支付宝客户端
//    appId:应用ID
//    privateKey:应用秘钥
//    isProd:是否是正式环境
client := gopay.NewAliPayClient("2016091200494382", privateKey, false)

//设置支付宝请求 公共参数
//    注意:具体设置哪些参数,根据不同的方法而不同,此处列举出所以设置参数
client.SetAliPayRootCertSN().               //设置支付宝根证书SN,通过 gopay.GetCertSN() 获取
    SetAppCertSN().                         //设置应用公钥证书SN,通过 gopay.GetCertSN() 获取
    SetCharset("utf-8").                    //设置字符编码,不设置默认 utf-8
    SetSignType("RSA2").                    //设置签名类型,不设置默认 RSA2
    SetReturnUrl("https://www.gopay.ink").  //设置返回URL
    SetNotifyUrl("https://www.gopay.ink").  //设置异步通知URL
    SetAppAuthToken().                      //设置第三方应用授权
    SetAuthToken()                          //设置个人信息授权

client, err := client.SetAppCertSnByPath("appCertPublicKey.crt")
client, err := client.SetAliPayPublicCertSnByPath("alipayCertPublicKey_RSA2.crt")
client, err := client.SetAliPayRootCertSnByPath("alipayRootCert.crt")

2、初始化并赋值BodyMap(client的方法所需的入参)

  • 微信请求参数

具体参数请根据不同接口查看:微信支付接口文档

//初始化 BodyMap
bm := make(gopay.BodyMap)
bm.Set("nonce_str", gopay.GetRandomString(32))
bm.Set("body", "小程序测试支付")
bm.Set("out_trade_no", number)
bm.Set("total_fee", 1)
bm.Set("spbill_create_ip", "127.0.0.1")
bm.Set("notify_url", "http://www.gopay.ink")
bm.Set("trade_type", gopay.TradeType_Mini)
bm.Set("device_info", "WEB")
bm.Set("sign_type", gopay.SignType_MD5)
bm.Set("openid", "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")

//嵌套json格式数据(例如:H5支付的 scene_info 参数)
h5Info := make(map[string]string)
h5Info["type"] = "Wap"
h5Info["wap_url"] = "http://www.gopay.ink"
h5Info["wap_name"] = "H5测试支付"

sceneInfo := make(map[string]map[string]string)
sceneInfo["h5_info"] = h5Info

bm.Set("scene_info", sceneInfo)

//参数 sign ,可单独生成赋值到BodyMap中;也可不传sign参数,client内部会自动获取
//如需单独赋值 sign 参数,需通过下面方法,最后获取sign值并在最后赋值此参数
sign := gopay.GetWeChatParamSign("wxdaa2ab9ef87b5497", mchId, apiKey, body)
//sign, _ := gopay.GetWeChatSanBoxParamSign("wxdaa2ab9ef87b5497", mchId, apiKey, body)
bm.Set("sign", sign)
  • 支付宝请求参数

具体参数请根据不同接口查看:支付宝支付API接口文档

//此时李
//初始化 BodyMap
bm := make(gopay.BodyMap)
bm.Set("subject", "手机网站测试支付")
bm.Set("out_trade_no", "GZ201901301040355703")
bm.Set("quit_url", "https://www.gopay.ink")
bm.Set("total_amount", "100.00")
bm.Set("product_code", "QUICK_WAP_WAY")

3、client 方法调用

  • 微信 client
wxRsp, err := client.UnifiedOrder(bm)
wxRsp, err := client.Micropay(bm)
wxRsp, err := client.QueryOrder(bm)
wxRsp, err := client.CloseOrder(bm)
wxRsp, err := client.Reverse(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.Refund(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.QueryRefund(bm)
wxRsp, err := client.DownloadBill(bm)
wxRsp, err := client.DownloadFundFlow(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.BatchQueryComment(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
wxRsp, err := client.Transfer(bm, "apiclient_cert.pem", "apiclient_key.pem", "apiclient_cert.p12")
  • 支付宝 client
//手机网站支付是通过服务端获取支付URL后,然后返回给客户端,请求URL地址即可打开支付页面
payUrl, err := client.AliPayTradeWapPay(bm)

//电脑网站支付是通过服务端获取支付URL后,然后返回给客户端,请求URL地址即可打开支付页面
payUrl, err := client.AliPayTradePagePay(bm)

//APP支付是通过服务端获取支付参数后,然后通过Android/iOS客户端的SDK调用支付功能
payParam, err := client.AliPayTradeAppPay(bm)

//商家使用扫码枪等条码识别设备扫描用户支付宝钱包上的条码/二维码,完成收款
aliRsp, err := client.AliPayTradePay(bm)

//支付宝小程序支付时 buyer_id 为必传参数,需要提前获取,获取方法如下两种
//    1、gopay.AliPaySystemOauthToken()     返回取值:rsp.AliPaySystemOauthTokenResponse.UserId
//    2、client.AliPaySystemOauthToken()    返回取值:aliRsp.AliPaySystemOauthTokenResponse.UserId
aliRsp, err := client.AliPayTradeCreate(bm)

aliRsp, err := client.AliPayTradeQuery(bm)
aliRsp, err := client.AliPayTradeClose(bm)
aliRsp, err := client.AliPayTradeCancel(bm)
aliRsp, err := client.AliPayTradeRefund(bm)
aliRsp, err := client.AliPayTradePageRefund(bm)
aliRsp, err := client.AliPayTradeFastPayRefundQuery(bm)
aliRsp, err := client.AliPayTradeOrderSettle(bm)
aliRsp, err := client.AliPayTradePrecreate(bm)
aliRsp, err := client.AlipayFundTransToaccountTransfer(bm)
aliRsp, err := client.AliPaySystemOauthToken(bm)
aliRsp, err := client.AliPayOpenAuthTokenApp(bm)
aliRsp, err := client.ZhimaCreditScoreGet(bm)
aliRsp, err := client.AliPayUserCertifyOpenInit(bm)
aliRsp, err := client.AliPayUserCertifyOpenCertify(bm)
aliRsp, err := client.AliPayUserCertifyOpenQuery(bm)

4、微信统一下单后,获取微信小程序支付、APP支付、微信内H5支付所需要的 paySign

  • 微信(只有微信需要此操作)

微信小程序支付官方文档:微信小程序支付API

APP支付官方文档:APP端调起支付的参数列表文档

微信内H5支付官方文档:微信内H5支付文档

//====微信小程序 paySign====
timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
prepayId := "prepay_id=" + wxRsp.PrepayId   //此处的 wxRsp.PrepayId ,统一下单成功后得到
//获取微信小程序支付的 paySign
//    appId:APPID
//    nonceStr:随机字符串
//    prepayId:统一下单成功后得到的值
//    signType:签名方式,务必与统一下单时用的签名方式一致
//    timeStamp:时间
//    apiKey:API秘钥值
paySign := gopay.GetMiniPaySign(AppID, wxRsp.NonceStr, prepayId, gopay.SignType_MD5, timeStamp, apiKey)

//====APP支付 paySign====
timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
//获取APP支付的 paySign
//注意:package 参数因为是固定值,无需开发者再传入
//    appId:APPID
//    partnerid:partnerid
//    nonceStr:随机字符串
//    prepayId:统一下单成功后得到的值
//    signType:签名方式,务必与统一下单时用的签名方式一致
//    timeStamp:时间
//    apiKey:API秘钥值
paySign := gopay.GetAppPaySign(appid, partnerid, wxRsp.NonceStr, wxRsp.PrepayId, gopay.SignType_MD5, timeStamp, apiKey)

//====微信内H5支付 paySign====
timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
packages := "prepay_id=" + wxRsp.PrepayId   //此处的 wxRsp.PrepayId ,统一下单成功后得到
//获取微信内H5支付 paySign
//    appId:APPID
//    nonceStr:随机字符串
//    packages:统一下单成功后拼接得到的值
//    signType:签名方式,务必与统一下单时用的签名方式一致
//    timeStamp:时间
//    apiKey:API秘钥值
paySign := gopay.GetMiniPaySign(AppID, wxRsp.NonceStr, packages, gopay.SignType_MD5, timeStamp, apiKey)

5、同步返回参数验签Sign、异步通知参数解析和验签Sign、异步通知返回

异步参数需要先解析,解析出来的结构体或BodyMap再验签

Echo Web框架,有兴趣的可以尝试一下

异步通知处理完后,需回复平台固定数据

  • 微信
//====同步返回参数验签Sign====
wxRsp, err := client.UnifiedOrder(bm)
// 微信同步返回参数验签或异步通知参数验签
//    apiKey:API秘钥值
//    signType:签名类型(调用API方法时填写的类型)
//    bean:微信同步返回的结构体 wxRsp 或 异步通知解析的结构体 notifyReq
//    返回参数 ok:是否验签通过
//    返回参数 err:错误信息
ok, err := gopay.VerifyWeChatSign(apiKey, gopay.SignType_MD5, wxRsp)

//====支付异步通知参数解析和验签Sign====
// 解析支付异步通知的参数
//    req:*http.Request
//    返回参数 notifyReq:通知的参数
//    返回参数 err:错误信息
notifyReq, err := gopay.ParseWeChatNotifyResult(c.Request())    //c.Request()是 echo 框架的获取 *http.Request 的写法
//验签操作
ok, err := gopay.VerifyWeChatSign(apiKey, gopay.SignType_MD5, notifyReq)

//====退款异步通知参数解析,退款通知无sign,不用验签====
// 
// 解析退款异步通知的参数,解析出来的 req_info 是加密数据,需解密
//    req:*http.Request
//    返回参数 notifyReq:通知的参数
//    返回参数 err:错误信息
notifyReq, err := gopay.ParseWeChatRefundNotifyResult(c.Request())

//==解密退款异步通知的加密参数 req_info ==
refundNotify, err := gopay.DecryptRefundNotifyReqInfo(notifyReq.ReqInfo, apiKey)

//==异步通知,返回给微信平台的信息==
rsp := new(gopay.WeChatNotifyResponse) //回复微信的数据
rsp.ReturnCode = gopay.SUCCESS
rsp.ReturnMsg = gopay.OK
return c.String(http.StatusOK, rsp.ToXmlString())   //此写法是 echo 框架返回客户端数据的写法
  • 支付宝

注意:APP支付、手机网站支付、电脑网站支付 暂不支持同步返回验签

支付宝支付后的同步/异步通知验签文档:支付结果通知

//====同步返回参数验签Sign====
aliRsp, err := client.AliPayTradePay(bm)
//支付宝同步返回验签
//    注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签
//    aliPayPublicKey:支付宝公钥
//    signData:待验签参数,aliRsp.SignData
//    sign:待验签sign,aliRsp.Sign
//    返回参数ok:是否验签通过
//    返回参数err:错误信息
ok, err := gopay.VerifyAliPaySyncSign(aliPayPublicKey, aliRsp.SignData, aliRsp.Sign)

//====异步通知参数解析和验签Sign====
//解析异步通知的参数
//    req:*http.Request
//    返回参数 notifyReq:通知的参数
//    返回参数 err:错误信息
notifyReq, err = gopay.ParseAliPayNotifyResult(c.Request())     //c.Request()是 echo 框架的获取
//验签操作
ok, err = gopay.VerifyAliPaySign(aliPayPublicKey, notifyReq)

//==异步通知,返回支付宝平台的信息==
//    文档:https://docs.open.alipay.com/203/105286
//    程序执行完后必须打印输出“success”(不包含引号)。如果商户反馈给支付宝的字符不是success这7个字符,支付宝服务器会不断重发通知,直到超过24小时22分钟。一般情况下,25小时以内完成8次通知(通知的间隔频率一般是:4m,10m,10m,1h,2h,6h,15h)
return c.String(http.StatusOK, "success")   //此写法是 echo 框架返回客户端数据的写法

6、微信、支付宝 公共API(仅部分说明)

  • 微信 公共API

官方文档:code2Session

button按钮获取手机号码:button组件文档

微信解密算法文档:解密算法文档

//获取微信小程序用户的OpenId、SessionKey、UnionId
//    appId:微信小程序的APPID
//    appSecret:微信小程序的AppSecret
//    wxCode:小程序调用wx.login 获取的code
sessionRsp, err := gopay.Code2Session(appId, appSecret, wxCode)

//====解密微信加密数据到指定结构体====

//小程序获取手机号
data := "Kf3TdPbzEmhWMuPKtlKxIWDkijhn402w1bxoHL4kLdcKr6jT1jNcIhvDJfjXmJcgDWLjmBiIGJ5acUuSvxLws3WgAkERmtTuiCG10CKLsJiR+AXVk7B2TUQzsq88YVilDz/YAN3647REE7glGmeBPfvUmdbfDzhL9BzvEiuRhABuCYyTMz4iaM8hFjbLB1caaeoOlykYAFMWC5pZi9P8uw=="
iv := "Cds8j3VYoGvnTp1BrjXdJg=="
session := "lyY4HPQbaOYzZdG+JcYK9w=="
phone := new(gopay.WeChatUserPhone)
//解密开放数据
//    encryptedData:包括敏感数据在内的完整用户信息的加密数据,小程序获取到
//    iv:加密算法的初始向量,小程序获取到
//    sessionKey:会话密钥,通过 gopay.Code2Session() 方法获取到
//    beanPtr:需要解析到的结构体指针,操作完后,声明的结构体会被赋值
err := gopay.DecryptWeChatOpenDataToStruct(data, iv, session, phone)
fmt.Println(*phone)
//获取微信小程序用户信息
sessionKey := "tiihtNczf5v6AKRyjwEUhQ=="
encryptedData := "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=="
iv2 := "r7BXXKkLb8qrSNn05n0qiA=="

//微信小程序 用户信息
userInfo := new(gopay.WeChatAppletUserInfo)
err = gopay.DecryptWeChatOpenDataToStruct(encryptedData, iv2, sessionKey, userInfo)
fmt.Println(*userInfo)

data := "Kf3TdPbzEmhWMuPKtlKxIWDkijhn402w1bxoHL4kLdcKr6jT1jNcIhvDJfjXmJcgDWLjmBiIGJ5acUuSvxLws3WgAkERmtTuiCG10CKLsJiR+AXVk7B2TUQzsq88YVilDz/YAN3647REE7glGmeBPfvUmdbfDzhL9BzvEiuRhABuCYyTMz4iaM8hFjbLB1caaeoOlykYAFMWC5pZi9P8uw=="
iv := "Cds8j3VYoGvnTp1BrjXdJg=="
session := "lyY4HPQbaOYzZdG+JcYK9w=="
    
//解密开放数据到 BodyMap
//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
//    iv:加密算法的初始向量
//    sessionKey:会话密钥
bm, err := gopay.DecryptWeChatOpenDataToBodyMap(data, iv, session)
if err != nil {
     fmt.Println("err:", err)
     return
}
fmt.Println("WeChatUserPhone:", bm)
  • 支付宝 公共API

支付宝换取授权访问令牌文档:换取授权访问令牌

获取用户手机号文档:获取用户手机号

支付宝加解密文档:AES配置文档AES加解密文档

//换取授权访问令牌(默认使用utf-8,RSA2)
//    appId:应用ID
//    privateKey:应用私钥
//    grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取
//    codeOrToken:支付宝授权码或refresh_token
rsp, err := gopay.AlipaySystemOauthToken(appId, privateKey, grantType, codeOrToken)

//解密支付宝开放数据带到指定结构体
//    以小程序获取手机号为例
phone := new(gopay.AliPayUserPhone)
//解密支付宝开放数据
//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
//    secretKey:AES密钥,支付宝管理平台配置
//    beanPtr:需要解析到的结构体指针
err := gopay.DecryptAliPayOpenDataToStruct(encryptedData, secretKey, phone)
fmt.Println(*phone)

开源不易,讲究的朋友可以给个赞赏

微信: 支付宝:

License

Copyright 2019 Jerry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

View Source
const (
	TimeLayout string = "2006-01-02 15:04:05"
	DateLayout string = "2006-01-02"
	Version    string = "1.4.6"

	// 境外国家地区
	China         Country = 1 // 中国国内
	China2        Country = 2 // 中国国内(冗灾方案)
	SoutheastAsia Country = 3 // 东南亚
	Other         Country = 4 // 其他国家

	// 支付类型
	TradeType_Mini   = "JSAPI"
	TradeType_JsApi  = "JSAPI"
	TradeType_App    = "APP"
	TradeType_H5     = "MWEB"
	TradeType_Native = "NATIVE"

	// 签名方式
	SignType_MD5         = "MD5"
	SignType_HMAC_SHA256 = "HMAC-SHA256"
)
View Source
const (
	POST           = "POST"
	GET            = "GET"
	TypeJSON       = "json"
	TypeXML        = "xml"
	TypeUrlencoded = "urlencoded"
	TypeForm       = "form"
	TypeFormData   = "form-data"
)
View Source
const (
	SUCCESS = "SUCCESS"
	FAIL    = "FAIL"
	OK      = "OK"
)

Variables

View Source
var Types = map[string]string{
	TypeJSON:       "application/json",
	TypeXML:        "application/xml",
	TypeForm:       "application/x-www-form-urlencoded",
	TypeFormData:   "application/x-www-form-urlencoded",
	TypeUrlencoded: "application/x-www-form-urlencoded",
}

Functions

func DecryptAliPayOpenDataToStruct added in v1.4.7

func DecryptAliPayOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{}) (err error)

DecryptAliPayOpenDataToStruct 解密支付宝开放数据到 结构体

encryptedData:包括敏感数据在内的完整用户信息的加密数据
secretKey:AES密钥,支付宝管理平台配置
beanPtr:需要解析到的结构体指针
文档:https://docs.alipay.com/mini/introduce/aes
文档:https://docs.open.alipay.com/common/104567

func DecryptWeChatOpenDataToStruct added in v1.4.7

func DecryptWeChatOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr interface{}) (err error)

解密开放数据到结构体

encryptedData:包括敏感数据在内的完整用户信息的加密数据,小程序获取到
iv:加密算法的初始向量,小程序获取到
sessionKey:会话密钥,通过  gopay.Code2Session() 方法获取到
beanPtr:需要解析到的结构体指针,操作完后,声明的结构体会被赋值
文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

func Float32ToString

func Float32ToString(floatNum float32, prec ...int) (floatStr string)

Float32转字符串

floatNum:float32数字
prec:精度位数(不传则默认float数字精度)

func Float64ToString

func Float64ToString(floatNum float64, prec ...int) (floatStr string)

Float64转字符串

floatNum:float64数字
prec:精度位数(不传则默认float数字精度)

func FormatAliPayPublicKey added in v1.1.1

func FormatAliPayPublicKey(publicKey string) (pKey string)

FormatAliPayPublicKey 格式化 普通支付宝公钥

func FormatAliPayURLParam added in v1.1.1

func FormatAliPayURLParam(body BodyMap) (urlParam string)

格式化请求URL参数

func FormatPrivateKey added in v1.1.1

func FormatPrivateKey(privateKey string) (pKey string)

FormatPrivateKey 格式化 普通应用秘钥

func GetAppPaySign added in v1.1.0

func GetAppPaySign(appid, partnerid, noncestr, prepayid, signType, timestamp, apiKey string) (paySign string)

APP支付,统一下单获取支付参数后,再次计算APP支付所需要的的sign

appId:APPID
partnerid:partnerid
nonceStr:随即字符串
prepayId:统一下单成功后得到的值
signType:此处签名方式,务必与统一下单时用的签名方式一致
timeStamp:时间
ApiKey:API秘钥值
APP支付官方文档:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12

func GetCertSN added in v1.4.7

func GetCertSN(certPath string) (sn string, err error)

GetCertSN 获取证书序列号SN

certPath:X.509证书文件路径(appCertPublicKey.crt、alipayRootCert.crt、alipayCertPublicKey_RSA2)
返回 sn:证书序列号(app_cert_sn、alipay_root_cert_sn、alipay_cert_sn)
返回 err:error 信息

func GetH5PaySign added in v1.0.5

func GetH5PaySign(appId, nonceStr, packages, signType, timeStamp, apiKey string) (paySign string)

微信内H5支付,统一下单获取支付参数后,再次计算出微信内H5支付需要用的paySign

appId:APPID
nonceStr:随即字符串
packages:统一下单成功后拼接得到的值
signType:签名类型
timeStamp:时间
ApiKey:API秘钥值
微信内H5支付官方文档:https://pay.weixin.qq.com/wiki/doc/api/external/jsapi.php?chapter=7_7&index=6

func GetMiniPaySign

func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string)

JSAPI支付,统一下单获取支付参数后,再次计算出小程序用的paySign

appId:APPID
nonceStr:随即字符串
prepayId:统一下单成功后得到的值
signType:签名类型
timeStamp:时间
ApiKey:API秘钥值
微信小程序支付API:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html
微信小程序支付PaySign计算文档:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=3

func GetRandomString

func GetRandomString(length int) string

获取随机字符串

length:字符串长度

func GetWeChatParamSign added in v1.4.7

func GetWeChatParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string)

获取微信支付所需参数里的Sign值(通过支付参数计算Sign值)

注意:BodyMap中如无 sign_type 参数,默认赋值 sign_type 为 MD5
appId:应用ID
mchId:商户ID
ApiKey:API秘钥值
返回参数 sign:通过Appid、MchId、ApiKey和BodyMap中的参数计算出的Sign值

func GetWeChatSanBoxParamSign added in v1.4.7

func GetWeChatSanBoxParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string, err error)

获取微信支付沙箱环境所需参数里的Sign值(通过支付参数计算Sign值)

注意:沙箱环境默认 sign_type 为 MD5
appId:应用ID
mchId:商户ID
ApiKey:API秘钥值
返回参数 sign:通过Appid、MchId、ApiKey和BodyMap中的参数计算出的Sign值

func Int2String

func Int2String(intNum int) (intStr string)

Int转字符串

func Int322String added in v1.4.7

func Int322String(intNum int32) (int32Str string)

Int32转字符串

func Int642String

func Int642String(intNum int64) (int64Str string)

Int64转字符串

func PKCS5UnPadding added in v1.4.7

func PKCS5UnPadding(origData []byte) (bs []byte)

解密填充模式(去除补全码) PKCS5UnPadding 解密时,需要在最后面去掉加密时添加的填充byte

func PKCS7UnPadding added in v1.0.7

func PKCS7UnPadding(origData []byte) (bs []byte)

解密填充模式(去除补全码) PKCS7UnPadding 解密时,需要在最后面去掉加密时添加的填充byte

func ParseDateTime

func ParseDateTime(timeStr string) (datetime time.Time)

解析时间

func String2Float32 added in v1.4.7

func String2Float32(floatStr string) (floatNum float32)

字符串转Float32

func String2Float64 added in v1.4.7

func String2Float64(floatStr string) (floatNum float64)

字符串转Float64

func String2Int

func String2Int(intStr string) (intNum int)

字符串转Int

func String2Int32 added in v1.4.7

func String2Int32(intStr string) (int32Num int32)

字符串转Int32

func String2Int64

func String2Int64(intStr string) (int64Num int64)

字符串转Int64

func VerifyAliPaySign added in v1.4.7

func VerifyAliPaySign(aliPayPublicKey string, bean interface{}) (ok bool, err error)

VerifyAliPaySign 支付宝异步通知验签

注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签
aliPayPublicKey:支付宝公钥
bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm
返回参数ok:是否验签通过
返回参数err:错误信息
验签文档:https://docs.open.alipay.com/200/106120

func VerifyAliPaySyncSign added in v1.4.7

func VerifyAliPaySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error)

VerifyAliPaySyncSign 支付宝同步返回验签

注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签
aliPayPublicKey:支付宝公钥
signData:待验签参数,aliRsp.SignData
sign:待验签sign,aliRsp.Sign
返回参数ok:是否验签通过
返回参数err:错误信息
验签文档:https://docs.open.alipay.com/200/106120

func VerifyWeChatSign added in v1.4.7

func VerifyWeChatSign(apiKey, signType string, bean interface{}) (ok bool, err error)

微信同步返回参数验签或异步通知参数验签

ApiKey:API秘钥值
signType:签名类型(调用API方法时填写的类型)
bean:微信同步返回的结构体 wxRsp 或 异步通知解析的结构体 notifyReq
返回参数ok:是否验签通过
返回参数err:错误信息

Types

type AccessToken added in v1.0.7

type AccessToken struct {
	AccessToken string `json:"access_token,omitempty"` // 获取到的凭证
	ExpiresIn   int    `json:"expires_in,omitempty"`   // SessionKey超时时间(秒)
	Errcode     int    `json:"errcode,omitempty"`      // 错误码
	Errmsg      string `json:"errmsg,omitempty"`       // 错误信息
}

func GetWeChatAppletAccessToken added in v1.4.7

func GetWeChatAppletAccessToken(appId, appSecret string) (accessToken *AccessToken, err error)

获取微信小程序全局唯一后台接口调用凭据(AccessToken:157字符)

appId:APPID
appSecret:AppSecret
获取access_token文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html

type AliPayClient added in v1.4.7

type AliPayClient struct {
	AppId              string
	PrivateKey         string
	AppCertSN          string
	AliPayPublicCertSN string
	AliPayRootCertSN   string
	ReturnUrl          string
	NotifyUrl          string
	Charset            string
	SignType           string
	AppAuthToken       string
	AuthToken          string
	IsProd             bool
	// contains filtered or unexported fields
}

func NewAliPayClient added in v1.1.1

func NewAliPayClient(appId, privateKey string, isProd bool) (client *AliPayClient)

初始化支付宝客户端

注意:如果使用支付宝公钥证书验签,请设置 支付宝根证书SN(client.SetAlipayRootCertSN())、应用公钥证书SN(client.SetAppCertSN())
appId:应用ID
PrivateKey:应用私钥
IsProd:是否是正式环境

func (*AliPayClient) AliPayFundTransToaccountTransfer added in v1.4.7

func (a *AliPayClient) AliPayFundTransToaccountTransfer(body BodyMap) (aliRsp *AliPayFundTransToaccountTransferResponse, err error)

alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口)

文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer

func (*AliPayClient) AliPayOpenAuthTokenApp added in v1.4.7

func (a *AliPayClient) AliPayOpenAuthTokenApp(body BodyMap) (aliRsp *AliPayOpenAuthTokenAppResponse, err error)

alipay.open.auth.token.app(换取应用授权令牌)

文档地址:https://docs.open.alipay.com/api_9/alipay.open.auth.token.app

func (*AliPayClient) AliPaySystemOauthToken added in v1.4.7

func (a *AliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySystemOauthTokenResponse, err error)

alipay.system.oauth.token(换取授权访问令牌)

文档地址:https://docs.open.alipay.com/api_9/alipay.system.oauth.token

func (*AliPayClient) AliPayTradeAppPay added in v1.4.7

func (a *AliPayClient) AliPayTradeAppPay(body BodyMap) (payParam string, err error)

alipay.trade.app.pay(app支付接口2.0)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.app.pay

func (*AliPayClient) AliPayTradeCancel added in v1.4.7

func (a *AliPayClient) AliPayTradeCancel(body BodyMap) (aliRsp *AliPayTradeCancelResponse, err error)

alipay.trade.cancel(统一收单交易撤销接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.cancel

func (*AliPayClient) AliPayTradeClose added in v1.4.7

func (a *AliPayClient) AliPayTradeClose(body BodyMap) (aliRsp *AliPayTradeCloseResponse, err error)

alipay.trade.close(统一收单交易关闭接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.close

func (*AliPayClient) AliPayTradeCreate added in v1.4.7

func (a *AliPayClient) AliPayTradeCreate(body BodyMap) (aliRsp *AliPayTradeCreateResponse, err error)

alipay.trade.create(统一收单交易创建接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.create

func (*AliPayClient) AliPayTradeFastPayRefundQuery added in v1.4.7

func (a *AliPayClient) AliPayTradeFastPayRefundQuery(body BodyMap) (aliRsp *AliPayTradeFastpayRefundQueryResponse, err error)

alipay.trade.fastpay.refund.query(统一收单交易退款查询)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query

func (*AliPayClient) AliPayTradeOrderSettle added in v1.4.7

func (a *AliPayClient) AliPayTradeOrderSettle(body BodyMap) (aliRsp *AliPayTradeOrderSettleResponse, err error)

alipay.trade.order.settle(统一收单交易结算接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.order.settle

func (*AliPayClient) AliPayTradeOrderinfoSync added in v1.4.7

func (a *AliPayClient) AliPayTradeOrderinfoSync(body BodyMap)

alipay.trade.orderinfo.sync(支付宝订单信息同步接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.orderinfo.sync

func (*AliPayClient) AliPayTradePagePay added in v1.4.7

func (a *AliPayClient) AliPayTradePagePay(body BodyMap) (payUrl string, err error)

alipay.trade.page.pay(统一收单下单并支付页面接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.pay

func (*AliPayClient) AliPayTradePageRefund added in v1.4.7

func (a *AliPayClient) AliPayTradePageRefund(body BodyMap) (aliRsp *AliPayTradePageRefundResponse, err error)

alipay.trade.refund(统一收单退款页面接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.refund

func (*AliPayClient) AliPayTradePay added in v1.4.7

func (a *AliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayResponse, err error)

alipay.trade.pay(统一收单交易支付接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.pay

func (*AliPayClient) AliPayTradePrecreate added in v1.4.7

func (a *AliPayClient) AliPayTradePrecreate(body BodyMap) (aliRsp *AliPayTradePrecreateResponse, err error)

alipay.trade.precreate(统一收单线下交易预创建)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.precreate

func (*AliPayClient) AliPayTradeQuery added in v1.4.7

func (a *AliPayClient) AliPayTradeQuery(body BodyMap) (aliRsp *AliPayTradeQueryResponse, err error)

alipay.trade.query(统一收单线下交易查询)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.query

func (*AliPayClient) AliPayTradeRefund added in v1.4.7

func (a *AliPayClient) AliPayTradeRefund(body BodyMap) (aliRsp *AliPayTradeRefundResponse, err error)

alipay.trade.refund(统一收单交易退款接口)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.refund

func (*AliPayClient) AliPayTradeWapPay added in v1.4.7

func (a *AliPayClient) AliPayTradeWapPay(body BodyMap) (payUrl string, err error)

alipay.trade.wap.pay(手机网站支付接口2.0)

文档地址:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay

func (*AliPayClient) AliPayUserCertifyOpenCertify added in v1.4.7

func (a *AliPayClient) AliPayUserCertifyOpenCertify(body BodyMap) (certifyUrl string, err error)

alipay.user.certify.open.certify(身份认证开始认证)

API文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.certify
产品文档地址:https://docs.open.alipay.com/20181012100420932508/quickstart

func (*AliPayClient) AliPayUserCertifyOpenInit added in v1.4.7

func (a *AliPayClient) AliPayUserCertifyOpenInit(body BodyMap) (aliRsp *AliPayUserCertifyOpenInitResponse, err error)

alipay.user.certify.open.initialize(身份认证初始化服务)

文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.initialize

func (*AliPayClient) AliPayUserCertifyOpenQuery added in v1.4.7

func (a *AliPayClient) AliPayUserCertifyOpenQuery(body BodyMap) (aliRsp *AliPayUserCertifyOpenQueryResponse, err error)

alipay.user.certify.open.query(身份认证记录查询)

文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.query

func (*AliPayClient) AliPayUserInfoShare added in v1.4.7

func (a *AliPayClient) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareResponse, err error)

alipay.user.info.share(支付宝会员授权信息查询接口)

body:此接口无需body参数
文档地址:https://docs.open.alipay.com/api_2/alipay.user.info.share

func (*AliPayClient) SetAliPayPublicCertSN added in v1.4.7

func (a *AliPayClient) SetAliPayPublicCertSN(aliPayPublicCertSN string) (client *AliPayClient)

设置 支付宝公钥证书SN

aliPayPublicCertSN:支付宝公钥证书SN,通过 gopay.GetCertSN() 获取

func (*AliPayClient) SetAliPayPublicCertSnByPath added in v1.4.7

func (a *AliPayClient) SetAliPayPublicCertSnByPath(aliPayPublicCertPath string) (client *AliPayClient, err error)

设置 alipay_cert_sn 通过 支付宝公钥证书文件路径

aliPayPublicCertPath:支付宝公钥证书文件路径

func (*AliPayClient) SetAliPayRootCertSN added in v1.4.7

func (a *AliPayClient) SetAliPayRootCertSN(aliPayRootCertSN string) (client *AliPayClient)

设置 支付宝CA根证书SN

aliPayRootCertSN:支付宝CA根证书SN,通过 gopay.GetCertSN() 获取

func (*AliPayClient) SetAliPayRootCertSnByPath added in v1.4.7

func (a *AliPayClient) SetAliPayRootCertSnByPath(aliPayRootCertPath string) (client *AliPayClient, err error)

设置 alipay_root_cert_sn 通过支付宝CA根证书文件路径

aliPayRootCertPath:支付宝CA根证书文件路径

func (*AliPayClient) SetAppAuthToken added in v1.4.7

func (a *AliPayClient) SetAppAuthToken(appAuthToken string) (client *AliPayClient)

设置应用授权

func (*AliPayClient) SetAppCertSN added in v1.4.7

func (a *AliPayClient) SetAppCertSN(appCertSN string) (client *AliPayClient)

设置 应用公钥证书SN

appCertSN:应用公钥证书SN,通过 gopay.GetCertSN() 获取

func (*AliPayClient) SetAppCertSnByPath added in v1.4.7

func (a *AliPayClient) SetAppCertSnByPath(appCertPath string) (client *AliPayClient, err error)

设置 app_cert_sn 通过应用公钥证书路径

appCertPath:应用公钥证书路径

func (*AliPayClient) SetAuthToken added in v1.4.7

func (a *AliPayClient) SetAuthToken(authToken string) (client *AliPayClient)

设置用户信息授权

func (*AliPayClient) SetCharset added in v1.4.7

func (a *AliPayClient) SetCharset(charset string) (client *AliPayClient)

设置编码格式,如utf-8,gbk,gb2312等,默认推荐使用 utf-8

func (*AliPayClient) SetNotifyUrl added in v1.4.7

func (a *AliPayClient) SetNotifyUrl(url string) (client *AliPayClient)

设置支付宝服务器主动通知商户服务器里指定的页面http/https路径。

func (*AliPayClient) SetReturnUrl added in v1.4.7

func (a *AliPayClient) SetReturnUrl(url string) (client *AliPayClient)

设置支付后的ReturnUrl

func (*AliPayClient) SetSignType added in v1.4.7

func (a *AliPayClient) SetSignType(signType string) (client *AliPayClient)

设置签名算法类型,目前支持RSA2和RSA,默认推荐使用 RSA2

func (*AliPayClient) ZhimaCreditScoreGet added in v1.4.7

func (a *AliPayClient) ZhimaCreditScoreGet(body BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error)

zhima.credit.score.get(芝麻分)

文档地址:https://docs.open.alipay.com/api_8/zhima.credit.score.get

type AliPayFundTransToaccountTransferResponse added in v1.4.7

type AliPayFundTransToaccountTransferResponse struct {
	Response     *transToaccountTransferResponse `json:"alipay_fund_trans_toaccount_transfer_response,omitempty"`
	AliPayCertSn string                          `json:"alipay_cert_sn,omitempty"`
	SignData     string                          `json:"-"`
	Sign         string                          `json:"sign"`
}

===================================================

type AliPayNotifyRequest added in v1.1.2

type AliPayNotifyRequest struct {
	NotifyTime        string                   `json:"notify_time,omitempty"`
	NotifyType        string                   `json:"notify_type,omitempty"`
	NotifyId          string                   `json:"notify_id,omitempty"`
	AppId             string                   `json:"app_id,omitempty"`
	Charset           string                   `json:"charset,omitempty"`
	Version           string                   `json:"version,omitempty"`
	SignType          string                   `json:"sign_type,omitempty"`
	Sign              string                   `json:"sign,omitempty"`
	AuthAppId         string                   `json:"auth_app_id,omitempty"`
	TradeNo           string                   `json:"trade_no,omitempty"`
	OutTradeNo        string                   `json:"out_trade_no,omitempty"`
	OutBizNo          string                   `json:"out_biz_no,omitempty"`
	BuyerId           string                   `json:"buyer_id,omitempty"`
	BuyerLogonId      string                   `json:"buyer_logon_id,omitempty"`
	SellerId          string                   `json:"seller_id,omitempty"`
	SellerEmail       string                   `json:"seller_email,omitempty"`
	TradeStatus       string                   `json:"trade_status,omitempty"`
	TotalAmount       string                   `json:"total_amount,omitempty"`
	ReceiptAmount     string                   `json:"receipt_amount,omitempty"`
	InvoiceAmount     string                   `json:"invoice_amount,omitempty"`
	BuyerPayAmount    string                   `json:"buyer_pay_amount,omitempty"`
	PointAmount       string                   `json:"point_amount,omitempty"`
	RefundFee         string                   `json:"refund_fee,omitempty"`
	Subject           string                   `json:"subject,omitempty"`
	Body              string                   `json:"body,omitempty"`
	GmtCreate         string                   `json:"gmt_create,omitempty"`
	GmtPayment        string                   `json:"gmt_payment,omitempty"`
	GmtRefund         string                   `json:"gmt_refund,omitempty"`
	GmtClose          string                   `json:"gmt_close,omitempty"`
	FundBillList      []*fundBillListInfo      `json:"fund_bill_list,omitempty"`
	PassbackParams    string                   `json:"passback_params,omitempty"`
	VoucherDetailList []*voucherDetailListInfo `json:"voucher_detail_list,omitempty"`
	Method            string                   `json:"method,omitempty"`    //电脑网站支付 支付宝请求 return_url 同步返回参数
	Timestamp         string                   `json:"timestamp,omitempty"` //电脑网站支付 支付宝请求 return_url 同步返回参数
}

func ParseAliPayNotifyResult added in v1.1.2

func ParseAliPayNotifyResult(req *http.Request) (notifyReq *AliPayNotifyRequest, err error)

解析支付宝支付异步通知的参数到Struct

req:*http.Request
返回参数notifyReq:Notify请求的参数
返回参数err:错误信息
文档:https://docs.open.alipay.com/203/105286/

type AliPayOpenAuthTokenAppResponse added in v1.4.7

type AliPayOpenAuthTokenAppResponse struct {
	Response     *authTokenAppResponse `json:"alipay_open_auth_token_app_response,omitempty"`
	AliPayCertSn string                `json:"alipay_cert_sn,omitempty"`
	SignData     string                `json:"-"`
	Sign         string                `json:"sign"`
}

===================================================

type AliPaySystemOauthTokenResponse added in v1.4.7

type AliPaySystemOauthTokenResponse struct {
	Response      *oauthTokenInfo `json:"alipay_system_oauth_token_response,omitempty"`
	ErrorResponse *struct {
		Code    string `json:"code,omitempty"`
		Msg     string `json:"msg,omitempty"`
		SubCode string `json:"sub_code,omitempty"`
		SubMsg  string `json:"sub_msg,omitempty"`
	} `json:"error_response,omitempty"`
	AliPayCertSn string `json:"alipay_cert_sn,omitempty"`
	SignData     string `json:"-"`
	Sign         string `json:"sign"`
}

===================================================

func AliPaySystemOauthToken added in v1.4.7

func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (rsp *AliPaySystemOauthTokenResponse, err error)

AliPaySystemOauthToken 换取授权访问令牌(默认使用utf-8,RSA2)

appId:应用ID
PrivateKey:应用私钥
grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取
codeOrToken:支付宝授权码或refresh_token
文档:https://docs.open.alipay.com/api_9/alipay.system.oauth.token

type AliPayTradeCancelResponse added in v1.1.8

type AliPayTradeCancelResponse struct {
	Response     *cancelResponse `json:"alipay_trade_cancel_response,omitempty"`
	AliPayCertSn string          `json:"alipay_cert_sn,omitempty"`
	SignData     string          `json:"-"`
	Sign         string          `json:"sign"`
}

===================================================

type AliPayTradeCloseResponse added in v1.1.8

type AliPayTradeCloseResponse struct {
	Response *closeResponse `json:"alipay_trade_close_response,omitempty"`
	SignData string         `json:"-"`
	Sign     string         `json:"sign"`
}

===================================================

type AliPayTradeCreateResponse added in v1.1.8

type AliPayTradeCreateResponse struct {
	Response *createResponse `json:"alipay_trade_create_response,omitempty"`
	SignData string          `json:"-"`
	Sign     string          `json:"sign"`
}

===================================================

type AliPayTradeFastpayRefundQueryResponse added in v1.4.7

type AliPayTradeFastpayRefundQueryResponse struct {
	Response     *refundQueryResponse `json:"alipay_trade_fastpay_refund_query_response,omitempty"`
	AliPayCertSn string               `json:"alipay_cert_sn,omitempty"`
	SignData     string               `json:"-"`
	Sign         string               `json:"sign"`
}

===================================================

type AliPayTradeOrderSettleResponse added in v1.4.7

type AliPayTradeOrderSettleResponse struct {
	Response     *orderSettleResponse `json:"alipay_trade_order_settle_response,omitempty"`
	AliPayCertSn string               `json:"alipay_cert_sn,omitempty"`
	SignData     string               `json:"-"`
	Sign         string               `json:"sign"`
}

===================================================

type AliPayTradePageRefundResponse added in v1.4.7

type AliPayTradePageRefundResponse struct {
	Response     *pageRefundResponse `json:"alipay_trade_page_refund_response,omitempty"`
	AliPayCertSn string              `json:"alipay_cert_sn,omitempty"`
	SignData     string              `json:"-"`
	Sign         string              `json:"sign"`
}

===================================================

type AliPayTradePayResponse added in v1.1.8

type AliPayTradePayResponse struct {
	Response *payResponse `json:"alipay_trade_pay_response,omitempty"`
	SignData string       `json:"-"`
	Sign     string       `json:"sign"`
}

===================================================

type AliPayTradePrecreateResponse added in v1.4.7

type AliPayTradePrecreateResponse struct {
	Response     *precreateResponse `json:"alipay_trade_precreate_response,omitempty"`
	AliPayCertSn string             `json:"alipay_cert_sn,omitempty"`
	SignData     string             `json:"-"`
	Sign         string             `json:"sign"`
}

===================================================

type AliPayTradeQueryResponse added in v1.1.8

type AliPayTradeQueryResponse struct {
	Response *queryResponse `json:"alipay_trade_query_response,omitempty"`
	SignData string         `json:"-"`
	Sign     string         `json:"sign"`
}

===================================================

type AliPayTradeRefundResponse added in v1.4.7

type AliPayTradeRefundResponse struct {
	Response     *refundResponse `json:"alipay_trade_refund_response,omitempty"`
	AliPayCertSn string          `json:"alipay_cert_sn,omitempty"`
	SignData     string          `json:"-"`
	Sign         string          `json:"sign"`
}

===================================================

type AliPayUserCertifyOpenCertifyResponse added in v1.4.7

type AliPayUserCertifyOpenCertifyResponse struct {
	Response     *userCertifyOpenCertifyResponse `json:"alipay_user_certify_open_certify_response,omitempty"`
	AliPayCertSn string                          `json:"alipay_cert_sn,omitempty"`
	SignData     string                          `json:"-"`
	Sign         string                          `json:"sign"`
}

===================================================

type AliPayUserCertifyOpenInitResponse added in v1.4.7

type AliPayUserCertifyOpenInitResponse struct {
	Response     *userCertifyOpenInitResponse `json:"alipay_user_certify_open_initialize_response,omitempty"`
	AliPayCertSn string                       `json:"alipay_cert_sn,omitempty"`
	SignData     string                       `json:"-"`
	Sign         string                       `json:"sign"`
}

===================================================

type AliPayUserCertifyOpenQueryResponse added in v1.4.7

type AliPayUserCertifyOpenQueryResponse struct {
	Response     *userCertifyOpenQueryResponse `json:"alipay_user_certify_open_query_response,omitempty"`
	AliPayCertSn string                        `json:"alipay_cert_sn,omitempty"`
	SignData     string                        `json:"-"`
	Sign         string                        `json:"sign"`
}

===================================================

type AliPayUserInfoShareResponse added in v1.4.7

type AliPayUserInfoShareResponse struct {
	Response     *userInfoShare `json:"alipay_user_info_share_response,omitempty"`
	AliPayCertSn string         `json:"alipay_cert_sn,omitempty"`
	SignData     string         `json:"-"`
	Sign         string         `json:"sign"`
}

===================================================

type AliPayUserPhone added in v1.4.7

type AliPayUserPhone struct {
	Code    string `json:"code,omitempty"`
	Msg     string `json:"msg,omitempty"`
	SubCode string `json:"subCode,omitempty"`
	SubMsg  string `json:"subMsg,omitempty"`
	Mobile  string `json:"mobile,omitempty"`
}

type AppWeChatLoginAccessToken added in v1.4.7

type AppWeChatLoginAccessToken struct {
	AccessToken  string `json:"access_token,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Openid       string `json:"openid,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Scope        string `json:"scope,omitempty"`
	Unionid      string `json:"unionid,omitempty"`
	Errcode      int    `json:"errcode,omitempty"` // 错误码
	Errmsg       string `json:"errmsg,omitempty"`  // 错误信息
}

App应用微信第三方登录,code换取access_token

func GetAppWeChatLoginAccessToken added in v1.4.7

func GetAppWeChatLoginAccessToken(appId, appSecret, code string) (accessToken *AppWeChatLoginAccessToken, err error)

App应用微信第三方登录,code换取access_token

appId:应用唯一标识,在微信开放平台提交应用审核通过后获得
appSecret:应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
code:App用户换取access_token的code

type BodyMap

type BodyMap map[string]interface{}

func DecryptAliPayOpenDataToBodyMap added in v1.4.7

func DecryptAliPayOpenDataToBodyMap(encryptedData, secretKey string) (bm BodyMap, err error)

DecryptAliPayOpenDataToBodyMap 解密支付宝开放数据到 BodyMap

encryptedData:包括敏感数据在内的完整用户信息的加密数据
secretKey:AES密钥,支付宝管理平台配置
文档:https://docs.alipay.com/mini/introduce/aes
文档:https://docs.open.alipay.com/common/104567

func DecryptWeChatOpenDataToBodyMap added in v1.4.7

func DecryptWeChatOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm BodyMap, err error)

解密开放数据到 BodyMap

encryptedData:包括敏感数据在内的完整用户信息的加密数据,小程序获取到
iv:加密算法的初始向量,小程序获取到
sessionKey:会话密钥,通过  gopay.Code2Session() 方法获取到
文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

func ParseAliPayNotifyResultToBodyMap added in v1.4.7

func ParseAliPayNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error)

解析支付宝支付异步通知的参数到BodyMap

req:*http.Request
返回参数bm:Notify请求的参数
返回参数err:错误信息
文档:https://docs.open.alipay.com/203/105286/

func ParseWeChatNotifyResultToBodyMap added in v1.4.7

func ParseWeChatNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error)

解析微信支付异步通知的结果到BodyMap

req:*http.Request
返回参数bm:Notify请求的参数
返回参数err:错误信息

func (BodyMap) EncodeAliPaySignParams added in v1.4.7

func (bm BodyMap) EncodeAliPaySignParams() string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) EncodeWeChatSignParams added in v1.4.7

func (bm BodyMap) EncodeWeChatSignParams(apiKey string) string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) Get

func (bm BodyMap) Get(key string) string

获取参数

func (BodyMap) MarshalXML added in v1.4.7

func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

func (BodyMap) Remove

func (bm BodyMap) Remove(key string)

删除参数

func (BodyMap) Set

func (bm BodyMap) Set(key string, value interface{})

设置参数

func (*BodyMap) UnmarshalXML added in v1.4.7

func (bm *BodyMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

type Client added in v1.4.7

type Client struct {
	HttpClient    *http.Client
	Transport     *http.Transport
	Url           string
	Method        string
	RequestType   string
	FormString    string
	ContentType   string
	UnmarshalType string
	Types         map[string]string
	JsonByte      []byte
	Errors        []error
	// contains filtered or unexported fields
}

func NewHttpClient added in v1.4.7

func NewHttpClient() (client *Client)

NewHttpClient , default tls.Config{InsecureSkipVerify: true}

func (*Client) EndBytes added in v1.4.7

func (c *Client) EndBytes() (res *http.Response, bs []byte, errs []error)

func (*Client) EndStruct added in v1.4.7

func (c *Client) EndStruct(v interface{}) (res *http.Response, errs []error)

func (*Client) Get added in v1.4.7

func (c *Client) Get(url string) (client *Client)

func (*Client) Post added in v1.4.7

func (c *Client) Post(url string) (client *Client)

func (*Client) SendString added in v1.4.7

func (c *Client) SendString(v string) (client *Client)

func (*Client) SendStruct added in v1.4.7

func (c *Client) SendStruct(v interface{}) (client *Client)

func (*Client) SetTLSConfig added in v1.4.7

func (c *Client) SetTLSConfig(tlsCfg *tls.Config) (client *Client)

func (*Client) Type added in v1.4.7

func (c *Client) Type(typeStr string) (client *Client)

type Code2SessionRsp added in v1.0.6

type Code2SessionRsp struct {
	SessionKey string `json:"session_key,omitempty"` // 会话密钥
	ExpiresIn  int    `json:"expires_in,omitempty"`  // SessionKey超时时间(秒)
	Openid     string `json:"openid,omitempty"`      // 用户唯一标识
	Unionid    string `json:"unionid,omitempty"`     // 用户在开放平台的唯一标识符
	Errcode    int    `json:"errcode,omitempty"`     // 错误码
	Errmsg     string `json:"errmsg,omitempty"`      // 错误信息
}

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
文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html

type Country added in v1.4.7

type Country int

type OpenApiRoyaltyDetailInfoPojo added in v1.4.7

type OpenApiRoyaltyDetailInfoPojo struct {
	RoyaltyType  string `json:"royalty_type,omitempty"`
	TransOut     string `json:"trans_out,omitempty"`
	TransOutType string `json:"trans_out_type,omitempty"`
	TransInType  string `json:"trans_in_type,omitempty"`
	TransIn      string `json:"trans_in"`
	Amount       string `json:"amount,omitempty"`
	Desc         string `json:"desc,omitempty"`
}

type OpenIdByAuthCodeRsp added in v1.4.7

type OpenIdByAuthCodeRsp struct {
	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId      string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr   string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign       string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode    string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	Openid     string `xml:"openid,omitempty" json:"openid,omitempty"` // 用户唯一标识
}

授权码查询openid 返回

func GetOpenIdByAuthCode added in v1.4.7

func GetOpenIdByAuthCode(appId, mchId, apiKey, authCode, nonceStr string) (openIdRsp *OpenIdByAuthCodeRsp, err error)

授权码查询openid(AccessToken:157字符)

appId:APPID
mchId:商户号
ApiKey:apiKey
authCode:用户授权码
nonceStr:随即字符串
文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_13&index=9

type PaidUnionId added in v1.0.7

type PaidUnionId struct {
	Unionid string `json:"unionid,omitempty"` // 用户在开放平台的唯一标识符
	Errcode int    `json:"errcode,omitempty"` // 错误码
	Errmsg  string `json:"errmsg,omitempty"`  // 错误信息
}

func GetWeChatAppletPaidUnionId added in v1.4.7

func GetWeChatAppletPaidUnionId(accessToken, openId, transactionId string) (unionId *PaidUnionId, err error)

微信小程序用户支付完成后,获取该用户的 UnionId,无需用户授权。

accessToken:接口调用凭据
openId:用户的OpenID
transactionId:微信支付订单号
文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html

type RefreshAppWeChatLoginAccessTokenRsp added in v1.4.7

type RefreshAppWeChatLoginAccessTokenRsp struct {
	AccessToken  string `json:"access_token,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Openid       string `json:"openid,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Scope        string `json:"scope,omitempty"`
	Errcode      int    `json:"errcode,omitempty"` // 错误码
	Errmsg       string `json:"errmsg,omitempty"`  // 错误信息
}

刷新App应用微信第三方登录后,获取的 access_token

func RefreshAppWeChatLoginAccessToken added in v1.4.7

func RefreshAppWeChatLoginAccessToken(appId, refreshToken string) (accessToken *RefreshAppWeChatLoginAccessTokenRsp, err error)

刷新App应用微信第三方登录后,获取的 access_token

appId:应用唯一标识,在微信开放平台提交应用审核通过后获得
appSecret:应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
code:App用户换取access_token的code

type RefundNotify added in v1.4.7

type RefundNotify struct {
	TransactionId       string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo          string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	RefundId            string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
	OutRefundNo         string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
	TotalFee            int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee  int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	RefundFee           int    `xml:"refund_fee,omitempty" json:"refund_fee,omitempty"`
	SettlementRefundFee int    `xml:"settlement_refund_fee,omitempty" json:"settlement_refund_fee,omitempty"`
	RefundStatus        string `xml:"refund_status,omitempty" json:"refund_status,omitempty"`
	SuccessTime         string `xml:"success_time,omitempty" json:"success_time,omitempty"`
	RefundRecvAccout    string `xml:"refund_recv_accout,omitempty" json:"refund_recv_accout,omitempty"`
	RefundAccount       string `xml:"refund_account,omitempty" json:"refund_account,omitempty"`
	RefundRequestSource string `xml:"refund_request_source,omitempty" json:"refund_request_source,omitempty"`
}

func DecryptRefundNotifyReqInfo added in v1.4.7

func DecryptRefundNotifyReqInfo(reqInfo, apiKey string) (refundNotify *RefundNotify, err error)

解密微信退款异步通知的加密数据

reqInfo:gopay.ParseWeChatRefundNotifyResult() 方法获取的加密数据 req_info
apiKey:API秘钥值
返回参数refundNotify:RefundNotify请求的加密数据
返回参数err:错误信息
文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=10

type ReturnMessage

type ReturnMessage struct {
	ReturnCode string `json:"return_code"`
	ReturnMsg  string `json:"return_msg"`
}

type WeChatAppletUserInfo added in v1.4.7

type WeChatAppletUserInfo struct {
	OpenId    string         `json:"openId,omitempty"`
	NickName  string         `json:"nickName,omitempty"`
	Gender    int            `json:"gender,omitempty"`
	City      string         `json:"city,omitempty"`
	Province  string         `json:"province,omitempty"`
	Country   string         `json:"country,omitempty"`
	AvatarUrl string         `json:"avatarUrl,omitempty"`
	UnionId   string         `json:"unionId,omitempty"`
	Watermark *watermarkInfo `json:"watermark,omitempty"`
}

微信小程序解密后 用户信息结构体

type WeChatClient added in v1.4.7

type WeChatClient struct {
	AppId      string
	MchId      string
	ApiKey     string
	BaseURL    string
	CertFile   []byte
	KeyFile    []byte
	Pkcs12File []byte
	IsProd     bool
	// contains filtered or unexported fields
}

func NewWeChatClient

func NewWeChatClient(appId, mchId, apiKey string, isProd bool) (client *WeChatClient)

初始化微信客户端

appId:应用ID
mchId:商户ID
ApiKey:API秘钥值
IsProd:是否是正式环境

func (*WeChatClient) AddCertFileByte added in v1.4.7

func (w *WeChatClient) AddCertFileByte(certFile, keyFile, pkcs12File []byte)

添加微信证书 Byte 数组

certFile:apiclient_cert.pem byte数组
keyFile:apiclient_key.pem byte数组
pkcs12File:apiclient_cert.p12 byte数组

func (*WeChatClient) AddCertFilePath added in v1.4.7

func (w *WeChatClient) AddCertFilePath(certFilePath, keyFilePath, pkcs12FilePath string) (err error)

添加微信证书 Path 路径

certFilePath:apiclient_cert.pem 路径
keyFilePath:apiclient_key.pem 路径
pkcs12FilePath:apiclient_cert.p12 路径
返回err

func (*WeChatClient) BatchQueryComment added in v1.4.7

func (w *WeChatClient) BatchQueryComment(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error)

拉取订单评价数据

注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=11

func (*WeChatClient) CloseOrder added in v1.4.7

func (w *WeChatClient) CloseOrder(body BodyMap) (wxRsp *WeChatCloseOrderResponse, err error)

关闭订单

文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3

func (*WeChatClient) DownloadBill added in v1.4.7

func (w *WeChatClient) DownloadBill(body BodyMap) (wxRsp string, err error)

下载对账单

文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6

func (*WeChatClient) DownloadFundFlow added in v1.4.7

func (w *WeChatClient) DownloadFundFlow(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error)

下载资金账单

注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18&index=7

func (*WeChatClient) EntrustPublic added in v1.4.7

func (w *WeChatClient) EntrustPublic(body BodyMap) (bs []byte, err error)

公众号纯签约(未完成)

文档地址:https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_1&index=1

func (*WeChatClient) Micropay added in v1.4.7

func (w *WeChatClient) Micropay(body BodyMap) (wxRsp *WeChatMicropayResponse, err error)

提交付款码支付

文档地址:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1

func (*WeChatClient) QueryOrder added in v1.4.7

func (w *WeChatClient) QueryOrder(body BodyMap) (wxRsp *WeChatQueryOrderResponse, err error)

查询订单

文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2

func (*WeChatClient) QueryRefund added in v1.4.7

func (w *WeChatClient) QueryRefund(body BodyMap) (wxRsp *WeChatQueryRefundResponse, err error)

查询退款

文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5

func (*WeChatClient) Refund added in v1.4.7

func (w *WeChatClient) Refund(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatRefundResponse, err error)

申请退款

注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4

func (*WeChatClient) Reverse added in v1.4.7

func (w *WeChatClient) Reverse(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatReverseResponse, err error)

撤销订单

注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
文档地址:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3

func (*WeChatClient) SetCountry added in v1.4.7

func (w *WeChatClient) SetCountry(country Country) (client *WeChatClient)

设置支付国家(默认:中国国内)

根据支付地区情况设置国家
country:<China:中国国内,China2:中国国内(冗灾方案),SoutheastAsia:东南亚,Other:其他国家>

func (*WeChatClient) Transfer added in v1.4.7

func (w *WeChatClient) Transfer(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatTransfersResponse, err error)

企业向微信用户个人付款

注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
注意:此方法未支持沙箱环境,默认正式环境,转账请慎重
文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1

func (*WeChatClient) UnifiedOrder added in v1.4.7

func (w *WeChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderResponse, err error)

统一下单

文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1

type WeChatCloseOrderResponse

type WeChatCloseOrderResponse struct {
	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId      string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	DeviceInfo string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	NonceStr   string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign       string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode    string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
}

type WeChatMicropayResponse

type WeChatMicropayResponse struct {
	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid              string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId              string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	DeviceInfo         string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	NonceStr           string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign               string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode         string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode            string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes         string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	Openid             string `xml:"openid,omitempty" json:"openid,omitempty"`
	IsSubscribe        string `xml:"is_subscribe,omitempty" json:"is_subscribe,omitempty"`
	TradeType          string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
	BankType           string `xml:"bank_type,omitempty" json:"bank_type,omitempty"`
	FeeType            string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
	TotalFee           int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	CouponFee          int    `xml:"coupon_fee,omitempty" json:"coupon_fee,omitempty"`
	CashFeeType        string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
	CashFee            int    `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
	TransactionId      string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo         string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	Attach             string `xml:"attach,omitempty" json:"attach,omitempty"`
	TimeEnd            string `xml:"time_end,omitempty" json:"time_end,omitempty"`
	PromotionDetail    string `xml:"promotion_detail,omitempty" json:"promotion_detail,omitempty"`
}

type WeChatNotifyRequest

type WeChatNotifyRequest struct {
	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	ResultCode         string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode            string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes         string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	Appid              string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId              string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	DeviceInfo         string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	NonceStr           string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign               string `xml:"sign,omitempty" json:"sign,omitempty"`
	SignType           string `xml:"sign_type,omitempty" json:"sign_type,omitempty"`
	Openid             string `xml:"openid,omitempty" json:"openid,omitempty"`
	IsSubscribe        string `xml:"is_subscribe,omitempty" json:"is_subscribe,omitempty"`
	TradeType          string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
	BankType           string `xml:"bank_type,omitempty" json:"bank_type,omitempty"`
	TotalFee           int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	FeeType            string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
	CashFee            int    `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
	CashFeeType        string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
	CouponFee          int    `xml:"coupon_fee,omitempty" json:"coupon_fee,omitempty"`
	CouponCount        int    `xml:"coupon_count,omitempty" json:"coupon_count,omitempty"`
	CouponType0        string `xml:"coupon_type_0,omitempty" json:"coupon_type_0,omitempty"`
	CouponType1        string `xml:"coupon_type_1,omitempty" json:"coupon_type_1,omitempty"`
	CouponId0          string `xml:"coupon_id_0,omitempty" json:"coupon_id_0,omitempty"`
	CouponId1          string `xml:"coupon_id_1,omitempty" json:"coupon_id_1,omitempty"`
	CouponFee0         int    `xml:"coupon_fee_0,omitempty" json:"coupon_fee_0,omitempty"`
	CouponFee1         int    `xml:"coupon_fee_1,omitempty" json:"coupon_fee_1,omitempty"`
	TransactionId      string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo         string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	Attach             string `xml:"attach,omitempty" json:"attach,omitempty"`
	TimeEnd            string `xml:"time_end,omitempty" json:"time_end,omitempty"`
}

func ParseWeChatNotifyResult added in v1.4.7

func ParseWeChatNotifyResult(req *http.Request) (notifyReq *WeChatNotifyRequest, err error)

解析微信支付异步通知的参数

req:*http.Request
返回参数notifyReq:Notify请求的参数
返回参数err:错误信息

type WeChatNotifyResponse

type WeChatNotifyResponse struct {
	ReturnCode string `xml:"return_code"`
	ReturnMsg  string `xml:"return_msg"`
}

func (*WeChatNotifyResponse) ToXmlString

func (w *WeChatNotifyResponse) ToXmlString() (xmlStr string)

返回数据给微信

type WeChatQueryOrderResponse

type WeChatQueryOrderResponse struct {
	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid              string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId              string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr           string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign               string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode         string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode            string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes         string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	DeviceInfo         string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	Openid             string `xml:"openid,omitempty" json:"openid,omitempty"`
	IsSubscribe        string `xml:"is_subscribe,omitempty" json:"is_subscribe,omitempty"`
	TradeType          string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
	TradeState         string `xml:"trade_state,omitempty" json:"trade_state,omitempty"`
	BankType           string `xml:"bank_type,omitempty" json:"bank_type,omitempty"`
	TotalFee           int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	FeeType            string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
	CashFee            int    `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
	CashFeeType        string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
	CouponFee          int    `xml:"coupon_fee,omitempty" json:"coupon_fee,omitempty"`
	CouponCount        int    `xml:"coupon_count,omitempty" json:"coupon_count,omitempty"`
	CouponType0        string `xml:"coupon_type_0,omitempty" json:"coupon_type_0,omitempty"`
	CouponType1        string `xml:"coupon_type_1,omitempty" json:"coupon_type_1,omitempty"`
	CouponId0          string `xml:"coupon_id_0,omitempty" json:"coupon_id_0,omitempty"`
	CouponId1          string `xml:"coupon_id_1,omitempty" json:"coupon_id_1,omitempty"`
	CouponFee0         int    `xml:"coupon_fee_0,omitempty" json:"coupon_fee_0,omitempty"`
	CouponFee1         int    `xml:"coupon_fee_1,omitempty" json:"coupon_fee_1,omitempty"`
	TransactionId      string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo         string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	Attach             string `xml:"attach,omitempty" json:"attach,omitempty"`
	TimeEnd            string `xml:"time_end,omitempty" json:"time_end,omitempty"`
	TradeStateDesc     string `xml:"trade_state_desc,omitempty" json:"trade_state_desc,omitempty"`
}

type WeChatQueryRefundResponse

type WeChatQueryRefundResponse struct {
	ReturnCode           string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg            string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	ResultCode           string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode              string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes           string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	Appid                string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId                string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr             string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign                 string `xml:"sign,omitempty" json:"sign,omitempty"`
	TotalRefundCount     int    `xml:"total_refund_count,omitempty" json:"total_refund_count,omitempty"`
	TransactionId        string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo           string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	TotalFee             int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee   int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	FeeType              string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
	CashFee              int    `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
	RefundCount          int    `xml:"refund_count,omitempty" json:"refund_count,omitempty"`
	OutRefundNo0         string `xml:"out_refund_no_0,omitempty" json:"out_refund_no_0,omitempty"`
	OutRefundNo1         string `xml:"out_refund_no_1,omitempty" json:"out_refund_no_1,omitempty"`
	RefundId0            string `xml:"refund_id_0,omitempty" json:"refund_id_0,omitempty"`
	RefundId1            string `xml:"refund_id_1,omitempty" json:"refund_id_1,omitempty"`
	RefundChannel0       string `xml:"refund_channel_0,omitempty" json:"refund_channel_0,omitempty"`
	RefundChannel1       string `xml:"refund_channel_1,omitempty" json:"refund_channel_1,omitempty"`
	RefundFee            int    `xml:"refund_fee,omitempty" json:"refund_fee,omitempty"`
	RefundFee0           int    `xml:"refund_fee_0,omitempty" json:"refund_fee_0,omitempty"`
	RefundFee1           int    `xml:"refund_fee_1,omitempty" json:"refund_fee_1,omitempty"`
	SettlementRefundFee0 int    `xml:"settlement_refund_fee_0,omitempty" json:"settlement_refund_fee_0,omitempty"`
	SettlementRefundFee1 int    `xml:"settlement_refund_fee_1,omitempty" json:"settlement_refund_fee_1,omitempty"`
	CouponType00         string `xml:"coupon_type_0_0,omitempty" json:"coupon_type_0_0,omitempty"`
	CouponType01         string `xml:"coupon_type_0_1,omitempty" json:"coupon_type_0_1,omitempty"`
	CouponType10         string `xml:"coupon_type_1_0,omitempty" json:"coupon_type_1_0,omitempty"`
	CouponType11         string `xml:"coupon_type_1_1,omitempty" json:"coupon_type_1_1,omitempty"`
	CouponRefundFee0     int    `xml:"coupon_refund_fee_0,omitempty" json:"coupon_refund_fee_0,omitempty"`
	CouponRefundFee1     int    `xml:"coupon_refund_fee_1,omitempty" json:"coupon_refund_fee_1,omitempty"`
	CouponRefundCount0   int    `xml:"coupon_refund_count_0,omitempty" json:"coupon_refund_count_0,omitempty"`
	CouponRefundCount1   int    `xml:"coupon_refund_count_1,omitempty" json:"coupon_refund_count_1,omitempty"`
	CouponRefundId00     string `xml:"coupon_refund_id_0_0,omitempty" json:"coupon_refund_id_0_0,omitempty"`
	CouponRefundId01     string `xml:"coupon_refund_id_0_1,omitempty" json:"coupon_refund_id_0_1,omitempty"`
	CouponRefundId10     string `xml:"coupon_refund_id_1_0,omitempty" json:"coupon_refund_id_1_0,omitempty"`
	CouponRefundId11     string `xml:"coupon_refund_id_1_1,omitempty" json:"coupon_refund_id_1_1,omitempty"`
	CouponRefundFee00    int    `xml:"coupon_refund_fee_0_0,omitempty" json:"coupon_refund_fee_0_0,omitempty"`
	CouponRefundFee01    int    `xml:"coupon_refund_fee_0_1,omitempty" json:"coupon_refund_fee_0_1,omitempty"`
	CouponRefundFee10    int    `xml:"coupon_refund_fee_1_0,omitempty" json:"coupon_refund_fee_1_0,omitempty"`
	CouponRefundFee11    int    `xml:"coupon_refund_fee_1_1,omitempty" json:"coupon_refund_fee_1_1,omitempty"`
	RefundStatus0        string `xml:"refund_status_0,omitempty" json:"refund_status_0,omitempty"`
	RefundStatus1        string `xml:"refund_status_1,omitempty" json:"refund_status_1,omitempty"`
	RefundAccount0       string `xml:"refund_account_0,omitempty" json:"refund_account_0,omitempty"`
	RefundAccount1       string `xml:"refund_account_1,omitempty" json:"refund_account_1,omitempty"`
	RefundRecvAccout0    string `xml:"refund_recv_accout_0,omitempty" json:"refund_recv_accout_0,omitempty"`
	RefundRecvAccout1    string `xml:"refund_recv_accout_1,omitempty" json:"refund_recv_accout_1,omitempty"`
	RefundSuccessTime0   string `xml:"refund_success_time_0,omitempty" json:"refund_success_time_0,omitempty"`
	RefundSuccessTime1   string `xml:"refund_success_time_1,omitempty" json:"refund_success_time_1,omitempty"`
}

type WeChatRefundNotifyRequest added in v1.4.7

type WeChatRefundNotifyRequest struct {
	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId      string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr   string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	ReqInfo    string `xml:"req_info,omitempty" json:"req_info,omitempty"`
}

func ParseWeChatRefundNotifyResult added in v1.4.7

func ParseWeChatRefundNotifyResult(req *http.Request) (notifyReq *WeChatRefundNotifyRequest, err error)

解析微信退款异步通知的参数

req:*http.Request
返回参数notifyReq:Notify请求的参数
返回参数err:错误信息

type WeChatRefundResponse

type WeChatRefundResponse struct {
	ReturnCode          string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg           string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	ResultCode          string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode             string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes          string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	Appid               string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId               string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr            string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign                string `xml:"sign,omitempty" json:"sign,omitempty"`
	TransactionId       string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
	OutTradeNo          string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
	OutRefundNo         string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
	RefundId            string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
	RefundFee           int    `xml:"refund_fee,omitempty" json:"refund_fee,omitempty"`
	SettlementRefundFee int    `xml:"settlement_refund_fee,omitempty" json:"settlement_refund_fee,omitempty"`
	TotalFee            int    `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
	SettlementTotalFee  int    `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
	FeeType             string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
	CashFee             int    `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
	CashFeeType         string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
	CashRefundFee       int    `xml:"cash_refund_fee,omitempty" json:"cash_refund_fee,omitempty"`
	CouponType0         string `xml:"coupon_type_0,omitempty" json:"coupon_type_0,omitempty"`
	CouponType1         string `xml:"coupon_type_1,omitempty" json:"coupon_type_1,omitempty"`
	CouponRefundFee     int    `xml:"coupon_refund_fee,omitempty" json:"coupon_refund_fee,omitempty"`
	CouponRefundFee0    int    `xml:"coupon_refund_fee_0,omitempty" json:"coupon_refund_fee_0,omitempty"`
	CouponRefundFee1    int    `xml:"coupon_refund_fee_1,omitempty" json:"coupon_refund_fee_1,omitempty"`
	CouponRefundCount   int    `xml:"coupon_refund_count,omitempty" json:"coupon_refund_count,omitempty"`
	CouponRefundId0     string `xml:"coupon_refund_id_0,omitempty" json:"coupon_refund_id_0,omitempty"`
	CouponRefundId1     string `xml:"coupon_refund_id_1,omitempty" json:"coupon_refund_id_1,omitempty"`
}

type WeChatReverseResponse

type WeChatReverseResponse struct {
	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId      string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	NonceStr   string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign       string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode    string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	Recall     string `xml:"recall,omitempty" json:"recall,omitempty"`
}

type WeChatTransfersResponse added in v1.4.7

type WeChatTransfersResponse struct {
	ReturnCode     string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg      string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	MchAppid       string `xml:"mch_appid,omitempty" json:"mch_appid,omitempty"`
	Mchid          string `xml:"mchid,omitempty" json:"mchid,omitempty"`
	DeviceInfo     string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	NonceStr       string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	ResultCode     string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode        string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes     string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	PartnerTradeNo string `xml:"partner_trade_no,omitempty" json:"partner_trade_no,omitempty"`
	PaymentNo      string `xml:"payment_no,omitempty" json:"payment_no,omitempty"`
	PaymentTime    string `xml:"payment_time,omitempty" json:"payment_time,omitempty"`
}

type WeChatUnifiedOrderResponse

type WeChatUnifiedOrderResponse struct {
	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
	MchId      string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
	DeviceInfo string `xml:"device_info,omitempty" json:"device_info,omitempty"`
	NonceStr   string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
	Sign       string `xml:"sign,omitempty" json:"sign,omitempty"`
	ResultCode string `xml:"result_code,omitempty" json:"result_code,omitempty"`
	ErrCode    string `xml:"err_code,omitempty" json:"err_code,omitempty"`
	ErrCodeDes string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
	TradeType  string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
	PrepayId   string `xml:"prepay_id,omitempty" json:"prepay_id,omitempty"`
	CodeUrl    string `xml:"code_url,omitempty" json:"code_url,omitempty"`
	MwebUrl    string `xml:"mweb_url,omitempty" json:"mweb_url,omitempty"`
}

type WeChatUserInfo added in v1.0.7

type WeChatUserInfo struct {
	Subscribe      int    `json:"subscribe,omitempty"`       // 用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
	Openid         string `json:"openid,omitempty"`          // 用户唯一标识
	Nickname       string `json:"nickname,omitempty"`        // 用户的昵称
	Sex            int    `json:"sex,omitempty"`             // 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
	Language       string `json:"language,omitempty"`        // 用户的语言,简体中文为zh_CN
	City           string `json:"city,omitempty"`            // 用户所在城市
	Province       string `json:"province,omitempty"`        // 用户所在省份
	Country        string `json:"country,omitempty"`         // 用户所在国家
	Headimgurl     string `json:"headimgurl,omitempty"`      // 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
	SubscribeTime  int    `json:"subscribe_time,omitempty"`  // 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
	Unionid        string `json:"unionid,omitempty"`         // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
	Remark         string `json:"remark,omitempty"`          // 公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
	Groupid        int    `json:"groupid,omitempty"`         // 用户所在的分组ID(兼容旧的用户分组接口)
	TagidList      []int  `json:"tagid_list,omitempty"`      // 用户被打上的标签ID列表
	SubscribeScene string `json:"subscribe_scene,omitempty"` // 返回用户关注的渠道来源,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,omitempty"`        // 二维码扫码场景(开发者自定义)
	QrSceneStr     string `json:"qr_scene_str,omitempty"`    // 二维码扫码场景描述(开发者自定义)
	Errcode        int    `json:"errcode,omitempty"`         // 错误码
	Errmsg         string `json:"errmsg,omitempty"`          // 错误信息
}

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 英语
获取用户基本信息(UnionID机制)文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839

type WeChatUserPhone added in v1.0.7

type WeChatUserPhone struct {
	PhoneNumber     string         `json:"phoneNumber,omitempty"`
	PurePhoneNumber string         `json:"purePhoneNumber,omitempty"`
	CountryCode     string         `json:"countryCode,omitempty"`
	Watermark       *watermarkInfo `json:"watermark,omitempty"`
}

微信小程序解密后 用户手机号结构体

type ZhimaCreditScoreGetResponse added in v1.4.7

type ZhimaCreditScoreGetResponse struct {
	Response     *scoreGetResponse `json:"zhima_credit_score_get_response,omitempty"`
	AliPayCertSn string            `json:"alipay_cert_sn,omitempty"`
	SignData     string            `json:"-"`
	Sign         string            `json:"sign"`
}

===================================================

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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