Jerry 6 lat temu
rodzic
commit
9d991f0a02
2 zmienionych plików z 7 dodań i 7 usunięć
  1. 1 1
      alipay_client_test.go
  2. 6 6
      alipay_server_api.go

+ 1 - 1
alipay_client_test.go

@@ -77,7 +77,7 @@ func TestAliPayClient_AliPayTradePagePay(t *testing.T) {
 	//请求参数
 	body := make(BodyMap)
 	body.Set("subject", "网站测试支付")
-	body.Set("out_trade_no", "GYWX201901301040355706100427")
+	body.Set("out_trade_no", "GYWX201901301040355706100428")
 	body.Set("quit_url", "https://www.igoogle.ink")
 	body.Set("total_amount", "88.88")
 	body.Set("product_code", "FAST_INSTANT_TRADE_PAY")

+ 6 - 6
alipay_server_api.go

@@ -116,8 +116,8 @@ func VerifyAliPayResultSign(aliPayPublicKey string, notifyRsp *AliPayNotifyReque
 			newBody.Set(k, v)
 		}
 	}
-
-	sign, err := getRsaSign(newBody, aliPayPublicKey)
+	pKey := FormatAliPayPublicKey(aliPayPublicKey)
+	sign, err := getRsaSign(newBody, pKey)
 	if err != nil {
 		return false, ""
 	}
@@ -169,12 +169,12 @@ func FormatPrivateKey(privateKey string) (pKey string) {
 }
 
 //格式化秘钥
-func FormatAliPayPublicKey(publickKey string) (pKey string) {
+func FormatAliPayPublicKey(publicKey string) (pKey string) {
 	buffer := new(bytes.Buffer)
 	buffer.WriteString("-----BEGIN PUBLIC KEY-----\n")
 
 	rawLen := 64
-	keyLen := len(publickKey)
+	keyLen := len(publicKey)
 	raws := keyLen / rawLen
 	temp := keyLen % rawLen
 
@@ -185,9 +185,9 @@ func FormatAliPayPublicKey(publickKey string) (pKey string) {
 	end := start + rawLen
 	for i := 0; i < raws; i++ {
 		if i == raws-1 {
-			buffer.WriteString(publickKey[start:])
+			buffer.WriteString(publicKey[start:])
 		} else {
-			buffer.WriteString(publickKey[start:end])
+			buffer.WriteString(publicKey[start:end])
 		}
 		buffer.WriteString("\n")
 		start += rawLen