fix: 富友回调应答XMLName缺失 + term_ip自动探测服务器IP替代硬编码
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m8s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m8s
This commit is contained in:
@@ -54,7 +54,7 @@ type fuiouPaymentProvider struct {
|
|||||||
// CreateJSAPIPayment 创建富友 JSAPI 预下单。
|
// CreateJSAPIPayment 创建富友 JSAPI 预下单。
|
||||||
func (f *fuiouPaymentProvider) CreateJSAPIPayment(ctx context.Context, orderNo, description, openID string, amount int) (*PaymentResult, error) {
|
func (f *fuiouPaymentProvider) CreateJSAPIPayment(ctx context.Context, orderNo, description, openID string, amount int) (*PaymentResult, error) {
|
||||||
amountStr := strconv.Itoa(amount)
|
amountStr := strconv.Itoa(amount)
|
||||||
resp, err := f.client.WxPreCreate(orderNo, amountStr, description, "127.0.0.1", f.tradeType, f.appID, openID)
|
resp, err := f.client.WxPreCreate(orderNo, amountStr, description, fuiou.GetServerIP(), f.tradeType, f.appID, openID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(errors.CodeFuiouPayFailed, err, "富友预下单失败")
|
return nil, errors.Wrap(errors.CodeFuiouPayFailed, err, "富友预下单失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
@@ -255,6 +257,26 @@ func generateRandomStr() string {
|
|||||||
return fmt.Sprintf("%x", b)
|
return fmt.Sprintf("%x", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
serverIP string
|
||||||
|
serverIPOnce sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetServerIP 获取服务器非回环 IPv4 地址(进程生命周期内缓存)
|
||||||
|
func GetServerIP() string {
|
||||||
|
serverIPOnce.Do(func() {
|
||||||
|
addrs, _ := net.InterfaceAddrs()
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {
|
||||||
|
serverIP = ipNet.IP.String()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serverIP = "127.0.0.1"
|
||||||
|
})
|
||||||
|
return serverIP
|
||||||
|
}
|
||||||
|
|
||||||
// parsePrivateKey 解析 Base64 编码的 RSA 私钥
|
// parsePrivateKey 解析 Base64 编码的 RSA 私钥
|
||||||
// 支持多种格式: PEM(PKCS1/PKCS8) 和 DER(PKCS1/PKCS8)
|
// 支持多种格式: PEM(PKCS1/PKCS8) 和 DER(PKCS1/PKCS8)
|
||||||
func parsePrivateKey(base64Str string) (*rsa.PrivateKey, error) {
|
func parsePrivateKey(base64Str string) (*rsa.PrivateKey, error) {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ type NotifyRequest struct {
|
|||||||
|
|
||||||
// NotifyResponse 回调响应
|
// NotifyResponse 回调响应
|
||||||
type NotifyResponse struct {
|
type NotifyResponse struct {
|
||||||
ResultCode string `xml:"result_code"` // 结果码
|
XMLName xml.Name `xml:"xml"`
|
||||||
ResultMsg string `xml:"result_msg"` // 结果消息
|
ResultCode string `xml:"result_code"` // 结果码
|
||||||
|
ResultMsg string `xml:"result_msg"` // 结果消息
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user