LAPTOP-PC6VHEF0\XIONGHUY 1 год назад
Родитель
Сommit
5914de1340

+ 2 - 0
RO_Server_Trunk-branch_0.1.39/rocommon/service/yamlconfig.go

@@ -136,6 +136,8 @@ type configSDK struct {
 	YouYiGameIdList    []string `yaml:"youyigameidlist"`
 	YouYiGameIdIOS     string   `yaml:"youyigameidios"`
 	YouYiGameIdListIOS []string `yaml:"youyigameidlistios"`
+	// 支付路由,配置在1服的配置文件中
+	PayPostRouter []string `yaml:"paypostrouter"`
 }
 
 func (this *ConfigServerNode) Error() string {

+ 3 - 2
RO_Server_Trunk-branch_0.1.39/roserver/gmweb/main.go

@@ -118,8 +118,9 @@ func main() {
 		r1.GET("/register", msg.WebGMProcessServerRegister)
 		r1.GET("/reload", msg.WebGMProcessServerConfigReload) //配置文件热加载
 
-		router.POST("/pay", msg.WebPayQuickNotify)           // SDKquick 畅梦nbSDK
-		router.POST("/pay/hwQucik", msg.WebPayHwQuickNotify) // 海外quick
+		router.POST("/pay", msg.WebPayQuickNotify)                                 // SDKquick 畅梦nbSDK
+		router.POST("/pay/hwQucik", msg.WebPayHwQuickNotify)                       // 海外quick
+		router.POST("/pay/hwQucikFromS1GmWeb", msg.WebPayHwQuickNotifyFromS1GmWeb) // 海外quick 1服转发到其他服,这里接收
 		//router.POST("/pay/nb", msg.WebPayNBSDKNotify)	// 畅梦牛逼SDK
 		router.POST("/pay/uni", msg.WebPayUniSDKNotify)
 		router.POST("/pay/nbh5", msg.WebPayNBH5Notify) // 畅梦h5

+ 90 - 1
RO_Server_Trunk-branch_0.1.39/roserver/gmweb/msg/web_paymsg.go

@@ -1,6 +1,7 @@
 package msg
 
 import (
+	"bytes"
 	"crypto/hmac"
 	"crypto/md5"
 	"encoding/hex"
@@ -156,6 +157,70 @@ func getMd5Sign(callbackKey string, params map[string]string) string {
 // 海外版quick回调
 func WebPayHwQuickNotify(c *gin.Context) {
 
+	if err := c.Request.ParseForm(); err != nil {
+		util.ErrorF("参数异常 c.Request.ParseForm() err: %v", err)
+		c.JSON(http.StatusOK, "FAIL")
+		return
+	}
+	params := make(map[string]string)
+	for key, value := range c.Request.PostForm {
+		params[key] = value[0] // 假设每个参数只有一个值
+	}
+	util.InfoF("获取支付回调参数:%v\n", params)
+	callbackKey := service.GetServiceConfig().SDKConfig.QuickCallbackKey
+	//util.InfoF("callbackKey:%v\n", callbackKey)
+	newSign := getMd5Sign(callbackKey, params)
+	if newSign != params["sign"] {
+		util.ErrorF("签名错误%v", params["sign"])
+		c.JSON(http.StatusOK, "FAIL")
+		return
+	}
+	uid := c.PostForm("uid")
+	cpOrderId := c.PostForm("cpOrderNo")
+	orderNo := c.PostForm("orderNo")
+	payAmount := c.PostForm("payAmount")
+	payCurrency := c.PostForm("payCurrency")
+	payType := c.PostForm("payType")
+	usdAmount := c.PostForm("usdAmount")
+	ntfData := &WebNotifyData{}
+	ntfData.CpOrderId = cpOrderId
+	ntfData.SdkOrderId = orderNo
+	ntfData.PayMethod = payType
+	ntfData.PayCurrency = payCurrency
+	ntfData.PayTime = uint64(util.GetTimeSeconds())
+	ntfData.PayChannel = "qk_hw"
+	util.DebugF("uid=%v cpOrderNo=%v orderNo=%v payAmount=%v payCurrency=%v payType=%v usdAmount=%v",
+		uid, cpOrderId, orderNo, payAmount, payCurrency, payType, usdAmount)
+	f64, err := strconv.ParseFloat(usdAmount, 32)
+	if err != nil {
+		fmt.Println("Error:", err)
+		return
+	}
+	webPayNotify(ntfData, float32(f64), c)
+
+	// 简单粗暴,直接给其他服转发,不需要确认是哪个服
+	payPostRouter := service.GetServiceConfig().SDKConfig.PayPostRouter
+	util.InfoF("payPostRouter:%v\n", payPostRouter)
+	// 组装转发body
+	var routerStr strings.Builder
+	for key, value := range params {
+		routerStr.WriteString(key)
+		routerStr.WriteString("=")
+		routerStr.WriteString(value)
+		routerStr.WriteString("&")
+	}
+	routerString := routerStr.String()
+	util.InfoF("支付 routerString:%v\n", routerString)
+	for _, urlPost := range payPostRouter {
+		sendPostToOtherServer(urlPost, []byte(routerString))
+	}
+
+	c.JSON(http.StatusOK, "SUCCESS")
+}
+
+// http://110.40.223.119:8002/pay/hwQucikFromS1GmWeb
+func WebPayHwQuickNotifyFromS1GmWeb(c *gin.Context) {
+
 	if err := c.Request.ParseForm(); err != nil {
 		util.ErrorF("参数异常 c.Request.ParseForm() err: %v", err)
 		c.JSON(http.StatusOK, "FAIL")
@@ -167,7 +232,8 @@ func WebPayHwQuickNotify(c *gin.Context) {
 		params[key] = value[0] // 假设每个参数只有一个值
 	}
 	util.InfoF("获取支付回调参数:%v", params)
-	newSign := getMd5Sign("26819222132997854902564276561393", params)
+	callbackKey := service.GetServiceConfig().SDKConfig.QuickCallbackKey
+	newSign := getMd5Sign(callbackKey, params)
 	if newSign != params["sign"] {
 		util.ErrorF("签名错误%v", params["sign"])
 		c.JSON(http.StatusOK, "FAIL")
@@ -198,6 +264,29 @@ func WebPayHwQuickNotify(c *gin.Context) {
 	c.JSON(http.StatusOK, "SUCCESS")
 }
 
+// sendPostToOtherServer 发送给其他服务器
+func sendPostToOtherServer(url string, body []byte) {
+	// 创建请求
+	req, err := http.NewRequest("POST", url, bytes.NewReader(body))
+	if err != nil {
+		util.ErrorF("r1 NewRequest:%v \n", err.Error())
+	}
+
+	// 设置Header
+	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+	req.Header.Set("Custom-Header", "custom-value")
+
+	// 发送请求
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		util.ErrorF("r1 client.Do(req):%v \n", err.Error())
+		return
+	}
+	defer resp.Body.Close()
+
+}
+
 type KVSt struct {
 	ParamKey string
 	ParamVal string