first commit

This commit is contained in:
2025-11-28 10:08:12 +08:00
commit 09a14bf0a3
1088 changed files with 145132 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEMTCCAxmgAwIBAgIGAXUrc4b4MA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYT
AkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAwDgYDVQQHDAdCZWlKaW5nMRcwFQYDVQQK
DA5MYWthbGEgQ28uLEx0ZDEqMCgGA1UEAwwhTGFrYWxhIE9yZ2FuaXphdGlvbiBW
YWxpZGF0aW9uIENBMB4XDTIwMTAxNTA4NDk1MloXDTMwMTAxMzA4NDk1MlowZTEL
MAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcx
FzAVBgNVBAoMDkxha2FsYSBDby4sTHRkMRkwFwYDVQQDDBBBUElHVy5MQUtBTEEu
Q09NMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwAXZw9lupWcFXouC
Nhm0DQT47Zf4KOIRF8rqT8Ps3pYzT8odROJ8rq4P+lciGrg29czpqrRM22yQktFr
itvcM7JlE6jFbGH3rycnvGvhRYU/j1N9k0ozm8oVwmKX357/OtGzNivBECGSnU9L
Bkp4Nm9M1K4cOwEuZ0xsQEthZjQYF0mDpnlWmVJL5i1Lq834atN2qrb/mzMHBNtD
JnqRV7rPL39lKpe7LJiitsC2JuW1UbWZZU1NNwA/rz2d83C+KD1DLJ0+sMYY2Q3T
OQ4BPAowDEwOH7XAXrHM/0kRm+ZeIFlwevEGIQWmMt1Ogz+AW4Iq0slINc4wOINK
vH9tHwIDAQABo4HVMIHSMIGSBgNVHSMEgYowgYeAFCnH4DkZPR6CZxRn/kIqVsMo
dJHpoWekZTBjMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHQmVpSmluZzEQMA4GA1UE
BwwHQmVpSmluZzEXMBUGA1UECgwOTGFrYWxhIENvLixMdGQxFzAVBgNVBAMMDkxh
a2FsYSBSb290IENBggYBaiUALIowHQYDVR0OBBYEFIya0Yc4OSBer55JLyA0AYe9
m8mTMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUA
A4IBAQCBEwOlk3mXigNv94Drn3dcaY2ml/y+8yNpAIuUhuBE00WFoqEX5lOatFy5
fzdXuC12lBVQ8SjSm3aH7k2X0eXqDzkOHiur2ZBRKmJ++J4TeenuSUOjSIbQK/DT
vxaqFUjYwFSVCyizpy7wfU4wKt+jOuFb9LyULJ9lkM1dV9Kh7Lmd9+nlJYYuPEPU
LJkkVZqSALSiiJudXnTwlISjZTXEAkJpdIlMw+hvPTAkoG95B95M+OV/uLbItGK+
qT4+RHWo8EbBDPQYo6J4QYHOxRlfMoGBMyrz6XDt7ELLmT7ld4aE02w6KQPfK3gq
kLDT+/STozvaNmXzBJh7J6KqxJBH
-----END CERTIFICATE-----
+25
View File
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEMTCCAxmgAwIBAgIGAXRTgcMnMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYT
AkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAwDgYDVQQHDAdCZWlKaW5nMRcwFQYDVQQK
DA5MYWthbGEgQ28uLEx0ZDEqMCgGA1UEAwwhTGFrYWxhIE9yZ2FuaXphdGlvbiBW
YWxpZGF0aW9uIENBMB4XDTIwMTAxMDA1MjQxNFoXDTMwMTAwODA1MjQxNFowZTEL
MAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcx
FzAVBgNVBAoMDkxha2FsYSBDby4sTHRkMRkwFwYDVQQDDBBBUElHVy5MQUtBTEEu
Q09NMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1zHL54HiI8d2sLJ
lwoQji3/ln0nsvfZ/XVpOjuB+1YR6/0LdxEDMC/hxI6iH2Rm5MjwWz3dmN/6BZeI
gwGeTOWJUZFARo8UduKrlhC6gWMRpAiiGC8wA8stikc5gYB+UeFVZi/aJ0WN0cpP
JYCvPBhxhMvhVDnd4hNohnR1L7k0ypuWg0YwGjC25FaNAEFBYP9EYUyCJjE//9Z7
sMzHR9SJYCqqo6r9bOH9G6sWKuEp+osuAh+kJIxJMHfipw7w3tEcWG0hce9u/el4
cYJtg8/PPMVoccKmeCzMvarr7jdKP4lenJbtwlgyfs+JgNu60KMUJH8RS72wC9NY
uFz09wIDAQABo4HVMIHSMIGSBgNVHSMEgYowgYeAFCnH4DkZPR6CZxRn/kIqVsMo
dJHpoWekZTBjMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHQmVpSmluZzEQMA4GA1UE
BwwHQmVpSmluZzEXMBUGA1UECgwOTGFrYWxhIENvLixMdGQxFzAVBgNVBAMMDkxh
a2FsYSBSb290IENBggYBaiUALIowHQYDVR0OBBYEFJ2Kx9YZfmWpkKFnC33C0r5D
K3rFMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUA
A4IBAQBZoeU0XyH9O0LGF9R+JyGwfU/O5amoB97VeM+5n9v2z8OCiIJ8eXVGKN9L
tl9QkpTEanYwK30KkpHcJP1xfVkhPi/cCMgfTWQ5eKYC7Zm16zk7n4CP6IIgZIqm
TVGsIGKk8RzWseyWPB3lfqMDR52V1tdA1S8lJ7a2Xnpt5M2jkDXoArl3SVSwCb4D
AmThYhak48M++fUJNYII9JBGRdRGbfJ2GSFdPXgesUL2CwlReQwbW4GZkYGOg9LK
CNPK6XShlNdvgPv0CCR08KCYRwC3HZ0y1F0NjaKzYdGNPrvOq9lA495ONZCvzYDo
gmsu/kd6eqxTs/JwdaIYr4sCMg8Z
-----END CERTIFICATE-----
+192
View File
@@ -0,0 +1,192 @@
<?php
class LakalaClient
{
//appid
protected $appid;
//平台证书文件
private $platform_cert_file;
//商户证书文件
private $merchant_cert_file;
//商户私钥文件
private $merchant_private_file;
protected $gateway_url = 'https://s2.lakala.com';
private $version = '3.0';
private $schema = 'LKLAPI-SHA256withRSA';
public $request_body;
public $response_body;
public function __construct($appid, $isTest = false){
$this->appid = $appid;
$this->platform_cert_file = PLUGIN_ROOT.'lakala/cert/lkl-apigw-v1.cer';
$this->merchant_cert_file = PLUGIN_ROOT.'lakala/cert/api_cert.cer';
$this->merchant_private_file = PLUGIN_ROOT.'lakala/cert/api_private_key.pem';
if(file_exists(PLUGIN_ROOT.'lakala/cert/'.$appid.'.cer') && file_exists(PLUGIN_ROOT.'lakala/cert/'.$appid.'.pem')){
$this->merchant_cert_file = PLUGIN_ROOT.'lakala/cert/'.$appid.'.cer';
$this->merchant_private_file = PLUGIN_ROOT.'lakala/cert/'.$appid.'.pem';
}
if($isTest){
$this->gateway_url = 'https://test.wsmsd.cn/sit';
$this->platform_cert_file = PLUGIN_ROOT.'lakala/cert/lkl-apigw-v2.cer';
}
}
//发起请求
public function execute($path, $params)
{
$requrl = $this->gateway_url . $path;
$public_params = [
'req_time' => date('YmdHis'),
'version' => $this->version,
'req_data' => $params
];
$body = json_encode($public_params, JSON_UNESCAPED_UNICODE);
$authorization = $this->getAuthorization($body);
$this->request_body = $body;
$resp = $this->curl($requrl, $body, $authorization);
$this->response_body = $resp;
$result = json_decode($resp, true);
if(isset($result['code']) && $result['code'] == 'BBS00000'){
return $result['resp_data'];
}elseif($result['msg']){
throw new Exception('['.$result['code'].']'.$result['msg']);
}else{
throw new Exception('返回数据解析失败');
}
}
//收银台发起请求
public function cashier($path, $params)
{
$requrl = $this->gateway_url . $path;
$public_params = [
'req_time' => date('YmdHis'),
'version' => '1.0',
'req_data' => $params
];
$body = json_encode($public_params, JSON_UNESCAPED_UNICODE);
$authorization = $this->getAuthorization($body);
$this->request_body = $body;
$resp = $this->curl($requrl, $body, $authorization);
$this->response_body = $resp;
$result = json_decode($resp, true);
if(isset($result['code']) && $result['code'] == '000000'){
return $result['resp_data'];
}elseif($result['msg']){
throw new Exception('['.$result['code'].']'.$result['msg']);
}else{
throw new Exception('返回数据解析失败');
}
}
//签名
public function getAuthorization($body) {
$mchSerialNo = $this->getMchSerialNo();
$nonceStr = random(12);
$timestamp = time();
$message = $this->appid . "\n" . $mchSerialNo . "\n" . $timestamp . "\n" . $nonceStr . "\n" . $body . "\n";
$signature = $this->rsaPrivateSign($message);
return $this->schema . " appid=\"" . $this->appid . "\"," . "serial_no=\"" . $mchSerialNo . "\"," . "timestamp=\"" . $timestamp . "\"," . "nonce_str=\"" . $nonceStr . "\"," . "signature=\"" . $signature . "\"";
}
//验签
public function verifySign($authorization, $body) {
$authorization = str_replace($this->schema . " ", "", $authorization);
$authorization = str_replace(",","&", $authorization);
$authorization = str_replace("\"","", $authorization);
$array = $this->convertUrlQuery($authorization);
if(!isset($array['signature'])) return false;
$message = $array['timestamp'] . "\n" . $array['nonce_str'] . "\n" . $body . "\n";
return $this->rsaPublicVerify($message, $array['signature']);
}
// 私钥加签
private function rsaPrivateSign($data)
{
$priKey = file_get_contents($this->merchant_private_file);
$res = openssl_pkey_get_private($priKey);
if(!$res){
throw new \Exception('私钥加签失败,商户私钥错误');
}
$result = openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
if (!$result) throw new \Exception('sign error');
return base64_encode($sign);
}
// 公钥验签
private function rsaPublicVerify($data, $sign)
{
$cert = file_get_contents($this->platform_cert_file);
$res = openssl_pkey_get_public($cert);
if(!$res){
throw new \Exception('公钥验签失败,平台公钥错误');
}
$result = (openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256) === 1);
return $result;
}
//从商户证书获取序列号
private function getMchSerialNo(){
$cert = file_get_contents($this->merchant_cert_file);
$ssl = openssl_x509_parse($cert);
if(!$ssl){
throw new \Exception('获取证书序列号失败');
}
return $ssl['serialNumber'];
}
//请求
protected function curl($url, $data, $authorization) {
$headers = [
"Authorization: " . $authorization,
"Accept: application/json",
"Content-Type: application/json; charset=utf-8",
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
//签名参数转数组
private function convertUrlQuery($query) {
$queryParts = explode('&', $query);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
if($params['signature']) {
$params['signature'] = substr($query, strrpos($query, 'signature=') + 10);
}
return $params;
}
}
+488
View File
@@ -0,0 +1,488 @@
<?php
class lakala_plugin
{
static public $info = [
'name' => 'lakala', //支付插件英文名称,需和目录名称一致,不能有重复
'showname' => '拉卡拉', //支付插件显示名称
'author' => '拉卡拉', //支付插件作者
'link' => 'https://www.lakala.com/', //支付插件作者链接
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
'appid' => [
'name' => 'APPID',
'type' => 'input',
'note' => '',
],
'appmchid' => [
'name' => '商户号',
'type' => 'input',
'note' => '',
],
'appkey' => [
'name' => '终端号',
'type' => 'input',
'note' => '',
],
'appselect' => [
'name' => '接口类型',
'type' => 'select',
'options' => [0=>'聚合扫码',1=>'聚合收银台'],
],
'appswitch' => [
'name' => '环境选择',
'type' => 'select',
'options' => [0=>'生产环境',1=>'测试环境'],
],
],
'select' => null,
'note' => '将商户证书 api_cert.cer(或APPID.cer)、商户私钥 api_private_key.pem(或APPID.pem)上传到 /plugins/lakala/cert/', //支付密钥填写说明
'bindwxmp' => true, //是否支持绑定微信公众号
'bindwxa' => true, //是否支持绑定微信小程序
];
static public function submit(){
global $siteurl, $channel, $order, $sitename;
if($channel['appselect'] == 1){
return ['type'=>'jump','url'=>'/pay/cashier/'.TRADE_NO.'/?type='.$order['typename']];
}elseif($order['typename']=='alipay'){
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
}elseif($order['typename']=='wxpay'){
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')!==false && $channel['appwxmp']>0){
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/'];
}elseif(checkmobile()==true && $channel['appwxa']>0){
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
}else{
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
}
}elseif($order['typename']=='bank'){
return ['type'=>'jump','url'=>'/pay/bank/'.TRADE_NO.'/'];
}
}
static public function mapi(){
global $siteurl, $channel, $order, $conf, $device, $mdevice;
if($channel['appselect'] == 1){
return ['type'=>'jump','url'=>'/pay/cashier/'.TRADE_NO.'/?type='.$order['typename']];
}elseif($order['typename']=='alipay'){
return self::alipay();
}elseif($order['typename']=='wxpay'){
if($mdevice=='wechat'){
return self::wxjspay();
}elseif($device=='mobile' && $channel['appwxa']>0){
return self::wxwappay();
}else{
return self::wxpay();
}
}elseif($order['typename']=='bank'){
return self::bank();
}
}
//聚合扫码下单
static private function qrcode($account_type, $trans_type, $extend = null){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'merchant_no' => $channel['appmchid'],
'term_no' => $channel['appkey'],
'out_trade_no' => TRADE_NO,
'account_type' => $account_type,
'trans_type' => $trans_type,
'total_amount' => strval($order['realmoney']*100),
'location_info' => [
'request_ip' => $clientip
],
'subject' => $ordername,
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
];
if($extend){
$params['acc_busi_fields'] = $extend;
}
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
global $channel;
$result = $client->execute('/api/v3/labs/trans/preorder', $params);
\lib\Payment::updateOrder(TRADE_NO, $result['trade_no']);
if($channel['appswitch']==1){
echo '<div>请求报文:<br/><textarea name="request_body" rows="3" style="width:100%">'.$client->request_body.'</textarea><br/>返回报文:<br/><textarea name="response_body" rows="3" style="width:100%">'.$client->response_body.'</textarea></div>';
}
return $result['acc_resp_fields'];
});
}
//被扫支付
static public function micropay(){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
$auth_code = $_GET['auth_code'];
if(!$auth_code) return ['type'=>'error','msg'=>'auth_code不能为空'];
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'merchant_no' => $channel['appmchid'],
'term_no' => $channel['appkey'],
'out_trade_no' => TRADE_NO,
'auth_code' => $auth_code,
'total_amount' => strval($order['realmoney']*100),
'location_info' => [
'request_ip' => $clientip
],
'subject' => $ordername,
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
];
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
try{
$result = \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
global $channel;
$result = $client->execute('/api/v3/labs/trans/micropay', $params);
\lib\Payment::updateOrder(TRADE_NO, $result['trade_no']);
if($channel['appswitch']==1){
echo '<div>请求报文:<br/><textarea name="request_body" rows="3" style="width:100%">'.$client->request_body.'</textarea><br/>返回报文:<br/><textarea name="response_body" rows="3" style="width:100%">'.$client->response_body.'</textarea></div>';
}
return $result['acc_resp_fields'];
});
return ['type'=>'error','msg'=>'被扫支付下单成功!'.json_encode($result)];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'被扫支付下单失败!'.$ex->getMessage()];
}
}
//交易查询
static public function query(){
global $channel, $order;
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'merchant_no' => $channel['appmchid'],
'term_no' => $channel['appkey'],
'out_trade_no' => TRADE_NO,
];
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
try{
$result = $client->execute('/api/v3/labs/query/tradequery', $params);
if($channel['appswitch']==1){
echo '<div>请求报文:<br/><textarea name="request_body" rows="3" style="width:100%">'.$client->request_body.'</textarea><br/>返回报文:<br/><textarea name="response_body" rows="3" style="width:100%">'.$client->response_body.'</textarea></div>';
}
echo '交易查询成功!'.json_encode($result);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'交易查询失败!'.$ex->getMessage()];
}
}
//收银台下单
static public function cashier(){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
$pay_type = $_GET['type'];
if($pay_type == 'alipay'){
$pay_mode = 'ALIPAY';
}elseif($pay_type == 'wxpay'){
$pay_mode = 'WECHAT';
}elseif($pay_type == 'bank'){
$pay_mode = 'UNION';
}
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'out_order_no' => TRADE_NO,
'merchant_no' => $channel['appmchid'],
//'term_no' => $channel['appkey'],
'total_amount' => strval($order['realmoney']*100),
'order_efficient_time' => date('YmdHis', time()+1200),
'notify_url' => $conf['localurl'] . 'pay/cashiernotify/' . TRADE_NO . '/',
'support_refund' => 1,
'callback_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
'order_info' => $ordername,
'counter_param' => json_encode(['pay_mode'=>$pay_mode]),
];
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
try{
$result = $client->cashier('/api/v3/ccss/counter/order/special_create', $params);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'收银台下单失败!'.$ex->getMessage()];
}
\lib\Payment::updateOrder(TRADE_NO, $result['pay_order_no']);
if($channel['appswitch']==1){
echo '<div>请求报文:<br/><textarea name="request_body" rows="3" style="width:100%">'.$client->request_body.'</textarea><br/>返回报文:<br/><textarea name="response_body" rows="3" style="width:100%">'.$client->response_body.'</textarea><br/><br/><a href="'.$result['counter_url'].'">点此继续支付</a></div>';
exit;
}
return ['type'=>'jump','url'=>$result['counter_url']];
}
//交易查询
static public function cashierquery(){
global $channel, $order;
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'merchant_no' => $channel['appmchid'],
'out_order_no' => TRADE_NO,
];
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
try{
$result = $client->cashier('/api/v3/ccss/counter/order/query', $params);
if($channel['appswitch']==1){
echo '<div>请求报文:<br/><textarea name="request_body" rows="3" style="width:100%">'.$client->request_body.'</textarea><br/>返回报文:<br/><textarea name="response_body" rows="3" style="width:100%">'.$client->response_body.'</textarea></div>';
}
echo '交易查询成功!'.json_encode($result);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'交易查询失败!'.$ex->getMessage()];
}
}
//支付宝扫码支付
static public function alipay(){
try{
$result = self::qrcode('ALIPAY', '41');
$code_url = $result['code'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
}
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
}
//微信扫码支付
static public function wxpay(){
global $channel, $siteurl;
/*try{
$result = self::qrcode('WECHAT', '41');
$code_url = $result['code'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}*/
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
if (checkmobile()==true) {
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$code_url];
} else {
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$code_url];
}
}
//微信公众号支付
static public function wxjspay(){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
try{
$tools = new \WeChatPay\JsApiTool($wxinfo['appid'], $wxinfo['appsecret']);
$openid = $tools->GetOpenid();
}catch(Exception $e){
return ['type'=>'error','msg'=>$e->getMessage()];
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks) return $blocks;
try{
$extend = ['sub_appid' => $wxinfo['appid'], 'user_id' => $openid];
$result = self::qrcode('WECHAT', '51', $extend);
$pay_info = ['appId'=>$result['app_id'],'timeStamp'=>$result['time_stamp'],'nonceStr'=>$result['nonce_str'],'package'=>$result['package'],'paySign'=>$result['pay_sign'],'signType'=>$result['sign_type']];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
}
if($_GET['d']=='1'){
$redirect_url='data.backurl';
}else{
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
}
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>json_encode($pay_info), 'redirect_url'=>$redirect_url]];
}
//微信小程序支付
static public function wxminipay(){
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
$code = isset($_GET['code'])?trim($_GET['code']):exit('{"code":-1,"msg":"code不能为空"}');
$wxinfo = \lib\Channel::getWeixin($channel['appwxa']);
if(!$wxinfo)exit('{"code":-1,"msg":"支付通道绑定的微信小程序不存在"}');
try{
$tools = new \WeChatPay\JsApiTool($wxinfo['appid'], $wxinfo['appsecret']);
$openid = $tools->AppGetOpenid($code);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks)exit('{"code":-1,"msg":"'.$blocks['msg'].'"}');
try{
$extend = ['sub_appid' => $wxinfo['appid'], 'user_id' => $openid];
$result = self::qrcode('WECHAT', '71', $extend);
$pay_info = ['appId'=>$result['app_id'],'timeStamp'=>$result['time_stamp'],'nonceStr'=>$result['nonce_str'],'package'=>$result['package'],'paySign'=>$result['pay_sign'],'signType'=>$result['sign_type']];
}catch(Exception $ex){
exit(json_encode(['code'=>-1, 'msg'=>'微信支付下单失败 '.$ex->getMessage()]));
}
exit(json_encode(['code'=>0, 'data'=>$pay_info]));
}
//微信手机支付
static public function wxwappay(){
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
if($channel['appwxa']>0){
$wxinfo = \lib\Channel::getWeixin($channel['appwxa']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信小程序不存在'];
try{
$code_url = wxminipay_jump_scheme($wxinfo['id'], TRADE_NO);
}catch(Exception $e){
return ['type'=>'error','msg'=>$e->getMessage()];
}
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$code_url];
}elseif($channel['appwxmp']>0){
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$code_url];
}else{
return self::wxpay();
}
}
//云闪付扫码支付
static public function bank(){
try{
$result = self::qrcode('UQRCODEPAY', '41');
$code_url = $result['code'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
}
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
}
//异步回调
static public function notify(){
global $channel, $order;
$json = file_get_contents('php://input');
if($channel['appswitch']==1){
file_put_contents('lakala_log.txt',$json);
}
$data = json_decode($json, true);
if(!$data) return ['type'=>'html','data'=>'no data'];
$authorization = $_SERVER['HTTP_AUTHORIZATION'];
if(!$authorization) return ['type'=>'html','data'=>'no sign'];
require(PAY_ROOT."inc/LakalaClient.php");
//计算得出通知验证结果
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
$verify_result = $client->verifySign($authorization, $json);
if($verify_result) {//验证成功
$out_trade_no = $data['out_trade_no'];
$api_trade_no = $data['trade_no'];
$total_amount = $data['total_amount'];
$buyer = $data['user_id2'];
if($data['trade_status'] == 'SUCCESS'){
if($out_trade_no == TRADE_NO){
processNotify($order, $api_trade_no, $buyer);
}
}
return ['type'=>'html','data'=>'success'];
}
else {
//验证失败
return ['type'=>'html','data'=>'fail'];
}
}
//异步回调
static public function cashiernotify(){
global $channel, $order;
$json = file_get_contents('php://input');
if($channel['appswitch']==1){
file_put_contents('lakala_log.txt',$json);
}
$data = json_decode($json, true);
if(!$data) return ['type'=>'html','data'=>'no data'];
$authorization = $_SERVER['HTTP_AUTHORIZATION'];
if(!$authorization) return ['type'=>'html','data'=>'no sign'];
require(PAY_ROOT."inc/LakalaClient.php");
//计算得出通知验证结果
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
$verify_result = $client->verifySign($authorization, $json);
if($verify_result) {//验证成功
$out_trade_no = $data['out_order_no'];
$api_trade_no = $data['order_trade_info']['trade_no'];
$total_amount = $data['total_amount'];
$buyer = $data['order_trade_info']['user_id2'];
if($data['order_status'] == '2'){
if($out_trade_no == TRADE_NO){
processNotify($order, $api_trade_no, $buyer);
}
}
return ['type'=>'html','data'=>'success'];
}
else {
//验证失败
return ['type'=>'html','data'=>'fail'];
}
}
//支付返回页面
static public function return(){
return ['type'=>'page','page'=>'return'];
}
//退款
static public function refund($order){
global $channel, $clientip;
if(empty($order))exit();
require(PAY_ROOT."inc/LakalaClient.php");
$params = [
'merchant_no' => $channel['appmchid'],
'term_no' => $channel['appkey'],
'out_trade_no' => $order['refund_no'],
'refund_amount' => strval($order['refundmoney']*100),
'origin_out_trade_no' => $order['trade_no'],
'origin_trade_no' => $order['api_trade_no'],
'location_info' => [
'request_ip' => $clientip
],
];
//print_r($params);
$client = new LakalaClient($channel['appid'], $channel['appswitch']==1);
try{
$result = $client->execute('/api/v3/labs/relation/refund', $params);
return ['code'=>0, 'trade_no'=>$result['trade_no'], 'refund_fee'=>$result['refund_amount']/100];
}catch(Exception $ex){
return ['code'=>-1, 'msg'=>$ex->getMessage()];
}
}
}