转发流程已经ok
This commit is contained in:
parent
88d63f2918
commit
de4d07ecd6
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"game/base/log"
|
||||
"game/base/redis"
|
||||
"game/config"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Server 服务器
|
||||
@ -46,6 +48,7 @@ func (srv *PayServer) Run() {
|
||||
http.HandleFunc("/huaweiPreOrder", HuaweiPreOrder)
|
||||
http.HandleFunc("/checkRegisterReward", srv.CheckRegisterReward)
|
||||
http.HandleFunc("/RegisterReward", srv.RegisterReward)
|
||||
http.HandleFunc("/testGameProxy", srv.TestGameProxy)
|
||||
|
||||
server := http.Server{Addr: srv.addr, Handler: http.DefaultServeMux}
|
||||
go func() {
|
||||
@ -119,7 +122,72 @@ type ServerInfo struct {
|
||||
WorldName string `json:"worldName"`
|
||||
}
|
||||
|
||||
func (srv *PayServer) forwardKsGame(sid int, urlPath string, msg interface{}, name string) (respData []byte, e error) {
|
||||
var data []byte
|
||||
data, e = json.Marshal(msg)
|
||||
if e != nil {
|
||||
log.Debug("SendMsgToGameProxy e:", e)
|
||||
return
|
||||
}
|
||||
|
||||
var domain_name = "game1009proxy.kingsome.cn"
|
||||
if config.CmConfig.IsProxyDebug {
|
||||
domain_name = "game1009proxy-test.kingsome.cn"
|
||||
}
|
||||
|
||||
sUrl := fmt.Sprintf("https://%s/webapp/index.php?c=GameProxy&a=forwardMsg&sid=%d&urlPath=%s&msg=%s&name=%s",
|
||||
domain_name,
|
||||
sid,
|
||||
urlPath,
|
||||
url.QueryEscape(string(data)),
|
||||
url.QueryEscape(string(name)))
|
||||
ss, _ := url.QueryUnescape(sUrl)
|
||||
log.Info("SendMsgToGameProxy Url ", ss)
|
||||
|
||||
var resp *http.Response
|
||||
resp, e = http.Get(sUrl)
|
||||
if e != nil {
|
||||
log.Error("SendMsgToGameProxy Get fail err:", e)
|
||||
return
|
||||
}
|
||||
|
||||
respData, e = ioutil.ReadAll(resp.Body)
|
||||
if e != nil {
|
||||
log.Error("SendMsgToGameProxy ReadAll fail err:", e)
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
return respData, nil;
|
||||
}
|
||||
|
||||
func (srv *PayServer) TestGameProxy(w http.ResponseWriter, r *http.Request) {
|
||||
var msg = make(map[string]string)
|
||||
var e error
|
||||
if e = json.Unmarshal([]byte(r.FormValue("msg")), &msg); e != nil {
|
||||
log.Error("SendMsgToGame Unmarshal fail err:", e)
|
||||
return
|
||||
}
|
||||
var sid, _ = strconv.Atoi(r.FormValue("sid"));
|
||||
var urlPath = "selfChecking"
|
||||
if config.CmConfig.IsProxyDebug {
|
||||
urlPath = r.FormValue("urlPath")
|
||||
}
|
||||
var name = r.FormValue("name")
|
||||
|
||||
var respData, _ = srv.forwardKsGame(
|
||||
sid,
|
||||
urlPath,
|
||||
msg,
|
||||
name)
|
||||
log.Info("response", string(respData))
|
||||
w.Write(respData)
|
||||
}
|
||||
|
||||
func (srv *PayServer) SendMsgToGame(sid int, urlPath string, msg interface{}, name string) (respData []byte, e error) {
|
||||
if sid >= 100 {
|
||||
return srv.forwardKsGame(sid, urlPath, msg, name)
|
||||
}
|
||||
info := redis.HGet("game_info", sid)
|
||||
if info == "" {
|
||||
log.Debug("SendMsgToGame info=nil")
|
||||
|
@ -12,6 +12,7 @@ type CommonConfig struct {
|
||||
Debug bool `yaml:"debug"` // 是否测试环境
|
||||
IsHGameDebug bool `yaml:"isHGameDebug"` // 测试的充值渠道
|
||||
IsHuaweiPayDebug bool `yaml:"isHuaweiPayDebug"` // 测试华为的充值渠道
|
||||
IsProxyDebug bool `yaml:"isProxyDebug"` // 测试代理服务器
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user