123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- // 金立创建订单接口
- //
- include_once __DIR__ . '/../../../main.php'; # 导入game utils
- include_once __DIR__ . '/../Mo/payResp.php'; # 导入通用返回值结构
- include_once __DIR__ . '/../Mo/payRequest.php'; # 导入通用订单请求结构
- require_once __DIR__ . '/config_for_gionee.php'; # 配置文件
- use loyalsoft\CLog;
- use loyalsoft\JsonUtil;
- use loyalsoft\HttpUtil;
- $str = HttpUtil::getQueryString(); # 取参数
- // $str = gzinflate($str);
- $data = JsonUtil::decode($str);
- $req = new PayRequest($data); # 解析参数并创建订单
- $cfg = config_for_gionee::Inst();
- $req->notifyUrl .= "?ext_info=" . $req->callbackInfo;
- //生成内部订单,创建金立订单
- if ($req->InserDataBase()) { # 订单数据入库
- $post_arr = array('user_id' => $data->JinliUserId, // # 客户端登录返回的信息中包含user_id,
- 'out_order_no' => $req->cpOrderId, // # 商户订单号,
- 'subject' => $req->product_name, // # 请填写你的支付标题
- 'submit_time' => date('YmdHis'), // # 提交时间
- 'total_fee' => $req->amount, // # 需要支付的金额
- 'api_key' => $cfg->appkey, // # 商户自己的api_key
- 'deal_price' => $req->amount, // # 需要支付的金额
- 'deliver_type' => '1', // # 网游类型接入时固定值
- 'notify_url' => $req->notifyUrl, // # 请填写充值后的回调URL
- 'player_id' => 'amigo_player001', // # 请填写amigo玩家id
- 'ext_info' => $req->callbackInfo); // # 透传参数
- $post_arr['sign'] = $cfg->pay_sign($post_arr); # 计算签名
- $ret = HttpUtil::makeRequest($cfg->ApiURL_pay_createOrder, JsonUtil::encode($post_arr)); # 发送API请求,参数要求为json
- if ($ret['result']) { # 请求结果
- $return_json = JsonUtil::decode($ret['msg']);
- if (isset($return_json->status) && $return_json->status == '200010000') { # 成功
- /*
- * 记录下你得到的$post_arr['out_order_no']和$return_arr['order_no']的对应关系,充值回调的时候要使用的
- */
- $arr = $req->retData();
- $arr['orderInfo'] = $ret['msg'];
- CLog::pay('[金立.pay]创建订单' . $req . " 参数: " . JsonUtil::encode($arr));
- die(payResp::ok($arr)); # 返回值
- }
- } # 创建失败处理
- CLog::pay('[金立.pay]创建订单接口调用失败' . $ret['msg']);
- die(payResp::err(1, '创建订单失败'));
- } else { # 入库失败
- CLog::pay('[金立.pay]订单插入数据库失败' . $req);
- die(payResp::err(1, '创建订单失败')); # 返回值
- }
|