hxp
2025-06-09 6c3f6335c70859ded94a1ad8d218acb0ac34239c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
 
#创建日期:2012-4-17 下午3:18:45
#作者:zhouliang
 
include_once '/Common/MongoCommon.php';
include_once '/Common/ConfigReader.php';
include_once '/Common/CommFunc.php';
include_once '/Common/logging.php';
include_once '/ProjComm/CommonOperate.php';
include_once "/ProjComm/CfgReader.php";
 
 
function SendGameQueryCoin($qid, $orderAmount, $orderInfo, $orderID, $appID)
{
 
    \CfgReader\GetConfigData("Config", "GMKey", $key);
 
    $tool_page = "http://127.0.0.1/Server/Tool.php";
    if(\CfgReader\GetConfigData("ServerInfo", "GameServerWebPort_".$appID, $GameServerWebPort))
    {
        $tool_page = "http://127.0.0.1:".$GameServerWebPort."/Server/Tool.php";
    }
    $pack_data = array("queryType"=>"accID");
    $pack_data["playerFind"] = $qid;
    $pack_data["pack_type"] = "GMT_GetCoinReq";
    $pack_data["key"] = $key;
    $pack_data['coding'] = "gbk";
 
    //使用key加密
    $pack_data_dict = json_encode($pack_data);
    $sign = md5($pack_data_dict.$key);
    $post = array();
    $post['pack'] = $pack_data_dict;
    $post['sign'] = $sign;
 
    \Logging\LogInfo("post to page".$tool_page);
    \Logging\LogInfo("Send : ".print_r($post, true));
    \CommFunc\DoPost($tool_page, $post);
 
}
 
 
 
function Process_DataArray($DataArray, $DoName)
{
    \Logging\LogInfo("type: ".$DoName." recv: ".print_r($DataArray, true));
    
    # 返回充值结果
    $returnArr = array();
    $returnArr["errorcode"] = 0;
    $returnArr["errordesc"] = "fail";
 
    
    if (!array_key_exists("AccountID", $DataArray) ||
        !array_key_exists("RegionName", $DataArray) ||
        !array_key_exists("OrderAmount", $DataArray) ||
        !array_key_exists("BillNO", $DataArray) ||
        !array_key_exists("OrderInfo", $DataArray) ||
        !array_key_exists("OperatorID", $DataArray) ||
        !array_key_exists("Sign", $DataArray))
    {
        # \Logging\LogError("Param Err!".print_r($DataArray, true));
        $returnArr["errordesc"] = "param error.";
        echo json_encode($returnArr);
        return ;
    }
 
    $getServer_id = $DataArray["RegionName"];
 
    //读取配置文件
    if (!\CfgReader\ReadConfig())
    {
        \Logging\LogError("读取配置文件失败, 错误原因:".\CfgReader\GetConfigErrInfo());
        $returnArr["errordesc"] = "Server init error.";
        echo json_encode($returnArr);
        exit();
    }
    
    $opqid = $DataArray['AccountID'];
    $orderID = $DataArray["BillNO"];
    $orderAmount = $DataArray['OrderAmount'];
    $operatorID = $DataArray['OperatorID'];
    
    $changeAppID = '';  //新增一种平台标志,用于区分账号,如IOS和安卓是否混服同角色号处理
    if(!\CfgReader\GetConfigData("ServerInfo", "appid_".$operatorID, $changeAppID))
    {
        $changeAppID = $operatorID;     //未配置的取原appid
    }
    
    $qid = \CommonOperate\GetGameQid( $opqid, $getServer_id, $changeAppID);
    $recvSign = $DataArray['Sign'];
    
    \Logging\LogAddObj( \Logging\strServerDir, $getServer_id, ' SID:'.$getServer_id );
    \Logging\LogAddObj( \Logging\strUIDDir, $qid , ' QID:'.$qid  );
    
    \Logging\LogInfo( 'server_id:'.$getServer_id.' QID:'.$qid );
    
    if (!is_numeric($orderAmount)){
        \Logging\LogError("发现参数order_amount数据异常 = ".$orderAmount);
        $returnArr["errordesc"] = "OrderAmount error.";
        echo json_encode($returnArr);
        exit;
    }
    
    $strKey='';
    $isDecryptKey='';
    if( !\CfgReader\GetConfigData("ExChange", "Key_".$operatorID, $strKey) ||
        !\CfgReader\GetConfigData("Config", "IsDecryptKey", $isDecryptKey))
    {
        $returnArr["errordesc"] = "Server init error.";
        echo json_encode($returnArr);
        return;    
    }
    
    //如果配置了需要解密,对登录key进行解密
    if ($isDecryptKey == 1)
    {
        \Logging\LogInfo("需要对登录key进行解密,解密前key值:".$strKey);
        $strKey = \CommFunc\GetDecodePsw($strKey);
    }
    
    \Logging\LogInfo("密钥key:".$strKey);
    
    
    #判断sign是否相等
    $sign=md5( $opqid.$orderAmount.$orderID.$getServer_id.$strKey );
    if( $sign!=$recvSign )    # $_GET['sign'] 一定得是字符串才可以通过此判断 所以不需要转换
    {
        \Logging\LogInfo( '自己算出的签名是:'.$sign );
        \Logging\LogInfo( '对方的签名是:'.$recvSign );
        \Logging\LogWarn( '签名校验错误' );
        $returnArr["errordesc"] = "Sign error.";
        echo json_encode($returnArr);
        return;
    }
    
    \Logging\LogInfo( '签名校验成功' );
    
    $scaleNum = 1;
    if(!\CfgReader\GetConfigData("ExChange", "ExChangeScale_".$operatorID, $scaleNum))
    {
        if(!\CfgReader\GetConfigData("ExChange", "ExChangeScale", $scaleNum))
        {
            \Logging\LogError( '读取充值转化比例出错' );
            exit;
        }
    }
    
    //支持两位小数
    $nOrderAmount = intval(round(floatval($orderAmount) * $scaleNum));
    
    $noOrderAmount = 0;
    \CfgReader\GetConfigData("ExChange", "NoOrderAmount", $noOrderAmount);
    if( $nOrderAmount<1 && $noOrderAmount != 1)
    {
        $returnArr["errordesc"] = "OrderAmount error.";
        echo json_encode($returnArr);
        return ;
    }
    
    \Logging\LogInfo( "传来的order_amount=".$orderAmount." 转换后:".$nOrderAmount );
    
    
    #先连接数据库
    if( !\CommonOperate\GetMongoDB( dirname(__FILE__).'\\..\\..\\InterfaceConfig.php',
            'db', $mongoOpt ) )
    {
        $returnArr["errordesc"] = "db init error.";
        echo json_encode($returnArr);
        return;
    }
    
    #查询数据库是否有数据,如果有返回重复
    
    $arrayCheck=array('ServerID'=>$getServer_id, 'AccID'=>$qid,
                        'OrderID'=>$orderID);
    
    if( $mongoOpt->IsDataExist( 'tagPayInfo', $arrayCheck ) )
    {
        \Logging\LogInfo( '数据:'.var_export( $arrayCheck, true ).'已经存在,返回重复' );
        $returnArr["errorcode"] = 2;
        $returnArr["errordesc"] = "Repeat Commit";
        echo json_encode($returnArr);
        return;
    }
 
    $Extras = array_key_exists("Extras", $DataArray) ? $DataArray["Extras"] : "";
 
    // EndOrderTime 兑换游戏币成功后设置, IsProcess为0代表还没兑换
    $arrayInsert=array( '_id'=>$orderID, 'ServerID'=>$getServer_id, 
                        'AccID'=>$qid, 'OrderAmount'=>$nOrderAmount, 
                        'OrderID'=>$orderID, 'Sign'=>$recvSign, 
                        'BeginOrderTime'=>date("Y-m-d H:i:s"), 'EndOrderTime'=>0, 
                        'IsProcess'=>0, "OrderInfo"=>$DataArray['OrderInfo'], "Extras"=>$Extras);
    
    $arrayIndex=array( 'ServerID'=>1, 'AccID'=>1 );
    
    $mongoOpt->insert( 'tagPayInfo', $arrayInsert, $arrayIndex );
    
    if( $mongoOpt->IsDataExist( 'tagPayInfo', $arrayCheck ) )
    {
        \Logging\LogInfo( '成功插入充值数据:'.var_export( $arrayInsert, true ) );
        $returnArr["errorcode"] = 1;
        $returnArr["errordesc"] = "Success";
        echo json_encode($returnArr);
        // 通知游戏有充值,需立即查询到账
        // SendGameQueryCoin($qid, $nOrderAmount, $DataArray['OrderInfo'], $orderID, $changeAppID);
        return;
    }
    
    else
    {
        \Logging\LogError( '插入充值数据:'.var_export( $arrayInsert, true ).'失败' );
        echo json_encode($returnArr);
        return;
    }
}
 
 
 
function Process()
{
    \Logging\CreateLogging( "exchange" );
    \Logging\LogDebug("start...");
    \CommFunc\GLOBAL_RECV("Process_DataArray");
    \Logging\LogDebug("over...");
}
 
Process();
 
?>