pay/webapp/sdkwarpper/UnifiedWeiXin.php
aozhiwei 6cb9a7ec6d 1
2020-10-19 16:48:19 +08:00

69 lines
2.0 KiB
PHP

<?php
namespace sdkwarpper;
require 'BaseSdk.php';
use phpcommon;
use classes;
class UnifiedWeiXin extends BaseSdk {
function __construct()
{
parent::__construct();
$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\extractGameId($_REQUEST['account_id']);
$this->loadConfig();
$params = array(
'appid' => $this->conf_appid,
'mch_id' => $this->conf_mch_id,
'nonce_str' => uniqid('201019'),
'body' => '测试产品',
'out_trade_no' => uniqid('201019'),
'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
)) {
}
echo $response;
}
}