|
|
|
|
<?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();
|
|
|
|
|
// 传回org_num 供wxpay.php中使用
|
|
|
|
|
$_SESSION['org_num'] = $config['org_num'];
|
|
|
|
|
// 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));
|
|
|
|
|
|
|
|
|
|
// echo "reqsn is " . $reqsn . "\n\r";
|
|
|
|
|
// echo "uniqid reqsn is " . uniqid($reqsn_prefix) . "\n\r";
|
|
|
|
|
// echo "trxamt is " . $trxamt . "\n\r";
|
|
|
|
|
// $trade_data = array(
|
|
|
|
|
// 'orgid' => $config['org_num'],
|
|
|
|
|
// // 'orgid' => '5503001',
|
|
|
|
|
// 'cusid' => $config['cusid'],
|
|
|
|
|
// // 'cusid' => '10147',
|
|
|
|
|
// 'branchno' => $config['branchno'],
|
|
|
|
|
// // 'branchno' => '44',
|
|
|
|
|
// 'version' => $config['version'],
|
|
|
|
|
// // 'version' => '11',
|
|
|
|
|
// // jsapi支付不需要termcode
|
|
|
|
|
// 'termcode' => $config['termcode'],
|
|
|
|
|
// 'trxamt' => strval($trxamt), // total_fee bug: need:string supply:int
|
|
|
|
|
// // 'trxamt' => '180000', // total_fee
|
|
|
|
|
// 'reqsn' => $reqsn, // 交易订单号
|
|
|
|
|
// // 'reqsn' => uniqid($reqsn_prefix), // 交易订单号
|
|
|
|
|
// 'producp' => $config['producp'],
|
|
|
|
|
// 'transtype' => $config['transtype'], // 微信支付
|
|
|
|
|
// 'paytype' => $config['paytype'], // 微信js支付
|
|
|
|
|
// 'randomstr' => md5( uniqid() ),
|
|
|
|
|
// 'body' => 'pages',
|
|
|
|
|
// // 'acct' => $openid,
|
|
|
|
|
// 'notify_url' => $config['notify_url'], // 交易结果通知地址
|
|
|
|
|
// // 'limit_pay' => $config['limit_pay'],
|
|
|
|
|
// // 'sub_appid' => $config['sub_appid'],
|
|
|
|
|
// // 'front_url' => $config['front_url'], // 支付完成跳转
|
|
|
|
|
// );
|
|
|
|
|
// echo "\r\n test \r\n";
|
|
|
|
|
|
|
|
|
|
echo "please\r\n";
|
|
|
|
|
$trade_data = array(
|
|
|
|
|
'body'=>'订单标题',
|
|
|
|
|
'branchno'=>'401',
|
|
|
|
|
'cusid'=>'100018380507D2C',
|
|
|
|
|
// 'notify_url'=>'https://shop.heavenk.com/mobile/wxnotify.php',
|
|
|
|
|
'orgid'=>'100018380507D2C',
|
|
|
|
|
'paytype'=>'A01',
|
|
|
|
|
'producp'=>'JX0002',
|
|
|
|
|
'randomstr'=>'a14cf3397a8163a76a2f229c41085a61',
|
|
|
|
|
'reqsn'=>'2023081664dc2b9454389',
|
|
|
|
|
'termcode'=>'000000',
|
|
|
|
|
'transtype'=>'JSP511',
|
|
|
|
|
'trxamt'=>'1',
|
|
|
|
|
'version'=>'11',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 生成签名
|
|
|
|
|
$sign = $Base->Crypt->makeSign($trade_data);
|
|
|
|
|
echo "sign:\r\n";
|
|
|
|
|
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 "send result\r\n";
|
|
|
|
|
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 "decryptTradeData:\r\n";
|
|
|
|
|
// 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 json_decode($response_data,true);
|
|
|
|
|
|
|
|
|
|
// 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 = '2023080355431';
|
|
|
|
|
// $order_amount = '600';
|
|
|
|
|
// $response_data = $new_plugin->pay($openid_crypt,$order_sn,$order_amount);
|
|
|
|
|
// echo $response_data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|