|
|
@@ -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
|