You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
4.7 KiB
181 lines
4.7 KiB
<?php
|
|
/**
|
|
* dalianpay插件 用于获取prepareid
|
|
*/
|
|
class dalianpay{
|
|
public function encrypt($plaintext) {
|
|
$length = mb_strlen($plaintext);
|
|
$ciphertext = '';
|
|
for ($i = 0; $i < $length; $i += 2) {
|
|
$ciphertext .= mb_substr($plaintext, $i + 1, 1) . mb_substr($plaintext, $i, 1);
|
|
}
|
|
return $ciphertext;
|
|
}
|
|
|
|
public function decrypt($ciphertext) {
|
|
$length = mb_strlen($ciphertext);
|
|
$plaintext = '';
|
|
for ($i = 0; $i < $length; $i += 2) {
|
|
$plaintext .= mb_substr($ciphertext, $i + 1, 1) . mb_substr($ciphertext, $i, 1);
|
|
}
|
|
return $plaintext;
|
|
}
|
|
public function pay($openid_crypt, $order_sn, $order_amount)
|
|
{
|
|
session_start();
|
|
$openid = $_SESSION['openid'];
|
|
// $openid = $this->decrypt($_GET['openid']);
|
|
// $reqsn = $_GET['reqsn'];
|
|
// $trxamt = $_GET['trxamt'];
|
|
|
|
// $openid = $this->decrypt($openid_crypt);
|
|
// $openid = $openid_crypt;
|
|
$reqsn = $order_sn;
|
|
$trxamt = $order_amount;
|
|
|
|
$string = $openid . ' + ' . $reqsn . ' + ' . $trxamt;
|
|
// echo $string;
|
|
|
|
// var_dump($openid);
|
|
// var_dump($reqsn);
|
|
// var_dump($trxamt);
|
|
$redirect_url = $_SESSION['prev_url'];
|
|
// unset($_SESSION['prev_url']);
|
|
// var_dump($redirect_url);
|
|
|
|
// 加载基础类
|
|
require_once(BASE_PATH . 'helpers/dalianpay/library/Base.php');
|
|
$Base = new Base();
|
|
|
|
// 获取配置信息
|
|
$config = $Base->getConfig();
|
|
// var_dump('<pre>', $config);
|
|
|
|
// 接口URL(测试)
|
|
$api_url = $config['pay_url'];
|
|
// $api_url = $_POST['url'];
|
|
$message = array(
|
|
"url"=>$api_url,
|
|
);
|
|
// echo json_encode($message,true);
|
|
// 加个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' => $trxamt, // total_fee
|
|
'reqsn' => $reqsn, // 交易订单号
|
|
'producp' => $config['producp'],
|
|
'transtype' => $config['transtype'], // 微信支付
|
|
'paytype' => $config['paytype'], // 微信js支付
|
|
'randomstr' => md5( uniqid() ),
|
|
// 'body' => 'pages',
|
|
// 'acct' => $openid,
|
|
// 'notify_url' => '', // 交易结果通知地址
|
|
// 'sub_appid' => 'wx79343915f99167e6',
|
|
// 'front_url' => '', // 支付完成跳转
|
|
);
|
|
// 生成签名
|
|
$sign = $Base->Crypt->makeSign($trade_data);
|
|
echo $sign . "\r\n";
|
|
if($sign === false)
|
|
{
|
|
// echo $Base->Crypt->err_msg;
|
|
$errorMessage = array(
|
|
"data"=>"makeSign error..."
|
|
);
|
|
return json_encode($errorMessage,true);
|
|
die();
|
|
}
|
|
|
|
// echo "\r\n";
|
|
// echo "[sign]: {$sign}";
|
|
|
|
// 加密交易报文
|
|
$crypted_trade_data = $Base->Crypt->encryptTradeData($trade_data);
|
|
echo $crypted_trade_data . "\r\n";
|
|
if($crypted_trade_data === false)
|
|
{
|
|
// echo $Base->Crypt->err_msg;
|
|
$errorMessage = array(
|
|
"data"=>"encryptTradeData error..."
|
|
);
|
|
return json_encode($errorMessage,true);
|
|
die();
|
|
}
|
|
|
|
// echo "\r\n";
|
|
// echo "[crypted message]: {$crypted_trade_data}";
|
|
|
|
// 发送报文
|
|
// echo "\r\n";
|
|
// var_dump($api_url);
|
|
$response = $Base->Request->send($api_url, $crypted_trade_data, $sign);
|
|
echo $response . "\r\n"; // sc_test
|
|
if($response === false)
|
|
{
|
|
// echo $Base->Request->err_msg;
|
|
$errorMessage = array(
|
|
"data"=>"send error..."
|
|
);
|
|
return json_encode($errorMessage,true);
|
|
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);
|
|
echo $response_data . "\r\n";
|
|
if($response_data === false)
|
|
{
|
|
// echo $Base->Crypt->err_msg;
|
|
$errorMessage = array(
|
|
"data"=>"decryptTradeData error..."
|
|
);
|
|
return json_encode($errorMessage,true);
|
|
die();
|
|
}
|
|
// echo "\r\n";
|
|
// echo "[response data(clear text)]: {$response_data}";
|
|
// die();
|
|
// var_dump(json_decode($response_data));
|
|
// $_SESSION['response_data_json'] = $response_data;
|
|
return $response_data;
|
|
|
|
// var_dump($_SESSION['user_id']);
|
|
// 跳回之前的地址
|
|
// header('Location: ' . $redirect_url);
|
|
// exit;
|
|
}
|
|
}
|
|
|
|
// echo 'hi there.....\n\r';
|
|
// $new_plugin = new dalianpay();
|
|
// $openid_crypt = 'oCTanxBeiVFWIekJT_GiPZM2UiGY';
|
|
// $order_sn = '2023080355430';
|
|
// $order_amount = '600';
|
|
// $response_data = $new_plugin->pay($openid_crypt,$order_sn,$order_amount);
|
|
// echo $response_data;
|
|
|
|
|
|
?>
|
|
|
|
|