unified_channel = $this->channel; $this->conf_appid = ''; $this->conf_mch_id = ''; $this->conf_pay_secret_key = ''; } private function loadConfig() { $config_name = "../config/game{$this->gameid}/{$this->channel}/config.php"; $this->config = require($config_name); $this->conf_appid = $this->config['appid']; $tmp_str = explode('|', $this->config['pay_secret_key']); $this->conf_mch_id = $tmp_str[0]; $this->conf_pay_secret_key = $tmp_str[1]; } public function preOrder() { $this->gameid = phpcommon\extractGameId($_REQUEST['account_id']); $this->real_channel = phpcommon\extractChannelId($_REQUEST['account_id']); $this->loadConfig(); $cp_orderid = $this->order_ctrl->genOrderId(); { $this->order_ctrl->addPreOrder( array( 'orderid' => $cp_orderid, 'account_id' => $_REQUEST['account_id'], 'roleid' => '', 'server_id' => 0, 'poly_sdk_channel' => $this->poly_sdk_channel, 'unified_channel' => $this->unified_channel, 'itemid' => $itemid, 'ipv4' => phpcommon\getIPv4(), ) ); } $params = array( 'appid' => $this->conf_appid, 'mch_id' => $this->conf_mch_id, 'nonce_str' => md5($cp_orderid . time()), 'body' => '测试产品', 'out_trade_no' => $cp_orderid, 'total_fee' => '101', 'spbill_create_ip' => phpcommon\getIPv4(), 'notify_url' => 'https://gamepay.kingsome.cn/webapp/paynotify/unified_weixin.php', 'trade_type' => 'MWEB', //'scene_info' => '', ); if (SERVER_ENV != _ONLINE) { $params['notify_url'] = 'https://gamepay-test.kingsome.cn/webapp/paynotify/unified_weixin.php'; } $sign = phpcommon\wxPaySign($params, $this->conf_pay_secret_key ); $params['sign'] = strtoupper($sign); error_log(json_encode($params)); error_log(phpcommon\objectToXml($params)); $response = ''; if (phpcommon\HttpClient::postContent( 'https://api.mch.weixin.qq.com/pay/unifiedorder', phpcommon\objectToXml($params), $response )) { phpcommon\sendError(1, '服务器内部错误'); return; } echo $response; $xml = new \SimpleXMLElement($response); if ($xml->return_code != 'SUCCESS') { phpcommon\sendError(2, $xml->return_msg); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'cp_orderid' => $cp_orderid, 'prepayid' => $xml->prepay_id )); } public function payNotify() { } }