|
|
|
@ -12,97 +12,97 @@ class wxpay |
|
|
|
*/ |
|
|
|
public function pay() |
|
|
|
{ |
|
|
|
// 统一支付接口Demo |
|
|
|
|
|
|
|
// 加载基础类 |
|
|
|
require_once('./library/Base.php'); |
|
|
|
$Base = new Base(); |
|
|
|
|
|
|
|
// 获取配置信息 |
|
|
|
$config = $Base->getConfig(); |
|
|
|
// var_dump('<pre>', $config); |
|
|
|
|
|
|
|
// 接口URL(测试) |
|
|
|
$api_url = $config['pay_url']; |
|
|
|
|
|
|
|
// 加个body字段传中文试试 |
|
|
|
|
|
|
|
// 组装交易报文 |
|
|
|
$reqsn_prefix = date('Ymd'); |
|
|
|
// var_dump("uniq_id(reqsn)"); |
|
|
|
// echo "\r\n"; |
|
|
|
// var_dump(uniqid($reqsn_prefix)); |
|
|
|
$trade_data = array( |
|
|
|
'orgid' => $config['org_num'], |
|
|
|
'cusid' => $config['cusid'], |
|
|
|
'branchno' => $config['branchno'], |
|
|
|
'termcode' => $config['termcode'], |
|
|
|
'version' => $config['version'], |
|
|
|
'trxamt' => '1', |
|
|
|
'reqsn' => uniqid($reqsn_prefix), |
|
|
|
'producp' => 'JX0002', |
|
|
|
'transtype' => 'JSP511', |
|
|
|
'paytype' => 'W01', |
|
|
|
'randomstr' => md5( uniqid() ), |
|
|
|
'body' => 'pages', |
|
|
|
"acct" => $this->parameters["openid"] # 不知道好不好用... |
|
|
|
); |
|
|
|
|
|
|
|
// 生成签名 |
|
|
|
$sign = $Base->Crypt->makeSign($trade_data); |
|
|
|
if($sign === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[sign]: {$sign}"; |
|
|
|
// die(); |
|
|
|
|
|
|
|
// 加密交易报文 |
|
|
|
$crypted_trade_data = $Base->Crypt->encryptTradeData($trade_data); |
|
|
|
if($crypted_trade_data === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[crypted message]: {$crypted_trade_data}"; |
|
|
|
// die(); |
|
|
|
|
|
|
|
// 发送报文 |
|
|
|
// echo "\r\n"; |
|
|
|
// var_dump($api_url); |
|
|
|
$response = $Base->Request->send($api_url, $crypted_trade_data, $sign); |
|
|
|
if($response === false) |
|
|
|
{ |
|
|
|
// echo $Base->Request->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
|
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response message]: {$response}"; |
|
|
|
|
|
|
|
// 解析响应报文 |
|
|
|
$response = json_decode($response, true); |
|
|
|
$response_data_crypted = $response['data']; |
|
|
|
$response_sign = $response['sign']; |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response sign]: {$response_sign}"; |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response data (ciphertext)]: {$response_data_crypted}"; |
|
|
|
|
|
|
|
// 解密响应密文 |
|
|
|
$response_data = $Base->Crypt->decryptTradeData($response_data_crypted); |
|
|
|
if($response_data === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response data(clear text)]: {$response_data}"; |
|
|
|
echo $response_data; |
|
|
|
// die(); |
|
|
|
// 统一支付接口Demo |
|
|
|
|
|
|
|
// 加载基础类 |
|
|
|
require_once('./library/Base.php'); |
|
|
|
$Base = new Base(); |
|
|
|
|
|
|
|
// 获取配置信息 |
|
|
|
$config = $Base->getConfig(); |
|
|
|
// var_dump('<pre>', $config); |
|
|
|
|
|
|
|
// 接口URL(测试) |
|
|
|
$api_url = $config['pay_url']; |
|
|
|
|
|
|
|
// 加个body字段传中文试试 |
|
|
|
|
|
|
|
// 组装交易报文 |
|
|
|
$reqsn_prefix = date('Ymd'); |
|
|
|
// var_dump("uniq_id(reqsn)"); |
|
|
|
// echo "\r\n"; |
|
|
|
// var_dump(uniqid($reqsn_prefix)); |
|
|
|
$trade_data = array( |
|
|
|
'orgid' => $config['org_num'], |
|
|
|
'cusid' => $config['cusid'], |
|
|
|
'branchno' => $config['branchno'], |
|
|
|
'termcode' => $config['termcode'], |
|
|
|
'version' => $config['version'], |
|
|
|
'trxamt' => '1', |
|
|
|
'reqsn' => uniqid($reqsn_prefix), |
|
|
|
'producp' => 'JX0002', |
|
|
|
'transtype' => 'JSP511', |
|
|
|
'paytype' => 'W01', |
|
|
|
'randomstr' => md5( uniqid() ), |
|
|
|
'body' => 'pages', |
|
|
|
"acct" => $this->parameters["openid"] # 不知道好不好用... |
|
|
|
); |
|
|
|
|
|
|
|
// 生成签名 |
|
|
|
$sign = $Base->Crypt->makeSign($trade_data); |
|
|
|
if($sign === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[sign]: {$sign}"; |
|
|
|
// die(); |
|
|
|
|
|
|
|
// 加密交易报文 |
|
|
|
$crypted_trade_data = $Base->Crypt->encryptTradeData($trade_data); |
|
|
|
if($crypted_trade_data === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[crypted message]: {$crypted_trade_data}"; |
|
|
|
// die(); |
|
|
|
|
|
|
|
// 发送报文 |
|
|
|
// echo "\r\n"; |
|
|
|
// var_dump($api_url); |
|
|
|
$response = $Base->Request->send($api_url, $crypted_trade_data, $sign); |
|
|
|
if($response === false) |
|
|
|
{ |
|
|
|
// echo $Base->Request->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
|
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response message]: {$response}"; |
|
|
|
|
|
|
|
// 解析响应报文 |
|
|
|
$response = json_decode($response, true); |
|
|
|
$response_data_crypted = $response['data']; |
|
|
|
$response_sign = $response['sign']; |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response sign]: {$response_sign}"; |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response data (ciphertext)]: {$response_data_crypted}"; |
|
|
|
|
|
|
|
// 解密响应密文 |
|
|
|
$response_data = $Base->Crypt->decryptTradeData($response_data_crypted); |
|
|
|
if($response_data === false) |
|
|
|
{ |
|
|
|
// echo $Base->Crypt->err_msg; |
|
|
|
die(); |
|
|
|
} |
|
|
|
// echo "\r\n"; |
|
|
|
// echo "[response data(clear text)]: {$response_data}"; |
|
|
|
echo $response_data; |
|
|
|
// die(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|