部署仓库初始化: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

+386
View File
@@ -0,0 +1,386 @@
<?php
/**
* http://180.168.100.158:13318/fuiouWposApipay/
*/
class fuiou3_plugin
{
static public $info = [
'name' => 'fuiou3', //支付插件英文名称,需和目录名称一致,不能有重复
'showname' => '富友支付(互联网)', //支付插件显示名称
'author' => '富友', //支付插件作者
'link' => 'https://www.fuiou.com/', //支付插件作者链接
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
'appid' => [
'name' => '商户号',
'type' => 'input',
'note' => '',
],
'appsecret' => [
'name' => '商户私钥',
'type' => 'textarea',
'note' => '',
],
'appkey' => [
'name' => '富友公钥',
'type' => 'textarea',
'note' => '',
],
'appswitch' => [
'name' => '环境选择',
'type' => 'select',
'options' => [0=>'生产环境',1=>'测试环境'],
],
],
'select' => null,
'select_wxpay' => [
'1' => '扫码支付',
'2' => '公众号/小程序支付',
'3' => '跳转富友小程序',
],
'note' => '', //支付密钥填写说明
'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 || in_array('3',$channel['apptype']))){
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, $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 || in_array('3',$channel['apptype']))){
return self::wxwappay();
}else{
return self::wxpay();
}
}elseif($order['typename']=='bank'){
return self::bank();
}
}
//通用下单
static private function addOrder($pay_type, $appid = null, $openid = null){
global $siteurl, $channel, $order, $ordername, $clientip, $conf;
require(PAY_ROOT."inc/PayService.class.php");
if($channel['appswitch'] == 1){
$apiurl = 'https://hlwnets-test.fuioupay.com/aggpos/order.fuiou';
}else{
$apiurl = 'https://hlwnets.fuioupay.com/aggpos/order.fuiou';
}
$param = [
'order_date' => date('Ymd'),
'order_id' => TRADE_NO,
'order_amt' => strval($order['realmoney']*100),
'order_pay_type' => $pay_type,
'back_notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
'goods_name' => $ordername,
'goods_detail' => $ordername,
];
if($appid) $param['appid'] = $appid;
if($openid) $param['openid'] = $openid;
$client = new PayService($channel['appid'],$channel['appkey'],$channel['appsecret']);
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $apiurl, $param) {
$result = $client->submit($apiurl, $param);
return $result['order_info'];
});
}
//支付宝扫码支付
static public function alipay(){
global $channel, $device, $mdevice, $siteurl;
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
}else{
try{
$code_url = self::addOrder('ALIPAY');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
}
}
if(checkalipay() || $mdevice=='alipay'){
return ['type'=>'jump','url'=>$code_url];
}else{
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
}
}
static public function alipayjs(){
global $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{
$payinfo = self::addOrder('FWC', null, $user_id);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
}
$payinfo = json_decode($payinfo, true);
if($method == 'jsapi'){
return ['type'=>'jsapi','data'=>$payinfo['tradeNO']];
}
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'=>$payinfo['tradeNO'], 'redirect_url'=>$redirect_url]];
}
//微信扫码支付
static public function wxpay(){
global $channel, $siteurl, $device, $mdevice;
if(in_array('1',$channel['apptype'])){
try{
$code_url = self::addOrder('WECHAT');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
}elseif(in_array('2',$channel['apptype'])){
if($channel['appwxmp']>0){
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
}else{
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
}
}elseif(in_array('3',$channel['apptype'])){
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
}
if($mdevice == 'wechat' || checkwechat()){
return ['type'=>'jump','url'=>$code_url];
} elseif (checkmobile()) {
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, $method;
//①、获取用户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{
$payinfo = self::addOrder($order['is_applet'] == 1 ? 'LETPAY' : 'JSAPI', $wxinfo['appid'], $openid);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
if($method == 'jsapi'){
return ['type'=>'jsapi','data'=>$payinfo];
}
if($_GET['d']==1){
$redirect_url='data.backurl';
}else{
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
}
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$payinfo, 'redirect_url'=>$redirect_url]];
}
//微信手机支付
static public function wxwappay(){
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
if(in_array('3',$channel['apptype'])){
try{
$token = self::addOrder('TAPPLET');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
$code_url = 'weixin://dl/business/?appid=wx2877080d739b734a&path=pages/qrPay/qrPay&query=t%3D'.$token;
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$code_url];
}elseif($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];
}else{
return self::wxpay();
}
}
//微信小程序支付
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{
$jsApiParameters = self::addOrder('LETPAY', $wxinfo['appid'], $openid);
}catch(Exception $ex){
exit('{"code":-1,"msg":"'.$ex->getMessage().'"}');
}
exit(json_encode(['code'=>0, 'data'=>json_decode($jsApiParameters, true)]));
}
//云闪付扫码支付
static public function bank(){
try{
$code_url = self::addOrder('UNIONPAY');
}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');
$data = json_decode($json,true);
if(!$data) return ['type'=>'html','data'=>'no data'];
require(PAY_ROOT."inc/PayService.class.php");
$client = new PayService($channel['appid'],$channel['appkey'],$channel['appsecret']);
$arr = $client->decryptNotify($data['message']);
if ($arr) {
if($arr['order_st'] == 1){
$out_trade_no = $arr['order_id'];
$trade_no = $arr['order_fas_ssn'];
$money = $arr['order_amt'];
$buyer = $arr['openid'];
$bill_trade_no = $arr['pay_ssn'];
$bill_mch_trade_no = $arr['fy_order_id'];
if($out_trade_no == TRADE_NO){
processNotify($order, $trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
}
return ['type'=>'html','data'=>'success'];
}
return ['type'=>'html','data'=>'status_fail'];
}else{
return ['type'=>'html','data'=>'decrypt_fail'];
}
}
//同步回调
static public function return(){
return ['type'=>'page','page'=>'return'];
}
//退款
static public function refund($order){
global $channel;
if(empty($order))exit();
require(PAY_ROOT."inc/PayService.class.php");
if($channel['appswitch'] == 1){
$apiurl = 'https://refund-transfer-test.fuioupay.com/refund_transfer/aggposRefund.fuiou';
}else{
$apiurl = 'https://refund-transfer.fuioupay.com/refund_transfer/aggposRefund.fuiou';
}
$param = [
'refund_order_date' => date('Ymd'),
'refund_order_id' => $order['refund_no'],
'pay_order_date' => date('Ymd', strtotime($order['addtime'])),
'pay_order_id' => $order['trade_no'],
'refund_amt' => strval($order['refundmoney']*100),
];
$client = new PayService($channel['appid'],$channel['appkey'],$channel['appsecret']);
try{
$result = $client->submit($apiurl, $param);
return ['code'=>0, 'trade_no'=>$result['pay_order_id'], 'refund_fee'=>$result['refund_amt']];
}catch(Exception $ex){
return ['code'=>-1, 'msg'=>$ex->getMessage()];
}
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
class PayService
{
private $version = '1.0.0';
private $mchnt_cd;
private $platform_public_key;
private $merchant_private_key;
public function __construct($mchnt_cd, $platform_public_key, $merchant_private_key)
{
$this->mchnt_cd = $mchnt_cd;
$this->platform_public_key = $platform_public_key;
$this->merchant_private_key = $merchant_private_key;
}
//发起API请求
public function submit($requrl, $params){
$public_params = [
'ver' => $this->version,
'mchnt_cd' => $this->mchnt_cd,
];
$params = array_merge($public_params, $params);
$data = json_encode($params);
$data = $this->rsaPublicEncrypt($data);
$body = json_encode(['mchnt_cd'=>$this->mchnt_cd, 'message'=>$data]);
$response = get_curl($requrl, $body, 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
$result = json_decode($response, true);
if(isset($result['resp_code']) && $result['resp_code']=='0000'){
$data = $this->rsaPrivateDecrypt($result['message']);
$arr = json_decode($data, true);
if(!$arr){
throw new Exception('返回数据私钥解密失败');
}
return $arr;
}elseif(isset($result['resp_desc'])){
throw new Exception($result['resp_desc']);
}else{
throw new Exception('返回数据解析失败');
}
}
//回调数据解密
public function decryptNotify($message){
$data = $this->rsaPrivateDecrypt($message);
return json_decode($data, true);
}
//平台公钥加密
private function rsaPublicEncrypt($data){
if(!is_string($data)) return null;
$pubKey = str_replace(array("\r\n", "\r", "\n"), "", $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('加密失败,平台公钥不正确');
}
$encrypted = '';
$partLen = openssl_pkey_get_details($pubkeyid)['bits']/8 - 11;
$plainData = str_split($data, $partLen);
foreach ($plainData as $chunk) {
$partialEncrypted = '';
$encryptionOk = openssl_public_encrypt($chunk, $partialEncrypted, $pubkeyid);
if ($encryptionOk === false) {
return false;
}
$encrypted .= $partialEncrypted;
}
return base64_encode($encrypted);
}
//商户私钥解密
private function rsaPrivateDecrypt($data){
$priKey = str_replace(array("\r\n", "\r", "\n"), "", $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('解密失败,商户私钥不正确');
}
$decrypted = '';
$partLen = openssl_pkey_get_details($pkeyid)['bits'] / 8;
$data = str_split(base64_decode($data), $partLen);
foreach ($data as $chunk) {
$partial = '';
$decryptionOK = openssl_private_decrypt($chunk, $partial, $pkeyid);
if ($decryptionOK === false) {
return false;
}
$decrypted .= $partial;
}
return $decrypted;
}
}