<?php

/**
 * 小七手游 创建订单接口  
 * @version
 *          1.0.0 Created at 2018-5-5. by --gwang
 * @author gwang (mail@wanggangzero.cn)
 * @copyright ?  2018-5-5, SJZ LoyalSoft Corporation & gwang. All rights reserved.
 */
include_once __DIR__ . '/../../../main.php';             # 导入game utils
include_once __DIR__ . '/../Mo/resp.php';                # 导入通用返回值结构
include_once __DIR__ . '/../Mo/payRequest.php';          # 导入通用订单请求结构
require_once __DIR__ . '/config_x7sy.php';               # 渠道参数
include_once __DIR__ . "/common.php";

use loyalsoft\CLog;
use loyalsoft\JsonUtil;
use loyalsoft\HttpUtil;

$str = HttpUtil::getQueryString();                       # 取参数
//    $str = gzinflate($str);                
$data = JsonUtil::decode($str);
$req = new PayRequest($data);                            # 解析参数并创建订单
if ($req->InserDataBase()) {                             # 订单数据入库
    $cfg = config_x7sy::Inst();
    CLog::pay('[小七手游.pay]创建订单' . $req);
    $ret = $req->x7sy_retData();
    $qs = http_build_query_noencode($ret);               # 订单数据结构
    CLog::pay('[小七手游.pay]待签名串:' . $qs);
    $sign = md5($qs . $cfg->RSA_pub);                    # 签名
    CLog::pay('[小七手游.pay]签名:' . $sign);
    $ret['game_sign'] = $sign;
    echo Resp::ok($ret);                                 # 返回值
} else {
    CLog::pay('[小七手游.pay]创建订单失败' . $req);
    echo Resp::err(1, '创建订单失败');                    # 返回值
}