Skip to content

Commit 183a519

Browse files
authored
Fix/alipay API (#456)
* v1.5.109 --------- Co-authored-by: Jerry <Jerry>
1 parent 04f9468 commit 183a519

13 files changed

+77
-79
lines changed

alipay/client_request.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
162162
return nil, err
163163
}
164164
switch method {
165-
case "alipay.trade.app.pay", "alipay.fund.auth.order.app.freeze", "zhima.credit.pe.zmgo.sign.apply", "zhima.credit.payafteruse.creditagreement.sign":
165+
case "alipay.trade.app.pay", "alipay.fund.auth.order.app.freeze",
166+
"alipay.fund.trans.app.pay", "alipay.user.agreement.page.sign",
167+
"zhima.credit.pe.zmgo.sign.apply", "zhima.credit.payafteruse.creditagreement.sign":
166168
return []byte(param), nil
167169
case "alipay.trade.wap.pay", "alipay.trade.page.pay", "alipay.user.certify.open.certify":
168170
if !a.IsProd {
@@ -218,7 +220,9 @@ func (a *Client) DoAliPay(ctx context.Context, bm gopay.BodyMap, method string,
218220
return nil, err
219221
}
220222
switch method {
221-
case "alipay.trade.app.pay", "alipay.fund.auth.order.app.freeze":
223+
case "alipay.trade.app.pay", "alipay.fund.auth.order.app.freeze",
224+
"alipay.fund.trans.app.pay", "alipay.user.agreement.page.sign",
225+
"zhima.credit.pe.zmgo.sign.apply", "zhima.credit.payafteruse.creditagreement.sign":
222226
return []byte(param), nil
223227
case "alipay.trade.wap.pay", "alipay.trade.page.pay", "alipay.user.certify.open.certify":
224228
if !a.IsProd {
@@ -244,7 +248,7 @@ func (a *Client) DoAliPay(ctx context.Context, bm gopay.BodyMap, method string,
244248
}
245249
}
246250

247-
// 保持和官方 SDK 命名方式一致
251+
// Deprecated
248252
func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method string, authToken ...string) (url string, err error) {
249253
var (
250254
bizContent string

alipay/funds_api.go

+8-16
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (a *Client) FundAuthOrderVoucherCreate(ctx context.Context, bm gopay.BodyMa
171171

172172
// alipay.fund.auth.order.app.freeze(线上资金授权冻结接口)
173173
// 文档地址: https://opendocs.alipay.com/open/02f912
174-
func (a *Client) FundAuthOrderAppFreeze(ctx context.Context, bm gopay.BodyMap) (payParam string, err error) {
174+
func (a *Client) FundAuthOrderAppFreeze(ctx context.Context, bm gopay.BodyMap) (orderStr string, err error) {
175175
err = bm.CheckEmptyError("out_order_no", "out_request_no", "order_title", "amount", "product_code")
176176
if err != nil {
177177
return gopay.NULL, err
@@ -180,8 +180,8 @@ func (a *Client) FundAuthOrderAppFreeze(ctx context.Context, bm gopay.BodyMap) (
180180
if bs, err = a.doAliPay(ctx, bm, "alipay.fund.auth.order.app.freeze"); err != nil {
181181
return "", err
182182
}
183-
payParam = string(bs)
184-
return payParam, nil
183+
orderStr = string(bs)
184+
return orderStr, nil
185185
}
186186

187187
// alipay.fund.auth.order.unfreeze(资金授权解冻接口)
@@ -320,25 +320,17 @@ func (a *Client) FundBatchDetailQuery(ctx context.Context, bm gopay.BodyMap) (al
320320

321321
// alipay.fund.trans.app.pay(现金红包无线支付接口)
322322
// 文档地址: https://opendocs.alipay.com/open/03rbyf
323-
func (a *Client) FundTransAppPay(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundTransAppPayResponse, err error) {
323+
func (a *Client) FundTransAppPay(ctx context.Context, bm gopay.BodyMap) (pageRedirectionData string, err error) {
324324
err = bm.CheckEmptyError("out_biz_no", "trans_amount", "product_code", "biz_scene")
325325
if err != nil {
326-
return nil, err
326+
return gopay.NULL, err
327327
}
328328
var bs []byte
329329
if bs, err = a.doAliPay(ctx, bm, "alipay.fund.trans.app.pay"); err != nil {
330-
return nil, err
331-
}
332-
aliRsp = new(FundTransAppPayResponse)
333-
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
334-
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
335-
}
336-
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
337-
return aliRsp, err
330+
return "", err
338331
}
339-
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
340-
aliRsp.SignData = signData
341-
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
332+
pageRedirectionData = string(bs)
333+
return pageRedirectionData, nil
342334
}
343335

344336
// alipay.fund.trans.payee.bind.query(资金收款账号绑定关系查询)

alipay/funds_api_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,24 @@ func TestClient_FundTransPagePay(t *testing.T) {
9898

9999
aliRsp, err := client.FundTransPagePay(ctx, bm)
100100
if err != nil {
101-
//xlog.Errorf("client.FundTransPagePay(%+v),error:%+v", bm, err)
101+
xlog.Errorf("client.FundTransPagePay(%+v),err:%+v", bm, err)
102102
return
103103
}
104104
xlog.Debug("aliRsp:", *aliRsp)
105105
}
106+
107+
func TestClient_FundTransAppPay(t *testing.T) {
108+
bm := make(gopay.BodyMap)
109+
bm.Set("out_biz_no", "20180628000035").
110+
Set("trans_amount", "8.88").
111+
Set("product_code", "STD_RED_PACKET").
112+
Set("biz_scene", "PERSONAL_PAY").
113+
Set("order_title", "钉钉拼手气红包")
114+
115+
pageRedirectionData, err := client.FundTransAppPay(ctx, bm)
116+
if err != nil {
117+
xlog.Errorf("client.FundTransAppPay(%+v),err:%+v", bm, err)
118+
return
119+
}
120+
xlog.Debug("pageRedirectionData: ", pageRedirectionData)
121+
}

alipay/member_api.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (a *Client) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (al
209209

210210
// alipay.user.agreement.page.sign(支付宝个人协议页面签约接口)
211211
// 文档地址:https://opendocs.alipay.com/open/8bccfa0b_alipay.user.agreement.page.sign
212-
func (a *Client) UserAgreementPageSign(ctx context.Context, bm gopay.BodyMap) (ret string, err error) {
212+
func (a *Client) UserAgreementPageSign(ctx context.Context, bm gopay.BodyMap) (pageRedirectionData string, err error) {
213213
err = bm.CheckEmptyError("personal_product_code")
214214
if err != nil {
215215
return gopay.NULL, err
@@ -221,27 +221,43 @@ func (a *Client) UserAgreementPageSign(ctx context.Context, bm gopay.BodyMap) (r
221221
return string(bs), nil
222222
}
223223

224-
// alipay.user.agreement.page.sign(APP 支付宝个人协议页面签约接口)
225-
// 文档地址:https://opendocs.alipay.com/open/00a05b 通过 App 唤起支付宝的签约页面
224+
// alipay.user.agreement.page.sign(支付宝个人协议页面签约接口) - PC转二维码唤起签约页
225+
// 文档地址:https://opendocs.alipay.com/open/08ayiq?pathHash=a2d4e097#PC%E8%BD%AC%E4%BA%8C%E7%BB%B4%E7%A0%81%E5%94%A4%E8%B5%B7%E7%AD%BE%E7%BA%A6%E9%A1%B5
226+
func (a *Client) UserAgreementPageSignInQRCode(ctx context.Context, bm gopay.BodyMap) (qrcode string, err error) {
227+
err = bm.CheckEmptyError("personal_product_code", "access_params")
228+
if err != nil {
229+
return gopay.NULL, err
230+
}
231+
var bs []byte
232+
if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.page.sign"); err != nil {
233+
return "", err
234+
}
235+
// 该链接里面的 APPID 为固定值,不可修改
236+
// 生成唤起客户端。把signParams使用 UTF-8 字符集整体做一次 encode
237+
qrcode = "alipays://platformapi/startapp?appId=60000157&appClearTop=false&startMultApp=YES&sign_params=" + url.QueryEscape(string(bs))
238+
return qrcode, nil
239+
}
240+
241+
// Deprecated
242+
// 后续会删除,请使用 UserAgreementPageSignInQRCode() 替代
226243
func (a *Client) UserAgreementPageSignInApp(ctx context.Context, bm gopay.BodyMap) (ret string, err error) {
227-
err = bm.CheckEmptyError("personal_product_code")
244+
err = bm.CheckEmptyError("personal_product_code", "access_params")
228245
if err != nil {
229246
return gopay.NULL, err
230247
}
231248

232-
var bs string
233-
// 参考官方示例
234-
// PageExecute get方式,生成url
235-
if bs, err = a.PageExecute(ctx, bm, "alipay.user.agreement.page.sign"); err != nil {
249+
// 参考官方示例 PageExecute get方式,生成 uri
250+
uri, err := a.PageExecute(ctx, bm, "alipay.user.agreement.page.sign")
251+
if err != nil {
236252
return "", err
237253
}
238254

239-
// / 生成的url地址去除 http://openapi.alipay.com/gateway.do
255+
// / 生成的url地址去除 http://openapi.alipay.com/gateway.do?
240256
replaceUrl := baseUrl + "?"
241257
if !a.IsProd {
242258
replaceUrl = sandboxBaseUrl + "?"
243259
}
244-
signParams := strings.Replace(bs, replaceUrl, "", 1)
260+
signParams := strings.Replace(uri, replaceUrl, "", 1)
245261

246262
// 该链接里面的 APPID 为固定值,不可修改)
247263
// 生成唤起客户端。把signParams使用 UTF-8 字符集整体做一次 encode

alipay/member_api_test.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestUserAgreementTransfer(t *testing.T) {
122122
xlog.Debug("aliRsp:", *aliRsp)
123123
}
124124

125-
func TestUserAgreementPageSignInApp(t *testing.T) {
125+
func TestUserAgreementPageSignInQRCode(t *testing.T) {
126126
// 请求参数
127127
bm := make(gopay.BodyMap)
128128
bm.Set("personal_product_code", "CYCLE_PAY_AUTH_P")
@@ -143,8 +143,7 @@ func TestUserAgreementPageSignInApp(t *testing.T) {
143143
})
144144

145145
// 发起请求
146-
link, err := client.UserAgreementPageSignInApp(ctx, bm)
147-
xlog.Info(err)
146+
qrcode, err := client.UserAgreementPageSignInQRCode(ctx, bm)
148147
if err != nil {
149148
if bizErr, ok := IsBizError(err); ok {
150149
xlog.Errorf("%+v", bizErr)
@@ -153,8 +152,7 @@ func TestUserAgreementPageSignInApp(t *testing.T) {
153152
}
154153
return
155154
}
156-
157-
xlog.Debug("aliRsp:", link)
155+
xlog.Debug("aliRsp:", qrcode)
158156
}
159157

160158
func TestUserTwostageCommonUse(t *testing.T) {

alipay/mode_funds.go

-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ type FundBatchDetailQueryResponse struct {
9191
Sign string `json:"sign"`
9292
}
9393

94-
type FundTransAppPayResponse struct {
95-
Response *FundTransAppPay `json:"alipay_fund_trans_app_pay_response"`
96-
AlipayCertSn string `json:"alipay_cert_sn,omitempty"`
97-
SignData string `json:"-"`
98-
Sign string `json:"sign"`
99-
}
100-
10194
type FundTransPayeeBindQueryRsp struct {
10295
Response *FundTransPayeeBindQuery `json:"alipay_fund_trans_payee_bind_query_response"`
10396
AlipayCertSn string `json:"alipay_cert_sn,omitempty"`

alipay/payment_api.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (a *Client) TradePrecreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *
6161

6262
// alipay.trade.app.pay(app支付接口2.0)
6363
// 文档地址:https://opendocs.alipay.com/open/02e7gq
64-
func (a *Client) TradeAppPay(ctx context.Context, bm gopay.BodyMap) (payParam string, err error) {
64+
func (a *Client) TradeAppPay(ctx context.Context, bm gopay.BodyMap) (orderStr string, err error) {
6565
err = bm.CheckEmptyError("out_trade_no", "total_amount", "subject")
6666
if err != nil {
6767
return gopay.NULL, err
@@ -70,8 +70,8 @@ func (a *Client) TradeAppPay(ctx context.Context, bm gopay.BodyMap) (payParam st
7070
if bs, err = a.doAliPay(ctx, bm, "alipay.trade.app.pay"); err != nil {
7171
return gopay.NULL, err
7272
}
73-
payParam = string(bs)
74-
return payParam, nil
73+
orderStr = string(bs)
74+
return orderStr, nil
7575
}
7676

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

alipay/v3/client_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77

88
"github.com/go-pay/gopay"
99
"github.com/go-pay/gopay/alipay/cert"
10-
"github.com/go-pay/gopay/pkg/js"
1110
"github.com/go-pay/util"
11+
"github.com/go-pay/util/js"
1212
"github.com/go-pay/xlog"
1313
)
1414

@@ -68,7 +68,7 @@ func TestDoAliPayAPISelfV3(t *testing.T) {
6868
xlog.Errorf("client.TradePrecreate(), err:%v", err)
6969
return
7070
}
71-
xlog.Debugf("aliRsp:%s", js.Marshal(rsp))
71+
xlog.Debugf("aliRsp:%s", js.MarshalString(rsp))
7272
if res.StatusCode != Success {
7373
xlog.Errorf("aliRsp.StatusCode:%d", res.StatusCode)
7474
return
@@ -106,7 +106,7 @@ func TestClientV3_Transfer(t *testing.T) {
106106
return
107107
}
108108

109-
xlog.Debugf("aliRsp:%s", js.Marshal(res))
109+
xlog.Debugf("aliRsp:%s", js.MarshalString(res))
110110
if res.StatusCode != Success {
111111
xlog.Errorf("aliRsp.StatusCode:%d", res.StatusCode)
112112
return

alipay/v3/payment_api_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"testing"
55

66
"github.com/go-pay/gopay"
7-
"github.com/go-pay/gopay/pkg/js"
87
"github.com/go-pay/util"
8+
"github.com/go-pay/util/js"
99
"github.com/go-pay/xlog"
1010
)
1111

@@ -22,7 +22,7 @@ func TestTradePrecreate(t *testing.T) {
2222
xlog.Errorf("client.TradePrecreate(), err:%v", err)
2323
return
2424
}
25-
xlog.Debugf("aliRsp:%s", js.Marshal(aliRsp))
25+
xlog.Debugf("aliRsp:%s", js.MarshalString(aliRsp))
2626

2727
if aliRsp.StatusCode != Success {
2828
xlog.Errorf("aliRsp.StatusCode:%d", aliRsp.StatusCode)

constant.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const (
77
OK = "OK"
88
DebugOff = 0
99
DebugOn = 1
10-
Version = "v1.5.108"
10+
Version = "v1.5.109"
1111
)
1212

1313
type DebugSwitch int8

doc/alipay.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ xlog.Infof("%+v", phone)
278278
* 交易分账查询接口:`client.TradeOrderSettleQuery()`
279279
* 商家扣款
280280
* 支付宝个人协议页面签约接口: `client.UserAgreementPageSign()`
281-
* 支付宝个人协议页面签约接口(App 专用,生成唤醒签约页面链接): `client.UserAgreementPageSignInApp()`
281+
* 支付宝个人协议页面签约接口 - PC转二维码唤起签约页: `client.UserAgreementPageSignInQRCode()`
282282
* 支付宝个人代扣协议查询接口: `client.UserAgreementQuery()`
283283
* 支付宝个人代扣协议解约接口: `client.UserAgreementPageUnSign()`
284284
* 周期性扣款协议执行计划修改接口: `client.UserAgreementExecutionplanModify()`

pkg/js/json.go

-27
This file was deleted.

release_note.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 版本号:v1.5.109
2+
3+
* 修改记录:
4+
* 支付宝:作废 client.UserAgreementPageSignInApp() 方法,使用 client.UserAgreementPageSignInQRCode() 方法替换。
5+
* 支付宝:修改 client.FundTransAppPay() 方法返回参数。
6+
17
## 版本号:v1.5.108
28

39
* 修改记录:

0 commit comments

Comments
 (0)