部署仓库初始化:epay 部署配置、补丁与插件

- docker-compose.prod.yml:挂载 epay-ui.css/js/head.php 补丁到 staging(镜像升级不丢)
- docker/nginx.conf:补丁静态资源 no-cache,改版立即生效
- patches/:
  - test.php 修复 paytype JSON 对象导致测试支付页空白
  - epay-ui.css 后台全屏/侧栏加宽/导航两列布局覆盖
  - epay-ui.js 去除页面容器宽度限制 + 侧栏当前菜单自动滚动
  - head.php 资源 ?v= 版本号强制回源
  - functions.php is_public_url 白名单等既有补丁
- plugins/ 支付插件源码
- .gitignore 排除 .env 等敏感与临时文件
This commit is contained in:
opencode committed 2026-10-21 13:05:20 +08:00
commit b7613ba082
176 files changed
+47057

No files matched your search

+518
View File
@@ -0,0 +1,518 @@
<?php
class hlpay_plugin
{
static public $info = [
'name' => 'hlpay', //支付插件英文名称,需和目录名称一致,不能有重复
'showname' => '汇联支付', //支付插件显示名称
'author' => '汇联', //支付插件作者
'link' => 'https://www.huilianlink.com/', //支付插件作者链接
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
'transtypes' => ['alipay','wxpay'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
'appid' => [
'name' => '应用APPID',
'type' => 'input',
'note' => '',
],
'appkey' => [
'name' => '商户私钥',
'type' => 'textarea',
'note' => '',
],
'appsecret' => [
'name' => '平台公钥',
'type' => 'textarea',
'note' => '',
],
'channelcode' => [
'name' => '通道编码',
'type' => 'input',
'note' => '可留空,留空为随机路由',
],
'appmchid' => [
'name' => '子商户编码',
'type' => 'input',
'note' => '仅服务商可传,普通商户请勿填写',
],
'appswitch' => [
'name' => '场景类型',
'type' => 'select',
'options' => [1=>'线下',2=>'线上'],
],
],
'select' => null,
'select_alipay' => [
'1' => '扫码支付',
'2' => 'JS支付',
'3' => 'PC支付',
'4' => 'H5支付',
],
'select_wxpay' => [
'1' => '扫码支付',
'2' => '公众号/小程序支付',
],
'note' => null, //支付密钥填写说明
'bindwxmp' => true, //是否支持绑定微信公众号
'bindwxa' => true, //是否支持绑定微信小程序
];
static public function submit(){
global $siteurl, $channel, $order, $sitename;
if($order['typename']=='alipay'){
if(checkalipay() && in_array('2',$channel['apptype'])){
return ['type'=>'jump','url'=>'/pay/alipayjs/'.TRADE_NO.'/?d=1'];
}else{
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
}
}elseif($order['typename']=='wxpay'){
if(checkwechat() && in_array('2',$channel['apptype']) && $channel['appwxmp']>0){
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
}elseif(checkmobile() && in_array('2',$channel['apptype']) && $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, $method;
if($method=='jsapi'){
if($order['typename']=='alipay'){
return self::alipayjs();
}elseif($order['typename']=='wxpay'){
return self::wxjspay();
}
}elseif($order['typename']=='alipay'){
if($mdevice=='alipay' && in_array('2',$channel['apptype'])){
return ['type'=>'jump','url'=>$siteurl.'pay/alipayjs/'.TRADE_NO.'/?d=1'];
}else{
return self::alipay();
}
}elseif($order['typename']=='wxpay'){
if($mdevice=='wechat' && in_array('2',$channel['apptype']) && $channel['appwxmp']>0){
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
}elseif($device=='mobile' && in_array('2',$channel['apptype']) && $channel['appwxa']>0){
return self::wxwappay();
}else{
return self::wxpay();
}
}elseif($order['typename']=='bank'){
return self::bank();
}
}
//统一下单
static private function addOrder($pay_type, $pay_sub_type, $sub_appid=null, $sub_openid=null){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
require_once PAY_ROOT."inc/HlpayClient.php";
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
if($_GET['r'] == 1){
$returnUrl = $siteurl.'pay/ok/'.TRADE_NO.'/';
}else{
$returnUrl = $siteurl.'pay/return/'.TRADE_NO.'/';
}
$param = [
'payType' => $pay_type,
'paySubType' => $pay_sub_type,
'sceneType' => $channel['appswitch'],
'mchOrderNo' => TRADE_NO,
'amount' => $order['realmoney'],
'clientIp' => $clientip,
'subject' => $ordername,
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
'redirectUrl' => $returnUrl,
];
if(!empty($channel['channelcode'])){
$param['channelCode'] = $channel['channelcode'];
}
$extra = [];
if($sub_appid && $sub_openid){
$extra['subAppid'] = $sub_appid;
$extra['userId'] = $sub_openid;
}elseif($sub_openid){
$extra['userId'] = $sub_openid;
}
if($pay_type == 'WECHAT' && ($pay_sub_type == 'H5' || $pay_sub_type == 'APP')){
$extra['originalType'] = 0;
$extra['appName'] = $conf['sitename'];
}
if(!empty($extra)){
$param['extra'] = $extra;
}
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $param) {
$result = $client->execute('/openapi/pay/create', $param);
\lib\Payment::updateOrder(TRADE_NO, $result['payOrderNo']);
return $result;
});
}
//支付宝支付
static public function alipay(){
global $channel, $device, $mdevice, $siteurl;
if(in_array('4',$channel['apptype']) && ($device=='mobile' || checkmobile())){
$pay_sub_type = 'H5';
}elseif(in_array('3',$channel['apptype']) && ($device=='pc' || !checkmobile())){
$pay_sub_type = 'PC';
}elseif(in_array('1',$channel['apptype'])){
$pay_sub_type = 'NATIVE';
}elseif(in_array('2',$channel['apptype'])){
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
}elseif(in_array('4',$channel['apptype'])){
$qrcode_url = $siteurl.'pay/alipay/'.TRADE_NO.'/?r=1';
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$qrcode_url];
}else{
return ['type'=>'error','msg'=>'当前支付通道没有开启的支付方式'];
}
try{
$result = self::addOrder('ALIPAY', $pay_sub_type);
$code_url = $result['payInfo'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
}
if(checkalipay() || $mdevice=='alipay' || $pay_sub_type=='H5' || $pay_sub_type=='PC'){
return ['type'=>'jump','url'=>$code_url];
}else{
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
}
}
static public function alipayjs(){
global $conf, $method, $order;
if(!empty($order['sub_openid'])){
$user_id = $order['sub_openid'];
}else{
[$user_type, $user_id] = alipay_oauth();
}
$blocks = checkBlockUser($user_id, TRADE_NO);
if($blocks) return $blocks;
if($user_type == 'openid'){
return ['type'=>'error','msg'=>'支付宝快捷登录获取uid失败,需将用户标识切换到uid模式'];
}
try{
$result = self::addOrder('ALIPAY', 'JSAPI', null, $user_id);
$trade_no = $result['payInfo'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
}
if($method == 'jsapi'){
return ['type'=>'jsapi','data'=>$trade_no];
}
if($_GET['d']=='1'){
$redirect_url='data.backurl';
}else{
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
}
return ['type'=>'page','page'=>'alipay_jspay','data'=>['alipay_trade_no'=>$trade_no, 'redirect_url'=>$redirect_url]];
}
//微信扫码支付
static public function wxpay(){
global $channel, $device, $mdevice, $siteurl;
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
if($channel['appwxmp']>0 && $channel['appwxa']==0){
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
}else{
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
}
}else{
try{
$result = self::addOrder('WECHAT', 'NATIVE');
$code_url = $result['payInfo'];
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
}
if(checkwechat() || $mdevice=='wechat'){
return ['type'=>'jump','url'=>$code_url];
} elseif (checkmobile() || $device=='mobile') {
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, $method, $conf;
//①、获取用户openid
if(!empty($order['sub_openid'])){
if(!empty($order['sub_appid'])){
$wxinfo['appid'] = $order['sub_appid'];
}else{
if($order['is_applet'] == 1){
$wxinfo = \lib\Channel::getWeixin($channel['appwxa']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信小程序不存在'];
}else{
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
}
}
$openid = $order['sub_openid'];
}else{
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
$openid = wechat_oauth($wxinfo);
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks) return $blocks;
//②、统一下单
try{
$result = self::addOrder('WECHAT', $order['is_applet'] == 1 ? 'MINI_APP' : 'JSAPI', $wxinfo['appid'], $openid);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
if($method == 'jsapi'){
return ['type'=>'jsapi','data'=>$result['payInfo']];
}
if($_GET['d']==1){
$redirect_url='data.backurl';
}else{
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
}
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$result['payInfo'], 'redirect_url'=>$redirect_url]];
}
//微信小程序支付
static public function wxminipay(){
global $siteurl, $channel, $order, $ordername, $conf;
$code = isset($_GET['code'])?trim($_GET['code']):exit('{"code":-1,"msg":"code不能为空"}');
//①、获取用户openid
$wxinfo = \lib\Channel::getWeixin($channel['appwxa']);
if(!$wxinfo)exit('{"code":-1,"msg":"支付通道绑定的微信小程序不存在"}');
try{
$openid = wechat_applet_oauth($code, $wxinfo);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks)exit('{"code":-1,"msg":"'.$blocks['msg'].'"}');
//②、统一下单
try{
$result = self::addOrder('WECHAT', 'MINI_APP', $wxinfo['appid'], $openid);
}catch(Exception $ex){
exit('{"code":-1,"msg":"'.$ex->getMessage().'"}');
}
exit(json_encode(['code'=>0, 'data'=>json_decode($result['payInfo'], true)]));
}
//微信手机支付
static public function wxwappay(){
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
$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];
}
//云闪付扫码支付
static public function bank(){
global $channel;
try{
$code_url = self::addOrder('UNION_PAY', 'NATIVE');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
}
if(checkunionpay()){
return ['type'=>'jump','url'=>$code_url];
}else{
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
}
}
//异步回调
static public function notify(){
global $channel, $order;
$json = file_get_contents('php://input');
$arr = json_decode($json,true);
if(!$arr) return ['type'=>'html','data'=>'No data'];
require_once PAY_ROOT."inc/HlpayClient.php";
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
$verify_result = $client->verifySign($arr);
if($verify_result){
$data = $arr['data'];
if ($data['state'] == '3') {
$out_trade_no = $data['mchOrderNo'];
$trade_no = $data['payOrderNo'];
$bill_trade_no = $data['channelOrderNo'];
$bill_mch_trade_no = $data['instOrderNo'];
if($out_trade_no == TRADE_NO){
processNotify($order, $trade_no, null, $bill_trade_no, $bill_mch_trade_no);
}
return ['type'=>'html','data'=>'success'];
}
return ['type'=>'html','data'=>'status fail'];
}
else {
return ['type'=>'html','data'=>'sign fail'];
}
}
//支付成功页面
static public function ok(){
return ['type'=>'page','page'=>'ok'];
}
//支付返回页面
static public function return(){
return ['type'=>'page','page'=>'return'];
}
//退款
static public function refund($order){
global $channel;
if(empty($order))exit();
require_once PAY_ROOT."inc/HlpayClient.php";
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
$param = [
'payOrderNo' => $order['api_trade_no'],
'mchRefundOrderNo' => $order['refund_no'],
'amount' => $order['refundmoney'],
];
try{
$result = $client->execute('/openapi/pay/refund', $param);
}catch(Exception $e){
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
return ['code'=>0, 'trade_no'=>$result['instOrderNo'], 'refund_fee'=>$result['refundAmount']];
}
//转账
static public function transfer($channel, $bizParam){
global $clientip, $conf;
if(empty($channel) || empty($bizParam))exit();
if($bizParam['type'] == 'alipay') $entry_type = '1';
else if($bizParam['type'] == 'wxpay') $entry_type = '2';
else if($bizParam['type'] == 'bank') $entry_type = '3';
require_once PLUGIN_ROOT.'hlpay/inc/HlpayClient.php';
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
$param = [
'mchChannelCode' => $channel['channelcode'],
'entryType' => $entry_type,
'mchOrderNo' => $bizParam['out_biz_no'],
'amount' => $bizParam['money'],
'clientIp' => $clientip,
'remark' => $bizParam['desc'],
'name' => $bizParam['payee_real_name'],
'cardNo' => $bizParam['payee_account'],
];
if($bizParam['type'] == 'bank'){
$param['payeeType'] = '1';
}
if($bizParam['type'] == 'alipay'){
if(is_numeric($bizParam['payee_account']) && substr($bizParam['payee_account'],0,4)=='2088')$is_userid = 1;
elseif(strpos($bizParam['payee_account'], '@')!==false || is_numeric($bizParam['payee_account']))$is_userid = 2;
else $is_userid = 3;
$param['extra'] = ['accountType'=>$is_userid];
}
try{
$result = $client->execute('/openapi/payment/create', $param);
}catch(Exception $e){
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
if($result['status'] == 3){
$status = 1;
}elseif($result['status'] == 4 || $result['status'] == 6){
$status = 2;
}else{
$status = 0;
}
return ['code'=>0, 'status'=>$status, 'orderid'=>$result['payOrderNo'], 'paydate'=>date('Y-m-d H:i:s')];
}
//转账查询
static public function transfer_query($channel, $bizParam){
if(empty($channel) || empty($bizParam))exit();
require_once PLUGIN_ROOT.'hlpay/inc/HlpayClient.php';
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
$param = [
'mchOrderNo' => $bizParam['out_biz_no'],
];
try{
$result = $client->execute('/openapi/payment/query', $param);
}catch(Exception $e){
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
if($result['status'] == 3){
$status = 1;
}elseif($result['status'] == 4 || $result['status'] == 6){
$status = 2;
$errmsg = '转账失败';
}else{
$status = 0;
}
return ['code'=>0, 'status'=>$status, 'amount'=>$result['amount'], 'paydate'=>$result['successTime'], 'errmsg'=>$errmsg];
}
//余额查询
static public function balance_query($channel, $bizParam){
if(empty($channel))exit();
require_once PLUGIN_ROOT.'hlpay/inc/HlpayClient.php';
$client = new HlpayClient($channel['appid'], $channel['appkey'], $channel['appsecret'], $channel['appmchid']);
$param = [
'mchChannelCode' => $channel['channelcode'],
];
try{
$result = $client->execute('/openapi/payment/account', $param);
}catch(Exception $e){
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
$data = array_filter($result, function($value){
return $value['acctType'] == '3';
});
if(empty($data)) return ['code'=>-1, 'msg'=>'未查询到代付账户'];
return ['code'=>0, 'amount'=>$data[array_key_first($data)]['balance']];
}
}
+164
View File
@@ -0,0 +1,164 @@
<?php
/**
* @see https://doc.huilianlink.com/
*/
class HlpayClient
{
//接口地址
private $gateway_url = 'https://api.huilianlink.com';
//子商户编码
private $sub_sn;
//应用APPID
private $app_id;
//应用私钥
private $merchant_private_key;
//平台公钥
private $platform_public_key;
private $sign_type = 'RSA2';
private $version = '1.01';
public function __construct($app_id, $merchant_private_key, $platform_public_key, $sub_sn = null)
{
$this->sub_sn = $sub_sn;
$this->app_id = $app_id;
$this->merchant_private_key = $merchant_private_key;
$this->platform_public_key = $platform_public_key;
}
//请求API接口并解析返回数据
public function execute($path, $bizContent)
{
$requrl = $this->gateway_url . $path;
$params = [
'appId' => $this->app_id,
'subSn' => $this->sub_sn,
'timestamp' => time().'',
'requestId' => getMillisecond(),
'version' => $this->version,
'signType' => $this->sign_type,
'bizContent' => json_encode($bizContent, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)
];
$params['sign'] = $this->generateSign($params);
$response = get_curl($requrl, json_encode($params, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
$result = json_decode($response, true);
if(isset($result['code']) && $result['code']==200){
if(!$this->verifySign($result)){
throw new Exception('返回数据验签失败');
}
return $result['data'];
}elseif(isset($result['msg'])){
throw new Exception($result['msg']);
}else{
throw new Exception('返回数据解析失败');
}
}
//获取待签名字符串
private function getSignContent($param){
ksort($param);
$signstr = '';
foreach($param as $k => $v){
if($k != "sign" && !isNullOrEmpty($v)){
$signstr .= $k.'='.$v.'&';
}
}
$signstr = substr($signstr,0,-1);
return $signstr;
}
// 深度处理data字段(支持JSON字符串解析)
private static function processDataField($data) {
if (is_string($data)) {
$decoded = json_decode($data, true);
if (json_last_error() === JSON_ERROR_NONE) {
$data = $decoded;
}
}
if (is_array($data)) {
$filtered = self::deepFilterParams($data);
$sorted = self::deepSortParams($filtered);
return json_encode($sorted, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
return $data;
}
// 深度过滤空值参数(支持多维数组)
private static function deepFilterParams(array $params): array {
$filtered = [];
foreach ($params as $k => $v) {
if (isNullOrEmpty($v)) continue;
// 递归处理数组
if (is_array($v)) {
$v = self::deepFilterParams($v);
if (empty($v)) continue;
}
$filtered[$k] = $v;
}
return $filtered;
}
// 深度排序参数(支持多维数组)
private static function deepSortParams(array $params): array {
ksort($params, SORT_STRING);
foreach ($params as $k => $v) {
if (is_array($v)) {
$params[$k] = self::deepSortParams($v);
}
}
return $params;
}
//请求参数签名
private function generateSign($param){
return $this->rsaPrivateSign($this->getSignContent($param));
}
//验签方法
public function verifySign($param){
if(empty($param['sign'])) return false;
if (isset($param['data'])) {
$param['data'] = self::processDataField($param['data']);
}
return $this->rsaPubilcSign($this->getSignContent($param), $param['sign']);
}
//商户私钥签名
private function rsaPrivateSign($data){
$priKey = $this->merchant_private_key;
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($priKey, 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
$pkeyid = openssl_pkey_get_private($res);
if(!$pkeyid){
throw new Exception('签名失败,商户私钥不正确');
}
openssl_sign($data, $signature, $pkeyid, OPENSSL_ALGO_SHA256);
$signature = base64_encode($signature);
return $signature;
}
//平台公钥验签
private function rsaPubilcSign($data, $signature){
$pubKey = $this->platform_public_key;
$res = "-----BEGIN PUBLIC KEY-----\n" .
wordwrap($pubKey, 64, "\n", true) .
"\n-----END PUBLIC KEY-----";
$pubkeyid = openssl_pkey_get_public($res);
if(!$pubkeyid){
throw new Exception('验签失败,平台公钥不正确');
}
$result = openssl_verify($data, base64_decode($signature), $pubkeyid, OPENSSL_ALGO_SHA256);
return $result === 1;
}
}