Skip to content

Commit

Permalink
调整测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
smartwalle committed Apr 11, 2017
1 parent 18deeb6 commit 4a647ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 57 deletions.
53 changes: 4 additions & 49 deletions alipay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package alipay

import (
"testing"
"os"
"fmt"
)

Expand Down Expand Up @@ -47,50 +46,11 @@ vTlWbWwZHVDP85dioLE9mfo5+Hh3SmHDi3TaVXjxeJsUgHkRgOX7

var appID = "2016073100129537"

func TestSign(t *testing.T) {

// var publickKey = []byte(`-----BEGIN PUBLIC KEY-----
//MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZ8lmnG4TMFqJty0FoqAHKxEIs
//IcZaM2E8PXjXoQ+iszREsqi1B5Lmq7GeJ1/9N+OGDIjpDHnEfMMlHrj+5gYSTPab
//bLGCvtcluPbI6R+uJz3uYGtPzqn4EKiNvC1ixANLmbhdqbb3KAkCcRltZOZYSerG
//VE069nKjmSWRRlWJkQIDAQAB
//-----END PUBLIC KEY-----`)

// var privateKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
//MIICXgIBAAKBgQDZ8lmnG4TMFqJty0FoqAHKxEIsIcZaM2E8PXjXoQ+iszREsqi1
//B5Lmq7GeJ1/9N+OGDIjpDHnEfMMlHrj+5gYSTPabbLGCvtcluPbI6R+uJz3uYGtP
//zqn4EKiNvC1ixANLmbhdqbb3KAkCcRltZOZYSerGVE069nKjmSWRRlWJkQIDAQAB
//AoGBAKGAiRbfuYRSsYKSv6GB/fH3hOGXFZj5wfAVzVpcK23xRaYyjfm35w+v4yrD
//GspVg/BtkXbAm+sSWLlFDuk0IwJGhqxmIJ6TvxRFDxep4Kz5LjPlTvG1/mvSKKW6
//1uUZquT2Ll0qy2hwyui8K08+CWVxAO5NMskYHaztF8QArjgBAkEA8UtE8pawG/Cj
//24kj//y10f36Yt9tQ00/Nu7hfLXJe292zWn0cCEZG2ukkt6kQQtNoUBpRMTj9cQR
//hd+2hPgX8QJBAOc6z0sJUWwG6m13nSVlu6j2wmZTp6W9U52WNR364L1UDfn7MI/X
//7roW1SdwQwdYNVgwvt2N1MNJheTxt5/ZK6ECQQCs3Ta08J2UNq69LZ+72ejMWz7R
//LK3TZHjgOv0R4g5JPw6GlNzIo/2ftls92QEllBp2ZnXEDaYewOuo1B+nXTGRAkEA
//h8qCp+dN+KnLDAQ9thObdCuNmHgyMOQRca8ffH6zcpwlJRP9vcuqd4AnJ2UHCA4m
//Ladav1OmihToW74T/vyTYQJAAf+PKLRD+O2CuwcZJG0taEqL0RR+kXMEd0wLp4EN
//pFwKUHMh+rm4/Asgy126+rS6Hr0QuNuoJuQbAr3Q28h7PQ==
//-----END RSA PRIVATE KEY-----`)

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

//var p = AliPayFastpayTradeRefundQuery{}
//p.OutTradeNo = "1111111"
//p.OutRequestNo = "1111111"
//
//var r, err = client.TradeFastpayRefundQuery(p)
//if err != nil {
// fmt.Println(err)
// return
//}
//fmt.Println(r.IsSuccess(), r)
func TestSign(t *testing.T) {

//var p = AliPayTradeRefund{}
//p.RefundAmount = "10.00"
//p.OutTradeNo = "1111111"
//
//var r, err = client.TradeRefund(p)
//fmt.Println(r.IsSuccess(), err, r)
var client = New(appID, partnerID, publicKey, privateKey, false)

var p = AliPayTradeWapPay{}
p.NotifyURL = "http://203.86.24.181:3000/alipay"
Expand All @@ -100,11 +60,6 @@ func TestSign(t *testing.T) {
p.TotalAmount = "10.00"
p.ProductCode = "eeeeee"

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

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

f.WriteString(html)
f.Close()
}
13 changes: 5 additions & 8 deletions wap.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
package alipay

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, url *url.URL, err error) {
func (this *AliPay) TradeWapPay(param AliPayTradeWapPay) (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 "", nil, 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 "", nil, err
return nil, err
}
defer rep.Body.Close()

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

0 comments on commit 4a647ab

Please sign in to comment.