|
|
@@ -1,4 +1,4 @@
|
|
|
-package gopay
|
|
|
+package alipay
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
@@ -7,9 +7,11 @@ import (
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/iGoogle-ink/gopay"
|
|
|
)
|
|
|
|
|
|
-type AliPayClient struct {
|
|
|
+type Client struct {
|
|
|
AppId string
|
|
|
PrivateKey string
|
|
|
AppCertSN string
|
|
|
@@ -30,8 +32,8 @@ type AliPayClient struct {
|
|
|
// appId:应用ID
|
|
|
// PrivateKey:应用私钥
|
|
|
// IsProd:是否是正式环境
|
|
|
-func NewAliPayClient(appId, privateKey string, isProd bool) (client *AliPayClient) {
|
|
|
- return &AliPayClient{
|
|
|
+func NewClient(appId, privateKey string, isProd bool) (client *Client) {
|
|
|
+ return &Client{
|
|
|
AppId: appId,
|
|
|
PrivateKey: privateKey,
|
|
|
IsProd: isProd,
|
|
|
@@ -40,12 +42,12 @@ func NewAliPayClient(appId, privateKey string, isProd bool) (client *AliPayClien
|
|
|
|
|
|
// alipay.trade.fastpay.refund.query(统一收单交易退款查询)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query
|
|
|
-func (a *AliPayClient) AliPayTradeFastPayRefundQuery(body BodyMap) (aliRsp *AliPayTradeFastpayRefundQueryResponse, err error) {
|
|
|
+func (a *Client) TradeFastPayRefundQuery(body gopay.BodyMap) (aliRsp *AliPayTradeFastpayRefundQueryResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.fastpay.refund.query"); err != nil {
|
|
|
return
|
|
|
@@ -64,12 +66,12 @@ func (a *AliPayClient) AliPayTradeFastPayRefundQuery(body BodyMap) (aliRsp *AliP
|
|
|
|
|
|
// alipay.trade.order.settle(统一收单交易结算接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.order.settle
|
|
|
-func (a *AliPayClient) AliPayTradeOrderSettle(body BodyMap) (aliRsp *AliPayTradeOrderSettleResponse, err error) {
|
|
|
+func (a *Client) TradeOrderSettle(body gopay.BodyMap) (aliRsp *AliPayTradeOrderSettleResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_request_no") == null || body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_request_no or trade_no are not allowed to be null")
|
|
|
+ if body.Get("out_request_no") == gopay.NULL || body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_request_no or trade_no are not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.order.settle"); err != nil {
|
|
|
return
|
|
|
@@ -88,12 +90,12 @@ func (a *AliPayClient) AliPayTradeOrderSettle(body BodyMap) (aliRsp *AliPayTrade
|
|
|
|
|
|
// alipay.trade.create(统一收单交易创建接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.create
|
|
|
-func (a *AliPayClient) AliPayTradeCreate(body BodyMap) (aliRsp *AliPayTradeCreateResponse, err error) {
|
|
|
+func (a *Client) TradeCreate(body gopay.BodyMap) (aliRsp *AliPayTradeCreateResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("buyer_id") == null {
|
|
|
- return nil, errors.New("out_trade_no and buyer_id are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("buyer_id") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and buyer_id are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.create"); err != nil {
|
|
|
return
|
|
|
@@ -112,12 +114,12 @@ func (a *AliPayClient) AliPayTradeCreate(body BodyMap) (aliRsp *AliPayTradeCreat
|
|
|
|
|
|
// alipay.trade.close(统一收单交易关闭接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.close
|
|
|
-func (a *AliPayClient) AliPayTradeClose(body BodyMap) (aliRsp *AliPayTradeCloseResponse, err error) {
|
|
|
+func (a *Client) AliPayTradeClose(body gopay.BodyMap) (aliRsp *AliPayTradeCloseResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.close"); err != nil {
|
|
|
return
|
|
|
@@ -136,12 +138,12 @@ func (a *AliPayClient) AliPayTradeClose(body BodyMap) (aliRsp *AliPayTradeCloseR
|
|
|
|
|
|
// alipay.trade.cancel(统一收单交易撤销接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.cancel
|
|
|
-func (a *AliPayClient) AliPayTradeCancel(body BodyMap) (aliRsp *AliPayTradeCancelResponse, err error) {
|
|
|
+func (a *Client) AliPayTradeCancel(body gopay.BodyMap) (aliRsp *AliPayTradeCancelResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.cancel"); err != nil {
|
|
|
return
|
|
|
@@ -160,12 +162,12 @@ func (a *AliPayClient) AliPayTradeCancel(body BodyMap) (aliRsp *AliPayTradeCance
|
|
|
|
|
|
// alipay.trade.refund(统一收单交易退款接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.refund
|
|
|
-func (a *AliPayClient) AliPayTradeRefund(body BodyMap) (aliRsp *AliPayTradeRefundResponse, err error) {
|
|
|
+func (a *Client) AliPayTradeRefund(body gopay.BodyMap) (aliRsp *AliPayTradeRefundResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.refund"); err != nil {
|
|
|
return nil, err
|
|
|
@@ -184,12 +186,12 @@ func (a *AliPayClient) AliPayTradeRefund(body BodyMap) (aliRsp *AliPayTradeRefun
|
|
|
|
|
|
// alipay.trade.refund(统一收单退款页面接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.refund
|
|
|
-func (a *AliPayClient) AliPayTradePageRefund(body BodyMap) (aliRsp *AliPayTradePageRefundResponse, err error) {
|
|
|
+func (a *Client) AliPayTradePageRefund(body gopay.BodyMap) (aliRsp *AliPayTradePageRefundResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, " alipay.trade.page.refund"); err != nil {
|
|
|
return
|
|
|
@@ -208,10 +210,10 @@ func (a *AliPayClient) AliPayTradePageRefund(body BodyMap) (aliRsp *AliPayTradeP
|
|
|
|
|
|
// alipay.trade.precreate(统一收单线下交易预创建)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.precreate
|
|
|
-func (a *AliPayClient) AliPayTradePrecreate(body BodyMap) (aliRsp *AliPayTradePrecreateResponse, err error) {
|
|
|
+func (a *Client) AliPayTradePrecreate(body gopay.BodyMap) (aliRsp *AliPayTradePrecreateResponse, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no is not allowed to be null")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.precreate"); err != nil {
|
|
|
return
|
|
|
@@ -230,10 +232,10 @@ func (a *AliPayClient) AliPayTradePrecreate(body BodyMap) (aliRsp *AliPayTradePr
|
|
|
|
|
|
// alipay.trade.pay(统一收单交易支付接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.pay
|
|
|
-func (a *AliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayResponse, err error) {
|
|
|
+func (a *Client) AliPayTradePay(body gopay.BodyMap) (aliRsp *AliPayTradePayResponse, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no is not allowed to be null")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.pay"); err != nil {
|
|
|
return
|
|
|
@@ -252,12 +254,12 @@ func (a *AliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayRespo
|
|
|
|
|
|
// alipay.trade.query(统一收单线下交易查询)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.query
|
|
|
-func (a *AliPayClient) AliPayTradeQuery(body BodyMap) (aliRsp *AliPayTradeQueryResponse, err error) {
|
|
|
+func (a *Client) AliPayTradeQuery(body gopay.BodyMap) (aliRsp *AliPayTradeQueryResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
|
|
|
- return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.query"); err != nil {
|
|
|
return
|
|
|
@@ -276,13 +278,13 @@ func (a *AliPayClient) AliPayTradeQuery(body BodyMap) (aliRsp *AliPayTradeQueryR
|
|
|
|
|
|
// alipay.trade.app.pay(app支付接口2.0)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.app.pay
|
|
|
-func (a *AliPayClient) AliPayTradeAppPay(body BodyMap) (payParam string, err error) {
|
|
|
+func (a *Client) AliPayTradeAppPay(body gopay.BodyMap) (payParam string, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_trade_no") == null {
|
|
|
- return null, errors.New("out_trade_no is not allowed to be null")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL {
|
|
|
+ return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.app.pay"); err != nil {
|
|
|
- return null, err
|
|
|
+ return gopay.NULL, err
|
|
|
}
|
|
|
payParam = string(bs)
|
|
|
return
|
|
|
@@ -290,14 +292,14 @@ func (a *AliPayClient) AliPayTradeAppPay(body BodyMap) (payParam string, err err
|
|
|
|
|
|
// alipay.trade.wap.pay(手机网站支付接口2.0)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
|
|
|
-func (a *AliPayClient) AliPayTradeWapPay(body BodyMap) (payUrl string, err error) {
|
|
|
+func (a *Client) AliPayTradeWapPay(body gopay.BodyMap) (payUrl string, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_trade_no") == null {
|
|
|
- return null, errors.New("out_trade_no is not allowed to be null")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL {
|
|
|
+ return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
|
|
|
}
|
|
|
body.Set("product_code", "QUICK_WAP_WAY")
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.wap.pay"); err != nil {
|
|
|
- return null, err
|
|
|
+ return gopay.NULL, err
|
|
|
}
|
|
|
payUrl = string(bs)
|
|
|
return
|
|
|
@@ -305,14 +307,14 @@ func (a *AliPayClient) AliPayTradeWapPay(body BodyMap) (payUrl string, err error
|
|
|
|
|
|
// alipay.trade.page.pay(统一收单下单并支付页面接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
|
|
|
-func (a *AliPayClient) AliPayTradePagePay(body BodyMap) (payUrl string, err error) {
|
|
|
+func (a *Client) AliPayTradePagePay(body gopay.BodyMap) (payUrl string, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_trade_no") == null {
|
|
|
- return null, errors.New("out_trade_no is not allowed to be null")
|
|
|
+ if body.Get("out_trade_no") == gopay.NULL {
|
|
|
+ return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
|
|
|
}
|
|
|
body.Set("product_code", "FAST_INSTANT_TRADE_PAY")
|
|
|
if bs, err = a.doAliPay(body, "alipay.trade.page.pay"); err != nil {
|
|
|
- return null, err
|
|
|
+ return gopay.NULL, err
|
|
|
}
|
|
|
payUrl = string(bs)
|
|
|
return
|
|
|
@@ -320,10 +322,10 @@ func (a *AliPayClient) AliPayTradePagePay(body BodyMap) (payUrl string, err erro
|
|
|
|
|
|
// alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer
|
|
|
-func (a *AliPayClient) AliPayFundTransToaccountTransfer(body BodyMap) (aliRsp *AliPayFundTransToaccountTransferResponse, err error) {
|
|
|
+func (a *Client) AliPayFundTransToaccountTransfer(body gopay.BodyMap) (aliRsp *AliPayFundTransToaccountTransferResponse, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("out_biz_no") == null {
|
|
|
- return nil, errors.New("out_biz_no is not allowed to be null")
|
|
|
+ if body.Get("out_biz_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("out_biz_no is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.fund.trans.toaccount.transfer"); err != nil {
|
|
|
return
|
|
|
@@ -342,28 +344,28 @@ func (a *AliPayClient) AliPayFundTransToaccountTransfer(body BodyMap) (aliRsp *A
|
|
|
|
|
|
// alipay.trade.orderinfo.sync(支付宝订单信息同步接口)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_1/alipay.trade.orderinfo.sync
|
|
|
-func (a *AliPayClient) AliPayTradeOrderinfoSync(body BodyMap) {
|
|
|
+func (a *Client) AliPayTradeOrderinfoSync(body gopay.BodyMap) {
|
|
|
|
|
|
}
|
|
|
|
|
|
// alipay.system.oauth.token(换取授权访问令牌)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_9/alipay.system.oauth.token
|
|
|
-func (a *AliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySystemOauthTokenResponse, err error) {
|
|
|
+func (a *Client) SystemOauthToken(body gopay.BodyMap) (aliRsp *AliPaySystemOauthTokenResponse, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("grant_type") == null {
|
|
|
- return nil, errors.New("grant_type is not allowed to be null")
|
|
|
+ if body.Get("grant_type") == gopay.NULL {
|
|
|
+ return nil, errors.New("grant_type is not allowed to be NULL")
|
|
|
}
|
|
|
- if body.Get("code") == null && body.Get("refresh_token") == null {
|
|
|
- return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
|
|
|
+ if body.Get("code") == gopay.NULL && body.Get("refresh_token") == gopay.NULL {
|
|
|
+ return nil, errors.New("code and refresh_token are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
- if bs, err = aliPaySystemOauthToken(a.AppId, a.PrivateKey, body, "alipay.system.oauth.token", a.IsProd); err != nil {
|
|
|
+ if bs, err = systemOauthToken(a.AppId, a.PrivateKey, body, "alipay.system.oauth.token", a.IsProd); err != nil {
|
|
|
return
|
|
|
}
|
|
|
aliRsp = new(AliPaySystemOauthTokenResponse)
|
|
|
if err = json.Unmarshal(bs, aliRsp); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- if aliRsp.Response.AccessToken == null {
|
|
|
+ if aliRsp.Response.AccessToken == gopay.NULL {
|
|
|
info := aliRsp.ErrorResponse
|
|
|
return nil, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
|
|
|
}
|
|
|
@@ -374,7 +376,7 @@ func (a *AliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySyste
|
|
|
// alipay.user.info.share(支付宝会员授权信息查询接口)
|
|
|
// body:此接口无需body参数
|
|
|
// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.info.share
|
|
|
-func (a *AliPayClient) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareResponse, err error) {
|
|
|
+func (a *Client) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareResponse, err error) {
|
|
|
var bs []byte
|
|
|
if bs, err = a.doAliPay(nil, "alipay.user.info.share"); err != nil {
|
|
|
return nil, err
|
|
|
@@ -393,13 +395,13 @@ func (a *AliPayClient) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareRespons
|
|
|
|
|
|
// alipay.open.auth.token.app(换取应用授权令牌)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_9/alipay.open.auth.token.app
|
|
|
-func (a *AliPayClient) AliPayOpenAuthTokenApp(body BodyMap) (aliRsp *AliPayOpenAuthTokenAppResponse, err error) {
|
|
|
+func (a *Client) AliPayOpenAuthTokenApp(body gopay.BodyMap) (aliRsp *AliPayOpenAuthTokenAppResponse, err error) {
|
|
|
var bs []byte
|
|
|
- if body.Get("grant_type") == null {
|
|
|
- return nil, errors.New("grant_type is not allowed to be null")
|
|
|
+ if body.Get("grant_type") == gopay.NULL {
|
|
|
+ return nil, errors.New("grant_type is not allowed to be NULL")
|
|
|
}
|
|
|
- if body.Get("code") == null && body.Get("refresh_token") == null {
|
|
|
- return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
|
|
|
+ if body.Get("code") == gopay.NULL && body.Get("refresh_token") == gopay.NULL {
|
|
|
+ return nil, errors.New("code and refresh_token are not allowed to be NULL at the same time")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.open.auth.token.app"); err != nil {
|
|
|
return
|
|
|
@@ -418,15 +420,15 @@ func (a *AliPayClient) AliPayOpenAuthTokenApp(body BodyMap) (aliRsp *AliPayOpenA
|
|
|
|
|
|
// zhima.credit.score.get(芝麻分)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_8/zhima.credit.score.get
|
|
|
-func (a *AliPayClient) ZhimaCreditScoreGet(body BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error) {
|
|
|
+func (a *Client) ZhimaCreditScoreGet(body gopay.BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("product_code") == null {
|
|
|
+ if body.Get("product_code") == gopay.NULL {
|
|
|
body.Set("product_code", "w1010100100000000001")
|
|
|
}
|
|
|
- if body.Get("transaction_id") == null {
|
|
|
- return nil, errors.New("transaction_id is not allowed to be null")
|
|
|
+ if body.Get("transaction_id") == gopay.NULL {
|
|
|
+ return nil, errors.New("transaction_id is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "zhima.credit.score.get"); err != nil {
|
|
|
return
|
|
|
@@ -445,21 +447,21 @@ func (a *AliPayClient) ZhimaCreditScoreGet(body BodyMap) (aliRsp *ZhimaCreditSco
|
|
|
|
|
|
// alipay.user.certify.open.initialize(身份认证初始化服务)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.initialize
|
|
|
-func (a *AliPayClient) AliPayUserCertifyOpenInit(body BodyMap) (aliRsp *AliPayUserCertifyOpenInitResponse, err error) {
|
|
|
+func (a *Client) AliPayUserCertifyOpenInit(body gopay.BodyMap) (aliRsp *AliPayUserCertifyOpenInitResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("biz_code") == null {
|
|
|
- return nil, errors.New("biz_code is not allowed to be null")
|
|
|
+ if body.Get("biz_code") == gopay.NULL {
|
|
|
+ return nil, errors.New("biz_code is not allowed to be NULL")
|
|
|
}
|
|
|
- if body.Get("outer_order_no") == null {
|
|
|
- return nil, errors.New("outer_order_no is not allowed to be null")
|
|
|
+ if body.Get("outer_order_no") == gopay.NULL {
|
|
|
+ return nil, errors.New("outer_order_no is not allowed to be NULL")
|
|
|
}
|
|
|
- if body.Get("identity_param") == null {
|
|
|
- return nil, errors.New("identity_param is not allowed to be null")
|
|
|
+ if body.Get("identity_param") == gopay.NULL {
|
|
|
+ return nil, errors.New("identity_param is not allowed to be NULL")
|
|
|
}
|
|
|
- if body.Get("merchant_config") == null {
|
|
|
- return nil, errors.New("merchant_config is not allowed to be null")
|
|
|
+ if body.Get("merchant_config") == gopay.NULL {
|
|
|
+ return nil, errors.New("merchant_config is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.user.certify.open.initialize"); err != nil {
|
|
|
return
|
|
|
@@ -479,15 +481,15 @@ func (a *AliPayClient) AliPayUserCertifyOpenInit(body BodyMap) (aliRsp *AliPayUs
|
|
|
// 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 (a *AliPayClient) AliPayUserCertifyOpenCertify(body BodyMap) (certifyUrl string, err error) {
|
|
|
+func (a *Client) AliPayUserCertifyOpenCertify(body gopay.BodyMap) (certifyUrl string, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("certify_id") == null {
|
|
|
- return null, errors.New("certify_id is not allowed to be null")
|
|
|
+ if body.Get("certify_id") == gopay.NULL {
|
|
|
+ return gopay.NULL, errors.New("certify_id is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.user.certify.open.certify"); err != nil {
|
|
|
- return null, err
|
|
|
+ return gopay.NULL, err
|
|
|
}
|
|
|
certifyUrl = string(bs)
|
|
|
return
|
|
|
@@ -495,12 +497,12 @@ func (a *AliPayClient) AliPayUserCertifyOpenCertify(body BodyMap) (certifyUrl st
|
|
|
|
|
|
// alipay.user.certify.open.query(身份认证记录查询)
|
|
|
// 文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.query
|
|
|
-func (a *AliPayClient) AliPayUserCertifyOpenQuery(body BodyMap) (aliRsp *AliPayUserCertifyOpenQueryResponse, err error) {
|
|
|
+func (a *Client) AliPayUserCertifyOpenQuery(body gopay.BodyMap) (aliRsp *AliPayUserCertifyOpenQueryResponse, err error) {
|
|
|
var (
|
|
|
bs []byte
|
|
|
)
|
|
|
- if body.Get("certify_id") == null {
|
|
|
- return nil, errors.New("certify_id is not allowed to be null")
|
|
|
+ if body.Get("certify_id") == gopay.NULL {
|
|
|
+ return nil, errors.New("certify_id is not allowed to be NULL")
|
|
|
}
|
|
|
if bs, err = a.doAliPay(body, "alipay.user.certify.open.query"); err != nil {
|
|
|
return
|
|
|
@@ -518,7 +520,7 @@ func (a *AliPayClient) AliPayUserCertifyOpenQuery(body BodyMap) (aliRsp *AliPayU
|
|
|
}
|
|
|
|
|
|
// 向支付宝发送请求
|
|
|
-func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err error) {
|
|
|
+func (a *Client) doAliPay(body gopay.BodyMap, method string) (bs []byte, err error) {
|
|
|
var (
|
|
|
bodyStr, sign, url string
|
|
|
bodyBs []byte
|
|
|
@@ -529,64 +531,64 @@ func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err err
|
|
|
}
|
|
|
bodyStr = string(bodyBs)
|
|
|
}
|
|
|
- pubBody := make(BodyMap)
|
|
|
+ pubBody := make(gopay.BodyMap)
|
|
|
pubBody.Set("app_id", a.AppId)
|
|
|
pubBody.Set("method", method)
|
|
|
pubBody.Set("format", "JSON")
|
|
|
- if a.AppCertSN != null {
|
|
|
+ if a.AppCertSN != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("app_cert_sn", a.AppCertSN)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.AliPayRootCertSN != null {
|
|
|
+ if a.AliPayRootCertSN != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.ReturnUrl != null {
|
|
|
+ if a.ReturnUrl != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("return_url", a.ReturnUrl)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.Charset == null {
|
|
|
+ if a.Charset == gopay.NULL {
|
|
|
pubBody.Set("charset", "utf-8")
|
|
|
} else {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("charset", a.Charset)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.SignType == null {
|
|
|
+ if a.SignType == gopay.NULL {
|
|
|
pubBody.Set("sign_type", "RSA2")
|
|
|
} else {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("sign_type", a.SignType)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- pubBody.Set("timestamp", time.Now().Format(TimeLayout))
|
|
|
+ pubBody.Set("timestamp", time.Now().Format(gopay.TimeLayout))
|
|
|
pubBody.Set("version", "1.0")
|
|
|
- if a.NotifyUrl != null {
|
|
|
+ if a.NotifyUrl != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("notify_url", a.NotifyUrl)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.AppAuthToken != null {
|
|
|
+ if a.AppAuthToken != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("app_auth_token", a.AppAuthToken)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if a.AuthToken != null {
|
|
|
+ if a.AuthToken != gopay.NULL {
|
|
|
a.mu.RLock()
|
|
|
pubBody.Set("auth_token", a.AuthToken)
|
|
|
a.mu.RUnlock()
|
|
|
}
|
|
|
- if bodyStr != null {
|
|
|
+ if bodyStr != gopay.NULL {
|
|
|
pubBody.Set("biz_content", bodyStr)
|
|
|
}
|
|
|
if sign, err = getRsaSign(pubBody, pubBody.Get("sign_type"), FormatPrivateKey(a.PrivateKey)); err != nil {
|
|
|
return
|
|
|
}
|
|
|
pubBody.Set("sign", sign)
|
|
|
- param := FormatAliPayURLParam(pubBody)
|
|
|
+ param := FormatURLParam(pubBody)
|
|
|
if method == "alipay.trade.app.pay" {
|
|
|
return []byte(param), nil
|
|
|
}
|
|
|
@@ -604,13 +606,13 @@ func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err err
|
|
|
return []byte(zfbBaseUrl + "?" + param), nil
|
|
|
}
|
|
|
}
|
|
|
- httpClient := NewHttpClient()
|
|
|
+ httpClient := gopay.NewHttpClient()
|
|
|
if !a.IsProd {
|
|
|
url = zfbSandboxBaseUrlUtf8
|
|
|
} else {
|
|
|
url = zfbBaseUrlUtf8
|
|
|
}
|
|
|
- res, bs, errs := httpClient.Type(TypeForm).Post(url).SendString(param).EndBytes()
|
|
|
+ res, bs, errs := httpClient.Type(gopay.TypeForm).Post(url).SendString(param).EndBytes()
|
|
|
if len(errs) > 0 {
|
|
|
return nil, errs[0]
|
|
|
}
|