Skip to content

Commit

Permalink
TradeWapPay 返回支付 URL
Browse files Browse the repository at this point in the history
  • Loading branch information
smartwalle committed Mar 6, 2017
1 parent 204b69c commit 3d222c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions alipay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package alipay
import (
"testing"
"os"
"fmt"
)

var publicKey = []byte(`-----BEGIN PUBLIC KEY-----
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestSign(t *testing.T) {
//pFwKUHMh+rm4/Asgy126+rS6Hr0QuNuoJuQbAr3Q28h7PQ==
//-----END RSA PRIVATE KEY-----`)

var client = New("2016073100129537", "2088102169227503", publicKey, privateKey, false)
var client = New(appID, "2088102169227503", publicKey, privateKey, false)

//var p = AliPayFastpayTradeRefundQuery{}
//p.OutTradeNo = "1111111"
Expand Down Expand Up @@ -99,7 +100,8 @@ func TestSign(t *testing.T) {
p.TotalAmount = "10.00"
p.ProductCode = "eeeeee"

var html, _ = client.TradeWapPay(p)
var html, url, _ = client.TradeWapPay(p)
fmt.Println(url)

var f, _ = os.Create("test.html")

Expand Down
2 changes: 1 addition & 1 deletion bill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"
)

func TestBillDownloadurlQuery(t *testing.T) {
func TestBillDownloadURLQuery(t *testing.T) {
type arg struct {
param BillDownloadURLQuery
wanted string
Expand Down
11 changes: 6 additions & 5 deletions wap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ import (
"io/ioutil"
"strings"
"net/http"
"net/url"
)

// TradeWapPay https://doc.open.alipay.com/docs/api.htm?spm=a219a.7395905.0.0.stK0ff&docType=4&apiId=1046
func (this *AliPay) TradeWapPay(param AliPayTradeWapPay) (html string, err error) {
func (this *AliPay) TradeWapPay(param AliPayTradeWapPay) (html string, url *url.URL, err error) {
var buf = strings.NewReader(this.URLValues(param).Encode())

req, err := http.NewRequest("POST", this.apiDomain, buf)
if err != nil {
return "", err
return "", nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")

rep, err := this.client.Do(req)
if err != nil {
return "", err
return "", nil, err
}
defer rep.Body.Close()

data, err := ioutil.ReadAll(rep.Body)
if err != nil {
return "", err
return "", nil, err
}
html = string(data)
return html, err
return html, rep.Request.URL, err
}

0 comments on commit 3d222c5

Please sign in to comment.