Jerry hace 7 años
padre
commit
f7ac49eca2
Se han modificado 6 ficheros con 71 adiciones y 90 borrados
  1. 8 0
      README.md
  2. 10 0
      alipay_client.go
  3. 0 23
      alipay_params.go
  4. 0 13
      alipay_rsp.go
  5. 0 54
      util.go
  6. 53 0
      wechat_params.go

+ 8 - 0
README.md

@@ -41,6 +41,14 @@ $ go get github.com/iGoogle-ink/gopay
 
 参考文档:[微信支付文档](https://pay.weixin.qq.com/wiki/doc/api/index.html)
 
+### 付款结果回调,需回复微信平台是否成功
+```go
+rsp := new(gopay.WeChatNotifyResponse) //回复微信的数据
+
+rsp.ReturnCode = "SUCCESS"
+rsp.ReturnMsg = "OK"
+return c.String(http.StatusOK, rsp.ToXmlString())
+```
 
 ### 统一下单
 ```go

+ 10 - 0
alipay_client.go

@@ -1,5 +1,9 @@
 package gopay
 
+import (
+	"crypto/tls"
+)
+
 type aliPayClient struct {
 	AppId     string
 	MchId     string
@@ -97,3 +101,9 @@ func (this *aliPayClient) ZhimaCreditScoreBriefGet() {
 func (this *aliPayClient) ZhimaCreditScoreGet() {
 
 }
+
+//向支付宝发送请求
+func (this *aliPayClient) doAliPay(body BodyMap, method string, tlsConfig ...*tls.Config) (bytes []byte, err error) {
+
+	return bytes, nil
+}

+ 0 - 23
alipay_params.go

@@ -4,26 +4,3 @@
 //  * DateTime:2019/1/13 14:42
 //==================================
 package gopay
-
-type aliPayParams struct {
-	NonceStr       string `xml:"nonce_str"`
-	Body           string `xml:"body"`
-	OutTradeNo     string `xml:"out_trade_no"`
-	TotalFee       int    `xml:"total_fee"`
-	SpbillCreateIp string `xml:"spbill_create_ip"`
-	NotifyUrl      string `xml:"notify_url"`
-	TradeType      string `xml:"trade_type"`
-
-	DeviceInfo string `xml:"device_info"`
-	SignType   string `xml:"sign_type"`
-	Detail     string `xml:"detail"`
-	Attach     string `xml:"attach"`
-	FeeType    string `xml:"fee_type"`
-	TimeStart  string `xml:"time_start"`
-	TimeExpire string `xml:"time_expire"`
-	GoodsTag   string `xml:"goods_tag"`
-	ProductId  string `xml:"product_id"`
-	LimitPay   string `xml:"limit_pay"`
-	Openid     string `xml:"openid"`
-	Receipt    string `xml:"receipt"`
-}

+ 0 - 13
alipay_rsp.go

@@ -4,16 +4,3 @@
 //  * DateTime:2019/1/16 0:30
 //==================================
 package gopay
-
-type aliPayResponse struct {
-	ReturnCode string `xml:"return_code"`
-	ReturnMsg  string `xml:"return_msg"`
-	Appid      string `xml:"appid"`
-	MchId      string `xml:"mch_id"`
-	DeviceInfo string `xml:"device_info"`
-	NonceStr   string `xml:"nonce_str"`
-	Sign       string `xml:"sign"`
-	ResultCode string `xml:"result_code"`
-	PrepayId   string `xml:"prepay_id"`
-	TradeType  string `xml:"trade_type"`
-}

+ 0 - 54
util.go

@@ -1,12 +1,7 @@
 package gopay
 
 import (
-	"bytes"
-	"encoding/xml"
-	"errors"
-	"github.com/parnurzeal/gorequest"
 	"math/rand"
-	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -51,28 +46,6 @@ func GetRandomString(length int) string {
 	return string(result)
 }
 
-//获取根据Key排序后的请求参数字符串
-func sortSignParams(secretKey string, body BodyMap) string {
-	keyList := make([]string, 0)
-	for k := range body {
-		keyList = append(keyList, k)
-	}
-	sort.Strings(keyList)
-	buffer := new(bytes.Buffer)
-	for _, k := range keyList {
-		buffer.WriteString(k)
-		buffer.WriteString("=")
-
-		valueStr := convert2String(body[k])
-		buffer.WriteString(valueStr)
-
-		buffer.WriteString("&")
-	}
-	buffer.WriteString("key=")
-	buffer.WriteString(secretKey)
-	return buffer.String()
-}
-
 func convert2String(value interface{}) (valueStr string) {
 	switch v := value.(type) {
 	case int:
@@ -91,33 +64,6 @@ func convert2String(value interface{}) (valueStr string) {
 	return
 }
 
-//从微信提供的接口获取:SandboxSignkey
-func getSanBoxSignKey(mchId, nonceStr, sign string) (key string, err error) {
-	reqs := make(BodyMap)
-	reqs.Set("mch_id", mchId)
-	reqs.Set("nonce_str", nonceStr)
-	reqs.Set("sign", sign)
-
-	reqXml := generateXml(reqs)
-	//fmt.Println("req:::", reqXml)
-	_, byteList, errorList := gorequest.New().
-		Post(wxURL_SanBox_GetSignKey).
-		Type("xml").
-		SendString(reqXml).EndBytes()
-	if len(errorList) > 0 {
-		return "", errorList[0]
-	}
-	keyResponse := new(getSignKeyResponse)
-	err = xml.Unmarshal(byteList, keyResponse)
-	if err != nil {
-		return "", err
-	}
-	if keyResponse.ReturnCode == "FAIL" {
-		return "", errors.New(keyResponse.Retmsg)
-	}
-	return keyResponse.SandboxSignkey, nil
-}
-
 //解析时间
 func ParseDateTime(timeStr string) (datetime time.Time) {
 	datetime, _ = time.ParseInLocation(TimeLayout, timeStr, time.Local)

+ 53 - 0
wechat_params.go

@@ -6,6 +6,10 @@ import (
 	"crypto/md5"
 	"crypto/sha256"
 	"encoding/hex"
+	"encoding/xml"
+	"errors"
+	"github.com/parnurzeal/gorequest"
+	"sort"
 	"strings"
 )
 
@@ -64,6 +68,28 @@ func getLocalSign(secretKey string, signType string, body BodyMap) (sign string)
 	return
 }
 
+//获取根据Key排序后的请求参数字符串
+func sortSignParams(secretKey string, body BodyMap) string {
+	keyList := make([]string, 0)
+	for k := range body {
+		keyList = append(keyList, k)
+	}
+	sort.Strings(keyList)
+	buffer := new(bytes.Buffer)
+	for _, k := range keyList {
+		buffer.WriteString(k)
+		buffer.WriteString("=")
+
+		valueStr := convert2String(body[k])
+		buffer.WriteString(valueStr)
+
+		buffer.WriteString("&")
+	}
+	buffer.WriteString("key=")
+	buffer.WriteString(secretKey)
+	return buffer.String()
+}
+
 //从微信提供的接口获取:SandboxSignKey
 func getSanBoxSign(mchId, nonceStr, secretKey, signType string) (key string, err error) {
 	body := make(BodyMap)
@@ -80,6 +106,33 @@ func getSanBoxSign(mchId, nonceStr, secretKey, signType string) (key string, err
 	return
 }
 
+//从微信提供的接口获取:SandboxSignkey
+func getSanBoxSignKey(mchId, nonceStr, sign string) (key string, err error) {
+	reqs := make(BodyMap)
+	reqs.Set("mch_id", mchId)
+	reqs.Set("nonce_str", nonceStr)
+	reqs.Set("sign", sign)
+
+	reqXml := generateXml(reqs)
+	//fmt.Println("req:::", reqXml)
+	_, byteList, errorList := gorequest.New().
+		Post(wxURL_SanBox_GetSignKey).
+		Type("xml").
+		SendString(reqXml).EndBytes()
+	if len(errorList) > 0 {
+		return "", errorList[0]
+	}
+	keyResponse := new(getSignKeyResponse)
+	err = xml.Unmarshal(byteList, keyResponse)
+	if err != nil {
+		return "", err
+	}
+	if keyResponse.ReturnCode == "FAIL" {
+		return "", errors.New(keyResponse.Retmsg)
+	}
+	return keyResponse.SandboxSignkey, nil
+}
+
 //生成请求XML的Body体
 func generateXml(bm BodyMap) (reqXml string) {
 	buffer := new(bytes.Buffer)