部署仓库初始化: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:
commit
b7613ba082
176 files changed
+47057
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# 密钥与环境变量,禁止提交
|
||||
.env
|
||||
|
||||
# 日志与临时文件
|
||||
*.log
|
||||
*.tmp
|
||||
*.bak
|
||||
*.old
|
||||
@@ -0,0 +1,107 @@
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: epay-nginx
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${NGINX_PORT:-80}:80"
|
||||
volumes:
|
||||
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- app_data:/var/www/html:ro
|
||||
depends_on:
|
||||
php:
|
||||
condition: service_started
|
||||
networks:
|
||||
- epay-network
|
||||
|
||||
php:
|
||||
image: ghcr.io/aliveranme/epay:latest
|
||||
container_name: epay-php
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
DB_HOST: ${DB_HOST:-mysql}
|
||||
DB_PORT: ${DB_PORT:-3306}
|
||||
DB_USER: ${DB_USER:-epay}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_NAME: ${DB_NAME:-epay}
|
||||
DB_PREFIX: ${DB_PREFIX:-pay}
|
||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
||||
SITE_URL: ${SITE_URL:-http://localhost}
|
||||
# 部署自定义配置(可选):API 接口是否校验 timestamp,1=开启(默认),0=关闭(兼容不传 timestamp 的老平台)
|
||||
API_TIMESTAMP_CHECK: ${API_TIMESTAMP_CHECK:-}
|
||||
volumes:
|
||||
- app_data:/var/www/html
|
||||
- ./plugins:/var/www/html/plugins
|
||||
- uploads:/var/www/html/assets/uploads
|
||||
- sessions:/var/lib/php/sessions
|
||||
# 补丁:is_public_url 白名单(容器重启/升级后由 entrypoint 从 staging 自动同步)
|
||||
- ./patches/functions.php:/var/www/html-staging/includes/functions.php:ro
|
||||
# 补丁:后台布局覆盖 CSS(全屏自适应/侧栏加宽/导航两列)
|
||||
- ./patches/epay-ui.css:/var/www/html-staging/assets/dist/epay-ui.css:ro
|
||||
# 补丁:侧栏当前菜单自动滚动脚本
|
||||
- ./patches/epay-ui.js:/var/www/html-staging/assets/dist/epay-ui.js:ro
|
||||
# 补丁:后台入口资源版本号(?v= 强制回源)
|
||||
- ./patches/head.php:/var/www/html-staging/admin/head.php:ro
|
||||
# 补丁:后台改密码存明文(与登录逻辑一致)+ 登录兼容历史 md5 存储
|
||||
- ./patches/admin/set.php:/var/www/html-staging/admin/set.php:ro
|
||||
- ./patches/admin/login.php:/var/www/html-staging/admin/login.php:ro
|
||||
# 补丁:支付页轮询时主动向微信查单(异步回调延迟兜底),重启后由 staging 同步
|
||||
- ./patches/getshop.php:/var/www/html-staging/getshop.php:ro
|
||||
extra_hosts:
|
||||
- "newapi.88531.cn:host-gateway"
|
||||
- "ai.88531.cn:host-gateway"
|
||||
- "pay.88531.cn:host-gateway"
|
||||
networks:
|
||||
- epay-network
|
||||
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: epay-mysql
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
||||
MYSQL_DATABASE: ${DB_NAME:-epay}
|
||||
MYSQL_USER: ${DB_USER:-epay}
|
||||
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||
TZ: Asia/Shanghai
|
||||
command:
|
||||
- --character-set-server=utf8mb4
|
||||
- --collation-server=utf8mb4_unicode_ci
|
||||
- --sql-mode=
|
||||
- --default-time-zone=+08:00
|
||||
- --default-authentication-plugin=mysql_native_password
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
networks:
|
||||
- epay-network
|
||||
|
||||
cron:
|
||||
image: alpine:latest
|
||||
container_name: epay-cron
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
nginx:
|
||||
condition: service_started
|
||||
environment:
|
||||
CRON_KEY: ${CRON_KEY}
|
||||
SITE_URL: ${SITE_URL:-http://nginx}
|
||||
entrypoint: |
|
||||
/bin/sh -c '
|
||||
apk add --no-cache curl tzdata;
|
||||
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;
|
||||
echo "*/5 * * * * curl -s -o /dev/null -w \"%{http_code}\" $${SITE_URL}/cron.php?key=$${CRON_KEY}" > /etc/crontabs/root;
|
||||
crond -f -l 2
|
||||
'
|
||||
networks:
|
||||
- epay-network
|
||||
|
||||
volumes:
|
||||
app_data:
|
||||
uploads:
|
||||
sessions:
|
||||
mysql_data:
|
||||
|
||||
networks:
|
||||
epay-network:
|
||||
driver: bridge
|
||||
@@ -0,0 +1,127 @@
|
||||
# ============================================
|
||||
# 彩虹易支付 Nginx 配置
|
||||
# ============================================
|
||||
|
||||
upstream php-upstream {
|
||||
server php:9000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /var/www/html;
|
||||
index index.php index.html;
|
||||
|
||||
charset utf-8;
|
||||
client_max_body_size 50m;
|
||||
|
||||
# 反代环境下使用相对跳转,避免 301 到 http://
|
||||
absolute_redirect off;
|
||||
|
||||
# ==========================================
|
||||
# 信任宝塔 Nginx 反向代理传递的真实 IP
|
||||
# ==========================================
|
||||
set_real_ip_from 127.0.0.1;
|
||||
set_real_ip_from 172.16.0.0/12;
|
||||
set_real_ip_from 192.168.0.0/16;
|
||||
real_ip_header X-Forwarded-For;
|
||||
real_ip_recursive on;
|
||||
|
||||
# ==========================================
|
||||
# 安全响应头
|
||||
# ==========================================
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
||||
|
||||
# ==========================================
|
||||
# 安全规则:禁止直接访问核心目录
|
||||
# ==========================================
|
||||
location ^~ /includes {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
|
||||
location ^~ /plugins {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
|
||||
# install/index.php 在 install.lock 存在时自行拒绝重装;安装 SQL/锁文件不可下载。
|
||||
location ~* ^/install/.*\.(sql|lock)$ {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
|
||||
# 保护敏感文件
|
||||
location ~* /(config\.php|\.htaccess|\.git) {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# URL 重写规则(对应 nginx.txt)
|
||||
# ==========================================
|
||||
location / {
|
||||
# *.html → index.php?mod=xxx
|
||||
if (!-e $request_filename) {
|
||||
rewrite ^/(.[a-zA-Z0-9\-\_]+).html$ /index.php?mod=$1 last;
|
||||
}
|
||||
# /pay/xxx → pay.php?s=xxx
|
||||
rewrite ^/pay/(.*)$ /pay.php?s=$1 last;
|
||||
# /api/xxx → api.php?s=xxx
|
||||
rewrite ^/api/(.*)$ /api.php?s=$1 last;
|
||||
# /doc/xxx.html → index.php?doc=xxx
|
||||
rewrite ^/doc/(.[a-zA-Z0-9\-\_]+).html$ /index.php?doc=$1 last;
|
||||
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# PHP 处理
|
||||
# ==========================================
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass php-upstream;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
|
||||
# 安全:防止上传文件被执行
|
||||
fastcgi_param PHP_VALUE "open_basedir=/var/www/html:/tmp/:/var/lib/php/sessions/";
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# 静态资源缓存
|
||||
# ==========================================
|
||||
# 前端补丁文件(后台布局 CSS/JS):始终回源校验,改版立即生效
|
||||
location = /assets/dist/epay-ui.css {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Cache-Control "no-cache" always;
|
||||
}
|
||||
location = /assets/dist/epay-ui.js {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Cache-Control "no-cache" always;
|
||||
}
|
||||
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# 上传目录:禁止执行 PHP
|
||||
# ==========================================
|
||||
location /assets/uploads/ {
|
||||
location ~* \.php$ {
|
||||
deny all;
|
||||
return 403;
|
||||
}
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# 日志
|
||||
# ==========================================
|
||||
access_log /var/log/nginx/epay-access.log;
|
||||
error_log /var/log/nginx/epay-error.log;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
; ============================================
|
||||
; 彩虹易支付 PHP 自定义配置
|
||||
; ============================================
|
||||
|
||||
; 时区
|
||||
date.timezone = Asia/Shanghai
|
||||
|
||||
; 错误报告(生产环境关闭详细错误)
|
||||
error_reporting = E_ERROR | E_PARSE | E_COMPILE_ERROR
|
||||
display_errors = Off
|
||||
display_startup_errors = Off
|
||||
|
||||
; 性能
|
||||
max_execution_time = 300
|
||||
max_input_time = 300
|
||||
memory_limit = 256M
|
||||
|
||||
; 上传
|
||||
upload_max_filesize = 50M
|
||||
post_max_size = 50M
|
||||
file_uploads = On
|
||||
|
||||
; Session
|
||||
session.save_handler = files
|
||||
session.save_path = "/var/lib/php/sessions"
|
||||
session.gc_maxlifetime = 1440
|
||||
session.cookie_httponly = On
|
||||
; 生产环境部署在 HTTPS 下时建议改为 On
|
||||
session.cookie_secure = Off
|
||||
session.cookie_samesite = "Strict"
|
||||
session.use_strict_mode = 1
|
||||
session.use_only_cookies = 1
|
||||
|
||||
; 安全
|
||||
expose_php = Off
|
||||
allow_url_fopen = Off
|
||||
allow_url_include = Off
|
||||
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source,pcntl_exec
|
||||
enable_dl = Off
|
||||
|
||||
; cURL
|
||||
curl.cainfo = /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
; OpCache
|
||||
opcache.enable = 1
|
||||
opcache.memory_consumption = 128
|
||||
opcache.interned_strings_buffer = 8
|
||||
opcache.max_accelerated_files = 10000
|
||||
opcache.revalidate_freq = 2
|
||||
opcache.fast_shutdown = 1
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/** 管理员登录 API 与原生 shadcn 登录入口 */
|
||||
$verifycode = (function_exists('imagecreate') && file_exists('code.php')) ? 1 : 0;
|
||||
$login_limit_count = 5;
|
||||
include("../includes/common.php");
|
||||
$login_limit_file = sys_get_temp_dir() . '/epay_login_' . substr(md5(SYS_KEY), 0, 16) . '.lock';
|
||||
if(isset($_GET['act']) && $_GET['act'] === 'login'){
|
||||
if(!checkRefererHost()) exit('{"code":403}');
|
||||
$username = trim((string)($_POST['username'] ?? '')); $password = trim((string)($_POST['password'] ?? '')); $code = trim((string)($_POST['code'] ?? '')); $enc_type = (string)($_POST['enc'] ?? '0');
|
||||
if($username === '' || $password === '') exit(json_encode(['code'=>-1,'msg'=>'用户名或密码不能为空']));
|
||||
if($verifycode === 1 && (!$code || strtolower($code) !== ($_SESSION['vc_code'] ?? ''))) exit(json_encode(['code'=>-1,'msg'=>'验证码错误']));
|
||||
$errcount = $DB->getColumn("SELECT count(*) FROM `pre_log` WHERE `ip`=:ip AND `date`>DATE_SUB(NOW(),INTERVAL 1 DAY) AND `uid`=0 AND `type`='登录失败'", [':ip'=>$clientip]);
|
||||
if($errcount >= $login_limit_count && file_exists($login_limit_file)) exit(json_encode(['code'=>-1,'msg'=>'多次登录失败,暂时禁止登录']));
|
||||
if($enc_type === '1'){
|
||||
$plain = ''; $private_key = base64ToPem($conf['private_key'], 'PRIVATE KEY'); $pkey = openssl_pkey_get_private($private_key);
|
||||
if(!openssl_private_decrypt(base64_decode($password), $plain, $pkey, OPENSSL_PKCS1_PADDING)) exit(json_encode(['code'=>-1,'msg'=>'密码解密失败']));
|
||||
$password = $plain;
|
||||
}
|
||||
if($username === $conf['admin_user'] && ($password === $conf['admin_pwd'] || getMd5Pwd($password) === $conf['admin_pwd'])){
|
||||
if($conf['totp_open'] == 1 && !empty($conf['totp_secret'])) exit(json_encode(['code'=>-1,'msg'=>'需要验证动态口令','vcode'=>2]));
|
||||
$DB->insert('log', ['uid'=>0,'type'=>'登录后台','date'=>'NOW()','ip'=>$clientip]); if(file_exists($login_limit_file)) unlink($login_limit_file);
|
||||
$session = md5($username.$password.$password_hash); $expiretime = time()+2592000; $token = authcode("{$username}\t{$session}\t{$expiretime}",'ENCODE',SYS_KEY); $secure = is_https();
|
||||
setcookie('admin_token',$token,$expiretime,'/','',$secure,true); session_regenerate_id(true); unset($_SESSION['vc_code']); exit(json_encode(['code'=>0]));
|
||||
}
|
||||
$DB->insert('log', ['uid'=>0,'type'=>'登录失败','date'=>'NOW()','ip'=>$clientip]); unset($_SESSION['vc_code']); $errcount++;
|
||||
if($errcount >= $login_limit_count){ file_put_contents($login_limit_file,'1'); exit(json_encode(['code'=>-1,'msg'=>'多次登录失败,暂时禁止登录','vcode'=>1])); }
|
||||
exit(json_encode(['code'=>-1,'msg'=>'用户名或密码错误','vcode'=>1]));
|
||||
}
|
||||
if(isset($_GET['act']) && $_GET['act'] === 'totp'){
|
||||
if(!checkRefererHost()) exit('{"code":403}');
|
||||
$code = trim((string)($_POST['code'] ?? ''));
|
||||
if($code === '') exit(json_encode(['code'=>-1,'msg'=>'请输入动态口令']));
|
||||
if($conf['totp_open'] != 1 || empty($conf['totp_secret'])) exit(json_encode(['code'=>-1,'msg'=>'未启用TOTP二次验证']));
|
||||
try{ $totp = \lib\TOTP::create($conf['totp_secret']); if(!$totp->verify($code)) exit(json_encode(['code'=>-1,'msg'=>'动态口令错误'])); }catch(Exception $e){ exit(json_encode(['code'=>-1,'msg'=>$e->getMessage()])); }
|
||||
$DB->insert('log', ['uid'=>0,'type'=>'登录后台','date'=>'NOW()','ip'=>$clientip]); $session = md5($conf['admin_user'].$conf['admin_pwd'].$password_hash); $expiretime = time()+2592000; $token = authcode("{$conf['admin_user']}\t{$session}\t{$expiretime}",'ENCODE',SYS_KEY); $secure = is_https();
|
||||
setcookie('admin_token',$token,$expiretime,'/','',$secure,true); session_regenerate_id(true); exit(json_encode(['code'=>0]));
|
||||
}
|
||||
if(isset($_GET['logout'])){ if(!checkRefererHost()) exit(); $secure = is_https(); setcookie('admin_token','',time()-2592000,'/','',$secure,true); exit("<script>window.location.href='./login.php';</script>"); }
|
||||
if($islogin == 1) exit("<script>window.location.href='./';</script>");
|
||||
$title = '用户登录';
|
||||
$epay_ui_view = 'admin-login';
|
||||
$epay_ui_config = ['sitename'=>$conf['sitename'],'verifycode'=>$verifycode];
|
||||
include './head.php';
|
||||
?>
|
||||
<script>
|
||||
/* 登录动作由 React/shadcn 表单触发;这里仅保留后端 API 适配。 */
|
||||
window.submitlogin = async function(){
|
||||
var user = document.querySelector('#user')?.value.trim() || '';
|
||||
var pass = document.querySelector('#pass')?.value || '';
|
||||
var code = document.querySelector('#code')?.value.trim() || '';
|
||||
if(!user || !pass){ window.alert('用户名或密码不能为空'); return false; }
|
||||
var submit = document.querySelector('#submit');
|
||||
if(submit) submit.disabled = true;
|
||||
try{
|
||||
var response = await fetch('./login.php?act=login', {method:'POST', credentials:'same-origin', headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'}, body:new URLSearchParams({username:user, password:pass, code:code, enc:'0'})});
|
||||
var data = await response.json();
|
||||
if(Number(data.code) === 0){ window.location.href = './'; return false; }
|
||||
if(Number(data.vcode) === 1){ var image = document.querySelector('#verifycode'); if(image) image.src = './code.php?r='+Math.random(); }
|
||||
if(Number(data.vcode) === 2){ var loginForm = document.querySelector('#login-form'); var totpForm = document.querySelector('#totp-form'); if(loginForm) loginForm.classList.add('hidden'); if(totpForm){ totpForm.classList.remove('hidden'); totpForm.classList.add('flex'); } document.querySelector('#totp_code')?.focus(); return false; }
|
||||
window.alert(data.msg || '登录失败');
|
||||
}catch(error){ window.alert('服务器错误,请稍后重试'); }
|
||||
finally{ if(submit) submit.disabled = false; }
|
||||
return false;
|
||||
};
|
||||
window.doTotp = async function(){
|
||||
var code = document.querySelector('#totp_code')?.value.trim() || '';
|
||||
if(!/^\d{6}$/.test(code)){ window.alert('动态口令格式错误'); return false; }
|
||||
var submit = document.querySelector('#totp-form button[type="submit"]');
|
||||
if(submit) submit.disabled = true;
|
||||
try{
|
||||
var response = await fetch('./login.php?act=totp', {method:'POST', credentials:'same-origin', headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'}, body:new URLSearchParams({code:code})});
|
||||
var data = await response.json();
|
||||
if(Number(data.code) === 0){ window.location.href = './'; return false; }
|
||||
window.alert(data.msg || '动态口令验证失败');
|
||||
}catch(error){ window.alert('服务器错误,请稍后重试'); }
|
||||
finally{ if(submit) submit.disabled = false; }
|
||||
return false;
|
||||
};
|
||||
window.findpwd = function(){ window.alert('请进入数据库管理器修改 pre_config 表中的 admin_pwd;如已开启 TOTP,请同时清理 totp_open 和 totp_secret。'); };
|
||||
</script>
|
||||
</body></html>
|
||||
<?php exit;
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
include '/var/www/html/includes/common.php';
|
||||
$pwd = 'a3396336';
|
||||
$hash = hashPassword($pwd);
|
||||
var_dump($DB->update('user', ['pwd'=>$hash], ['uid'=>1001]));
|
||||
$row = $DB->getRow("SELECT pwd, LENGTH(pwd) AS plen FROM pre_user WHERE uid=1001");
|
||||
var_dump($row['plen'], verifyPassword($pwd, $row['pwd'], 1001));
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/** 系统设置(原生 shadcn 配置表单) */
|
||||
include("../includes/common.php");
|
||||
require_once __DIR__.'/epay_ui_entry.php';
|
||||
$mod = (string)($_GET['mod'] ?? 'site');
|
||||
$allowed = ['site','pay','risk','settle','transfer','oauth','notice','certificate','template','gonggao','mail','iptype','cron','proxy','account','upimg'];
|
||||
if(!in_array($mod, $allowed, true) && !in_array($mod, ['account_n','paypwd_n'], true)) $mod = 'site';
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($mod, ['account_n','paypwd_n'], true)){
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
$respond = function($code, $msg){ exit(json_encode(['code'=>$code,'msg'=>$msg], JSON_UNESCAPED_UNICODE)); };
|
||||
if(!isset($_POST['csrf_token']) || !isset($_SESSION['admin_csrf_token']) || !hash_equals((string)$_SESSION['admin_csrf_token'], (string)$_POST['csrf_token'])) $respond(-403, 'CSRF 校验失败,请刷新页面后重试。');
|
||||
if($mod === 'account_n'){
|
||||
$user = trim((string)($_POST['user'] ?? '')); $old = trim((string)($_POST['oldpwd'] ?? '')); $new = trim((string)($_POST['newpwd'] ?? '')); $new2 = trim((string)($_POST['newpwd2'] ?? ''));
|
||||
if($user === '' || !($old === (string)$conf['admin_pwd'] || getMd5Pwd($old) === (string)$conf['admin_pwd']) || $new === '' || $new !== $new2 || strlen($new) < 6) $respond(-1, '用户名、旧密码或新密码校验未通过。');
|
||||
saveSetting('admin_user', $user); saveSetting('admin_pwd', $new); $CACHE->clear(); $respond(0, '登录账号和密码已更新。');
|
||||
}
|
||||
$old = trim((string)($_POST['oldpwd'] ?? '')); $new = trim((string)($_POST['newpwd'] ?? '')); $new2 = trim((string)($_POST['newpwd2'] ?? ''));
|
||||
if($old !== (string)$conf['admin_paypwd'] || $new === '' || $new !== $new2 || strlen($new) < 6) $respond(-1, '旧支付密码或新密码校验未通过。');
|
||||
saveSetting('admin_paypwd', $new); $CACHE->clear(); $respond(0, '支付密码已更新。');
|
||||
}
|
||||
|
||||
$labels = [
|
||||
'sitename'=>'网站名称','title'=>'首页标题','keywords'=>'关键字','description'=>'网站描述','orgname'=>'公司/组织名称','localurl'=>'回调专用网址','apiurl'=>'用户对接网址','email'=>'联系邮箱','kfqq'=>'客服 QQ','qqqun'=>'加群链接','appurl'=>'APP 下载链接','verifytype'=>'用户验证方式','reg_open'=>'开放注册','reg_input_settle'=>'注册后可不填结算账户','user_review'=>'开启注册审核','reg_pay'=>'注册付费','reg_pay_price'=>'注册付费金额','user_settings_edit'=>'用户编辑接口信息','test_open'=>'测试支付','test_pay_uid'=>'测试支付收款商户 ID','captcha_id'=>'极验验证码 ID','captcha_key'=>'极验验证码密钥','captcha_version'=>'极验版本','captcha_open_login'=>'登录验证码','close_keylogin'=>'密钥登录','user_style'=>'用户中心风格','cdnpublic'=>'公共静态资源 CDN','homepage'=>'首页显示模式','homepage_url'=>'显示网址 URL',
|
||||
'pay_open'=>'开启支付','pay_verify'=>'支付验证','pay_minmoney'=>'最小支付金额','pay_maxmoney'=>'最大支付金额','pay_daymoney'=>'每日金额上限','pay_domain_open'=>'开放域名','pay_domain_forbid'=>'禁止未授权域名','pay_iplimit'=>'支付 IP 限制','pay_userlimit'=>'支付用户限制','ordername'=>'订单名称模板','notifyordername'=>'通知订单名称',
|
||||
'settle_open'=>'开启结算','settle_type'=>'结算方式','settle_transfer'=>'自动转账','settle_money'=>'最低结算金额','settle_rate'=>'结算费率','settle_fee_min'=>'最低手续费','settle_fee_max'=>'最高手续费','settle_maxlimit'=>'结算限额',
|
||||
'transfer_alipay'=>'支付宝付款通道','transfer_wxpay'=>'微信付款通道','transfer_qqpay'=>'QQ 付款通道','transfer_bank'=>'银行卡付款通道','transfer_rate'=>'付款费率','transfer_minmoney'=>'最低付款金额','transfer_maxmoney'=>'最高付款金额','transfer_maxlimit'=>'付款限额','transfer_name'=>'红包名称','transfer_desc'=>'红包备注',
|
||||
'login_apiurl'=>'快捷登录 API','login_wx'=>'微信登录公众号','login_wxa'=>'微信登录小程序','login_alipay'=>'支付宝登录通道','login_qq'=>'QQ 登录','login_appid'=>'应用 ID','login_appkey'=>'应用密钥','login_qq_appid'=>'QQ 应用 ID','login_qq_appkey'=>'QQ 应用密钥',
|
||||
'wxnotice'=>'微信通知','mailnotice'=>'邮件通知','robotnotice'=>'机器人通知','msgrobot_url'=>'机器人地址','msgrobot_phone'=>'机器人手机号','cronkey'=>'计划任务密钥','ip_type'=>'IP 获取方式','proxy_server'=>'代理服务器','proxy_port'=>'代理端口','proxy_user'=>'代理用户','proxy_pwd'=>'代理密码','proxy_type'=>'代理类型',
|
||||
'cert_open'=>'实名认证','cert_force'=>'强制认证','cert_money'=>'认证金额','cert_channel'=>'认证通道','cert_aliyunid'=>'阿里云 ID','cert_aliyunkey'=>'阿里云密钥','cert_qcloudid'=>'腾讯云 ID','cert_qcloudkey'=>'腾讯云密钥','template'=>'首页模板','footer'=>'页脚内容','mail_smtp'=>'SMTP 服务器','mail_port'=>'SMTP 端口','mail_user'=>'SMTP 用户名','mail_pwd'=>'SMTP 密码','mail_name'=>'发件人名称','mail_recv'=>'接收邮箱','sms_api'=>'短信接口','sms_appid'=>'短信应用 ID','sms_appkey'=>'短信应用密钥','account'=>'管理员账户','cron'=>'计划任务配置','proxy'=>'中转代理配置','iptype'=>'IP 获取方式','gonggao'=>'网站公告配置','upimg'=>'首页 LOGO 设置',
|
||||
];
|
||||
$modKeys = [
|
||||
'site'=>['sitename','title','keywords','description','orgname','localurl','apiurl','email','kfqq','qqqun','appurl','verifytype','reg_open','reg_input_settle','user_review','reg_pay','reg_pay_price','user_settings_edit','test_open','test_pay_uid','captcha_id','captcha_key','captcha_version','captcha_open_login','close_keylogin','user_style','cdnpublic','homepage','homepage_url'],
|
||||
'pay'=>['pay_open','pay_verify','pay_minmoney','pay_maxmoney','pay_daymoney','pay_domain_open','pay_domain_forbid','pay_iplimit','pay_userlimit','ordername','notifyordername','pay_payaddstart','pay_payaddmin','pay_payaddmax','check_pay_regoin'],
|
||||
'risk'=>['check_channel_failcount','check_channel_second','check_notify_count','check_payip_count','check_payip_second','check_payspeed_count','check_payspeed_days','check_payspeed_second','check_sucrate_count','check_sucrate_second','check_sucrate_value','blockalert','blockname','black_payact'],
|
||||
'settle'=>['settle_open','settle_type','settle_transfer','settle_money','settle_rate','settle_fee_min','settle_fee_max','settle_maxlimit','settle_alipay','settle_wxpay','settle_qqpay','settle_bank'],
|
||||
'transfer'=>['transfer_alipay','transfer_wxpay','transfer_qqpay','transfer_bank','transfer_rate','transfer_minmoney','transfer_maxmoney','transfer_maxlimit','transfer_name','transfer_desc'],
|
||||
'oauth'=>['login_apiurl','login_wx','login_wxa','login_alipay','login_qq','login_appid','login_appkey','login_qq_appid','login_qq_appkey'],
|
||||
'notice'=>['wxnotice','mailnotice','robotnotice','msgrobot_url','msgrobot_phone','msgconfig_order','msgconfig_settle','msgconfig_balance','msgconfig_domain','msgconfig_group','msgconfig_risk'],
|
||||
'certificate'=>['cert_open','cert_force','cert_money','cert_channel','cert_aliyunid','cert_aliyunkey','cert_qcloudid','cert_qcloudkey'],
|
||||
'template'=>['template','homepage','footer','ordername','pageordername'],
|
||||
'gonggao'=>['footer','profits_desc','notifyordername'],
|
||||
'mail'=>['mail_smtp','mail_port','mail_user','mail_pwd','mail_name','mail_recv','mail_apikey','sms_api','sms_appid','sms_appkey','sms_sign'],
|
||||
'iptype'=>['ip_type'], 'cron'=>['cronkey','auto_check_channel','auto_check_notify','auto_check_complain','auto_settle_money'], 'proxy'=>['proxy','proxy_server','proxy_port','proxy_user','proxy_pwd','proxy_type','proxy_apiurl','proxy_apikey'],
|
||||
];
|
||||
$modKeys['site'] = array_values(array_unique(array_merge($modKeys['site'], ['captcha_open_test'])));
|
||||
$modKeys['pay'] = array_values(array_unique(array_merge($modKeys['pay'], ['pay_maxmoney','pay_minmoney','blockname','blockalert','pageordername','forceqq','localurl_alipay','localurl_wxpay','wxminipay_path','alipay_paymode','direct_settle_time','alipay_qrcode_url','wxpay_qrcode_url','black_payact','profits_desc','profits_failretry','api_timestamp_check','alipay_web_login','alipay_web_login_all','alipay_mini_login','alipay_wappaylogin','alipay_qrpaylogin','alipay_getmobile','alipay_aes_key','wxpay_qrpaylogin','wxpay_web_login','recharge','reg_pay_uid','onecode','user_refund','refund_fee_type','payfee_lessthan','payfee_mincost','applyments_open','user_profitsharing','invite_open','invite_order_type','invite_rate','invite_order_fee','invite_mode','invite_groupbuy_rate','invite_apply_rate','mchrisk_open','user_deposit','user_deposit_min','user_deposit_day','complain_range','complain_open','complain_freeze_order','complain_auto_reply','complain_auto_reply_repeat','complain_auto_reply_con','complain_auto_black','complain_auto_ipblack','complain_auto_refund','complain_auto_refund_money','wxcombine_open','alicombine_open','wxcombine_minmoney','wxcombine_submoney'])));
|
||||
$modKeys['risk'] = array_values(array_unique(array_merge($modKeys['risk'], ['pay_iplimit','pay_iplimit_white','pay_region_block','pay_verify_check_second','pay_verify_check_count','pay_verify_check_rate','pay_verify_check_ip','pay_verify_check_uid','pay_verify_type','auto_check_channel','check_channel_ids','check_channel_notice','auto_check_sucrate','check_sucrate_notice','auto_check_notify','check_notify_notice','auto_check_complain','check_complain_rate','check_complain_notice','auto_check_payip','auto_check_payspeed','check_paymsg','check_paymsg_notice','check_paymsg_retry','alipay_settle_check','alipay_settle_notice'])));
|
||||
$modKeys['settle'] = array_values(array_unique(array_merge($modKeys['settle'], ['settle_transfermax','auto_settle_money'])));
|
||||
$modKeys['transfer'] = array_values(array_unique(array_merge($modKeys['transfer'], ['transfer_alipay_scene_name','transfer_alipay_info_type','transfer_alipay_info_content','alipay_satf','alipay_satf_fee_type','alipay_satf_fee_account','transfer_wxpay_type','transfer_wxpay_scene_id','transfer_wxpay_info_type','transfer_wxpay_info_content','user_transfer','user_transfer_red'])));
|
||||
$modKeys['oauth'] = array_values(array_unique(array_merge($modKeys['oauth'], ['wx_open_url'])));
|
||||
$modKeys['notice'] = array_values(array_unique(array_merge($modKeys['notice'], ['wxnotice_tpl_order','wxnotice_tpl_order_no','wxnotice_tpl_order_name','wxnotice_tpl_order_money','wxnotice_tpl_order_time','wxnotice_tpl_order_outno','wxnotice_tpl_settle','wxnotice_tpl_settle_type','wxnotice_tpl_settle_account','wxnotice_tpl_settle_money','wxnotice_tpl_settle_realmoney','wxnotice_tpl_settle_time','wxnotice_tpl_login','wxnotice_tpl_login_user','wxnotice_tpl_login_time','wxnotice_tpl_login_name','wxnotice_tpl_login_ip','wxnotice_tpl_login_iploc','wxnotice_tpl_complain','wxnotice_tpl_complain_order_no','wxnotice_tpl_complain_time','wxnotice_tpl_complain_reason','wxnotice_tpl_complain_type','wxnotice_tpl_complain_name','wxnotice_tpl_balance','wxnotice_tpl_balance_user','wxnotice_tpl_balance_time','wxnotice_tpl_balance_money','msgconfig_regaudit','msgconfig_apply','msgconfig_complain_all','msgconfig_mchrisk_all','msgconfig_complain','msgconfig_mchrisk','voicenotice','voice_username','voice_apikey','orderprint','print_appid','print_appsecret'])));
|
||||
$modKeys['certificate'] = array_values(array_unique(array_merge($modKeys['certificate'], ['cert_appcode','cert_aliyunsceneid','cert_antiid','cert_antikey','cert_antisceneid','cert_corpopen','cert_appcode2','ocr_type','ocr_aliyunid','ocr_aliyunkey','ocr_baiduid','ocr_baidukey'])));
|
||||
$modKeys['mail'] = array_values(array_unique(array_merge($modKeys['mail'], ['mail_cloud','mail_apiuser','mail_name2','sms_tpl_reg','sms_tpl_find','sms_tpl_edit','sms_tpl_balance','sms_tpl_group','sms_tpl_complain'])));
|
||||
$modKeys['gonggao'] = ['modal','zhuce','footer'];
|
||||
$options = [
|
||||
'verifytype'=>[['value'=>'0','label'=>'邮箱验证'],['value'=>'1','label'=>'手机验证']], 'reg_open'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开放注册'],['value'=>'2','label'=>'仅邀请注册']], 'user_review'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'reg_pay'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'test_open'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'captcha_open_login'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'close_keylogin'=>[['value'=>'0','label'=>'开启'],['value'=>'1','label'=>'关闭']], 'pay_open'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'pay_verify'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'settle_open'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'settle_transfer'=>[['value'=>'0','label'=>'手动结算'],['value'=>'1','label'=>'自动转账']], 'wxnotice'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'mailnotice'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'robotnotice'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'proxy'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'cert_open'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']], 'cert_force'=>[['value'=>'0','label'=>'关闭'],['value'=>'1','label'=>'开启']],
|
||||
];
|
||||
$fields = [];
|
||||
foreach($modKeys[$mod] ?? $modKeys['site'] as $key){
|
||||
$field = ['key'=>$key,'label'=>$labels[$key] ?? $key,'value'=>(string)($conf[$key] ?? '')];
|
||||
if(isset($options[$key])){ $field['type']='select'; $field['options']=$options[$key]; }
|
||||
elseif($key === 'footer' || strpos($key, 'desc') !== false) $field['type']='textarea';
|
||||
elseif(strpos($key, 'pwd') !== false || strpos($key, 'key') !== false) $field['type']='password';
|
||||
$fields[] = $field;
|
||||
}
|
||||
$uploadNotice = isset($_GET['uploaded']) && $_GET['uploaded'] === '1' ? 'LOGO 上传成功。浏览器可能需要强制刷新才能看到新图片。' : '';
|
||||
if($mod === 'upimg'){
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST'){
|
||||
if(!isset($_POST['csrf_token']) || !isset($_SESSION['admin_csrf_token']) || !hash_equals((string)$_SESSION['admin_csrf_token'], (string)$_POST['csrf_token'])) epay_admin_view('admin-form', ['title'=>'LOGO 上传失败','description'=>'CSRF 校验失败,请刷新页面后重试。','notice'=>'CSRF 校验失败。','action'=>['endpoint'=>'./set.php?mod=upimg','method'=>'POST'],'fields'=>[['key'=>'file','label'=>'首页 LOGO','type'=>'file','accept'=>'image/png,image/jpeg,image/gif,image/webp','required'=>true]]]);
|
||||
$tmp = (string)($_FILES['file']['tmp_name'] ?? '');
|
||||
if($tmp === '' || !is_uploaded_file($tmp)) epay_admin_view('admin-form', ['title'=>'LOGO 上传失败','description'=>'没有收到有效的图片文件。','notice'=>'请选择 PNG、JPEG、GIF 或 WebP 图片。','action'=>['endpoint'=>'./set.php?mod=upimg','method'=>'POST'],'fields'=>[['key'=>'file','label'=>'首页 LOGO','type'=>'file','accept'=>'image/png,image/jpeg,image/gif,image/webp','required'=>true]]]);
|
||||
$allowedTypes = ['image/png','image/jpeg','image/gif','image/webp'];
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = $finfo ? finfo_file($finfo, $tmp) : ''; if($finfo) finfo_close($finfo);
|
||||
if(!in_array($mime, $allowedTypes, true)) epay_admin_view('admin-form', ['title'=>'LOGO 上传失败','description'=>'图片类型不受支持。','notice'=>'仅支持 PNG、JPEG、GIF 或 WebP。','action'=>['endpoint'=>'./set.php?mod=upimg','method'=>'POST'],'fields'=>[['key'=>'file','label'=>'首页 LOGO','type'=>'file','accept'=>'image/png,image/jpeg,image/gif,image/webp','required'=>true]]]);
|
||||
if(!move_uploaded_file($tmp, ROOT.'assets/img/logo.png')) epay_admin_view('admin-form', ['title'=>'LOGO 上传失败','description'=>'服务器无法写入 LOGO 文件。','notice'=>'请检查 assets/img 目录写入权限。','action'=>['endpoint'=>'./set.php?mod=upimg','method'=>'POST'],'fields'=>[['key'=>'file','label'=>'首页 LOGO','type'=>'file','accept'=>'image/png,image/jpeg,image/gif,image/webp','required'=>true]]]);
|
||||
header('Location: ./set.php?mod=upimg&uploaded=1'); exit;
|
||||
}
|
||||
epay_admin_view('admin-form', ['title'=>'首页 LOGO 设置','description'=>'上传后将覆盖 assets/img/logo.png。','notice'=>$uploadNotice,'action'=>['endpoint'=>'./set.php?mod=upimg','method'=>'POST','submitLabel'=>'确认上传'],'fields'=>[['key'=>'file','label'=>'首页 LOGO','type'=>'file','accept'=>'image/png,image/jpeg,image/gif,image/webp','required'=>true]]]);
|
||||
}
|
||||
$links = [];
|
||||
foreach(['site','pay','risk','settle','transfer','oauth','notice','certificate','template','mail','cron','proxy','iptype','upimg','account'] as $key) $links[] = ['label'=>$labels[$key] ?? $key, 'href'=>'./set.php?mod='.$key];
|
||||
if($mod === 'account'){
|
||||
epay_admin_view('admin-account', ['title'=>'管理员账户设置','description'=>'分别更新后台登录凭据和支付密码。','username'=>(string)($conf['admin_user'] ?? ''),'accountEndpoint'=>'./set.php?mod=account_n','payEndpoint'=>'./set.php?mod=paypwd_n','links'=>$links]);
|
||||
}
|
||||
$settingTitle = $labels[$mod] ?? '系统设置';
|
||||
epay_admin_view('admin-form', ['title'=>$settingTitle,'description'=>'使用统一的 shadcn 表单维护 '.$settingTitle.'。','action'=>['endpoint'=>'ajax.php?act=set','method'=>'POST','submitMode'=>'fetch','reloadOnSuccess'=>true,'submitLabel'=>'保存设置'],'fields'=>$fields,'links'=>$links]);
|
||||
@@ -0,0 +1,19 @@
|
||||
/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
|
||||
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){:root,:host{--shimmer-angle:20deg}*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-space-y-reverse:0;--tw-space-x-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-ease:initial;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-content:"";--tw-animation-delay:0s;--tw-animation-direction:normal;--tw-animation-duration:initial;--tw-animation-fill-mode:none;--tw-animation-iteration-count:1;--tw-enter-blur:0;--tw-enter-opacity:1;--tw-enter-rotate:0;--tw-enter-scale:1;--tw-enter-translate-x:0;--tw-enter-translate-y:0;--tw-exit-blur:0;--tw-exit-opacity:1;--tw-exit-rotate:0;--tw-exit-scale:1;--tw-exit-translate-x:0;--tw-exit-translate-y:0;--scroll-fade-t:0px;--scroll-fade-b:0px;--scroll-fade-s:0px;--scroll-fade-e:0px;--scroll-fade-mask:initial;--shimmer-image:initial;--shimmer-text-fill:initial}}}@layer theme{:root,:host{--font-sans:"Geist Variable", sans-serif;--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-xs:20rem;--container-sm:24rem;--container-md:28rem;--container-lg:32rem;--container-xl:36rem;--container-2xl:42rem;--container-3xl:48rem;--container-4xl:56rem;--container-5xl:64rem;--container-6xl:72rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-base:1rem;--text-base--line-height:calc(1.5 / 1);--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75 / 1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2 / 1.5);--text-3xl:1.875rem;--text-3xl--line-height:calc(2.25 / 1.875);--text-4xl:2.25rem;--text-4xl--line-height:calc(2.5 / 2.25);--text-5xl:3rem;--text-5xl--line-height:1;--text-6xl:3.75rem;--text-6xl--line-height:1;--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--tracking-tight:-.025em;--tracking-wide:.025em;--tracking-wider:.05em;--tracking-widest:.1em;--leading-tight:1.25;--leading-snug:1.375;--leading-normal:1.5;--radius-md:calc(var(--radius) * .8);--ease-in-out:cubic-bezier(.4, 0, .2, 1);--animate-spin:spin 1s linear infinite;--animate-pulse:pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;--blur-xs:4px;--blur-xl:24px;--blur-3xl:64px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:"Geist Variable", sans-serif;--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-seLine truncated
|
||||
|
||||
/* ===== epay custom overrides (patch 2026-09-23) ===== */
|
||||
/* 全屏自适应:去掉 1440px 最大宽度限制 */
|
||||
.max-w-\[1440px\]{max-width:none!important}
|
||||
/* 左侧导航栏加宽 256px -> 320px */
|
||||
aside[class*="w-64"]{width:20rem!important}
|
||||
/* 侧栏导航一行显示 2 个菜单(桌面端;分组标题独占整行) */
|
||||
aside nav[aria-label="主导航"]{grid-template-columns:repeat(2,minmax(0,1fr))}
|
||||
aside nav[aria-label="主导航"] > p{grid-column:1 / -1}
|
||||
aside nav[aria-label="主导航"] a{min-width:0}
|
||||
aside nav[aria-label="主导航"] a > span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
aside nav[aria-label="主导航"] a > .ml-auto{display:none}
|
||||
/* 后台窄页面容器放宽 */
|
||||
#epay-react-root[data-epay-view^="admin-"] .max-w-5xl,
|
||||
#epay-react-root[data-epay-view^="admin-"] .max-w-4xl,
|
||||
#epay-react-root[data-epay-view^="admin-"] .max-w-\[1200px\]{max-width:none!important}
|
||||
/* ===== end patch ===== */
|
||||
@@ -0,0 +1,74 @@
|
||||
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var l=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function ee(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function te(e,t){return ee(e.type,t,e.props)}function E(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function ne(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var D=/\/+/g;function re(e,t){return typeof e==`object`&&e&&e.key!=null?ne(``+e.key):t.toString(36)}function O(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function k(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,k(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+re(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(D,`$&/`)+`/`),k(o,r,i,``,function(e){return e})):o!=null&&(E(o)&&(o=te(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(D,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+re(a,u),c+=k(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+re(a,u++),c+=k(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return k(O(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function ie(e,t,n){if(e==null)return e;var r=[],i=0;return k(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ae(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var A=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeLine truncated
|
||||
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
||||
`+ye+e+be}var Se=!1;function Ce(e,t){if(!e||Se)return``;Se=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
||||
`),l=s.split(`
|
||||
`);for(i=r=0;r<c.length&&!c[r].includes(`DetermineComponentFrameRoot`);)r++;for(;i<l.length&&!l[i].includes(`DetermineComponentFrameRoot`);)i++;if(r===c.length||i===l.length)for(r=c.length-1,i=l.length-1;1<=r&&0<=i&&c[r]!==l[i];)i--;for(;1<=r&&0<=i;r--,i--)if(c[r]!==l[i]){if(r!==1||i!==1)do if(r--,i--,0>i||c[r]!==l[i]){var u=`
|
||||
`+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{Se=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?xe(n):``}function we(e,t){switch(e.tag){case 26:case 27:case 5:return xe(e.type);case 16:return xe(`Lazy`);case 13:return e.child!==t&&t!==null?xe(`Suspense Fallback`):xe(`Suspense`);case 19:return xe(`SuspenseList`);case 0:case 15:return Ce(e.type,!1);case 11:return Ce(e.type.render,!1);case 1:return Ce(e.type,!0);case 31:return xe(`Activity`);default:return``}}function Te(e){try{var t=``,n=null;do t+=we(e,n),n=e,e=e.return;while(e);return t}catch(e){return`
|
||||
Error generating stack: `+e.message+`
|
||||
`+e.stack}}var Ee=Object.prototype.hasOwnProperty,De=t.unstable_scheduleCallback,Oe=t.unstable_cancelCallback,ke=t.unstable_shouldYield,Ae=t.unstable_requestPaint,je=t.unstable_now,Me=t.unstable_getCurrentPriorityLevel,Ne=t.unstable_ImmediatePriority,N=t.unstable_UserBlockingPriority,Pe=t.unstable_NormalPriority,Fe=t.unstable_LowPriority,Ie=t.unstable_IdlePriority,Le=t.log,Re=t.unstable_setDisableYieldValue,ze=null,Be=null;function Ve(e){if(typeof Le==`function`&&Re(e),Be&&typeof Be.setStrictMode==`function`)try{Be.setStrictMode(ze,e)}catch{}}var He=Math.clz32?Math.clz32:Ge,Ue=Math.log,We=Math.LN2;function Ge(e){return e>>>=0,e===0?32:31-(Ue(e)/We|0)|0}var Ke=256,qe=262144,Je=4194304;function Ye(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Xe(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Ye(n))):i=Ye(o):i=Ye(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Ye(n))):i=Ye(o)):i=Ye(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Ze(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Qe(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function $e(){var e=Je;return Je<<=1,!(Je&62914560)&&(Je=4194304),e}function et(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function tt(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function nt(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0<n;){var u=31-He(n),d=1<<u;s[u]=0,c[u]=-1;var f=l[u];if(f!==null)for(l[u]=null,u=0;u<f.length;u++){var p=f[u];p!==null&&(p.lane&=-536870913)}n&=~d}r!==0&&rt(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function rt(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-He(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&261930}function it(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-He(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function at(e,t){var n=t&-t;return n=n&42?1:ot(n),(n&(e.suspendedLanes|t))===0?n:0}function ot(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function st(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function ct(){var e=oe.p;return e===0?(e=window.event,e===void 0?32:Tp(e.type)):e}function lt(e,t){var n=oe.p;try{return oe.p=e,t()}finally{oe.p=n}}var ut=Math.random().toString(36).slice(2),dt=`__reactFiber$`+ut,ft=`__reactProps$`+ut,pt=`__reactContainer$`+ut,mt=`__reactEvents$`+ut,ht=`__reactListeners$`+ut,gt=`__reactHandles$`+ut,_t=`__reactResources$`+ut,vt=`__reactMarker$`+ut;function yt(e){delete e[dt],delete e[ft],delete e[mt],delete e[ht],delete e[gt]}function bt(e){var t=e[dt];if(t)return t;for(var n=e.parentNode;n;){if(t=n[pt]||n[dt]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=Sf(e);e!==null;){if(n=e[dt])return n;e=Sf(e)}return t}e=n,n=e.parentNode}return null}function xt(e){if(e=e[dt]||e[pt]){var t=e.tag;if(t===5||t===6||t===13||t===31||t===26||t===27||t===3)return e}return null}function St(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(i(33))}function Ct(e){var t=e[_t];return t||=e[_t]={hoistableStyles:new Map,hoistableScripts:new Map},t}function wt(e){e[vt]=!0}var Tt=new Set,Et={};function Dt(e,t){Ot(e,t),Ot(e+`Capture`,t)}function Ot(e,t){for(Et[e]=t,e=0;e<t.length;e++)Tt.add(t[e])}var kt=RegExp(`^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3Line truncated
|
||||
`).replace(Bd,``)}function Hd(e,t){return t=Vd(t),Vd(e)===t}function Ud(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||Jt(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&Jt(e,``+r);break;case`className`:Pt(e,`class`,r);break;case`tabIndex`:Pt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:Pt(e,n,r);break;case`style`:Zt(e,r,o);break;case`data`:if(t!==`object`){Pt(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)){e.removeAttribute(n);break}if(r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=en(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}if(typeof o==`function`&&(n===`formAction`?(t!==`input`&&Ud(e,t,`name`,a.name,a,null),Ud(e,t,`formEncType`,a.formEncType,a,null),Ud(e,t,`formMethod`,a.formMethod,a,null),Ud(e,t,`formTarget`,a.formTarget,a,null)):(Ud(e,t,`encType`,a.encType,a,null),Ud(e,t,`method`,a.method,a,null),Ud(e,t,`target`,a.target,a,null))),r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=en(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=tn);break;case`onScroll`:r!=null&&kd(`scroll`,e);break;case`onScrollEnd`:r!=null&&kd(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=en(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:kd(`beforetoggle`,e),kd(`toggle`,e),Nt(e,`popover`,r);break;case`xlinkActuate`:P(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:P(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:P(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:P(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:P(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:P(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:P(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:P(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:P(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:Nt(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=I.get(n)||n,Nt(e,n,r))}}function Wd(e,t,n,r,a,o){switch(n){case`style`:Zt(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?Jt(e,r):(typeof r==`number`||typeof r==`bigint`)&&Jt(e,``+r);break;case`onScroll`:r!=null&&kd(`scroll`,e);break;case`onScrollEnd`:r!=null&&kd(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=tn);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref
Line truncated
|
||||
.${Gi} {
|
||||
overflow: hidden ${r};
|
||||
padding-right: ${s}px ${r};
|
||||
}
|
||||
body[${ya}] {
|
||||
overflow: hidden ${r};
|
||||
overscroll-behavior: contain;
|
||||
${[t&&`position: relative ${r};`,n===`margin`&&`
|
||||
padding-left: ${i}px;
|
||||
padding-top: ${a}px;
|
||||
padding-right: ${o}px;
|
||||
margin-left:0;
|
||||
margin-top:0;
|
||||
margin-right: ${s}px ${r};
|
||||
`,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)}
|
||||
}
|
||||
|
||||
.${Ui} {
|
||||
right: ${s}px ${r};
|
||||
}
|
||||
|
||||
.${Wi} {
|
||||
margin-right: ${s}px ${r};
|
||||
}
|
||||
|
||||
.${Ui} .${Ui} {
|
||||
right: 0 ${r};
|
||||
}
|
||||
|
||||
.${Wi} .${Wi} {
|
||||
margin-right: 0 ${r};
|
||||
}
|
||||
|
||||
body[${ya}] {
|
||||
${Ki}: ${s}px;
|
||||
}
|
||||
`},xa=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},Sa=function(){_.useEffect(function(){return document.body.setAttribute(ya,(xa()+1).toString()),function(){var e=xa()-1;e<=0?document.body.removeAttribute(ya):document.body.setAttribute(ya,e.toString())}},[])},Ca=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;Sa();var a=_.useMemo(function(){return _a(i)},[i]);return _.createElement(va,{styles:ba(a,!t,i,n?``:`!important`)})},wa=!1;if(typeof window<`u`)try{var Ta=Object.defineProperty({},"passive",{get:function(){return wa=!0,!0}});window.addEventListener(`test`,Ta,Ta),window.removeEventListener(`test`,Ta,Ta)}catch{wa=!1}var Ea=wa?{passive:!1}:!1,Da=function(e){return e.tagName===`TEXTAREA`},Oa=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!Da(e)&&n[t]===`visible`)},ka=function(e){return Oa(e,`overflowY`)},Aa=function(e){return Oa(e,`overflowX`)},ja=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),Pa(e,r)){var i=Fa(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ma=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},Na=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},Pa=function(e,t){return e===`v`?ka(t):Aa(t)},Fa=function(e,t){return e===`v`?Ma(t):Na(t)},Ia=function(e,t){return e===`h`&&t===`rtl`?-1:1},La=function(e,t,n,r,i){var a=Ia(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=Fa(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&Pa(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},Ra=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},za=function(e){return[e.deltaX,e.deltaY]},Ba=function(e){return e&&`current`in e?e.current:e},Va=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ha=function(e){return`
|
||||
.block-interactivity-${e} {pointer-events: none;}
|
||||
.allow-interactivity-${e} {pointer-events: all;}
|
||||
`},Ua=0,Wa=[];function Ga(e){var t=_.useRef([]),n=_.useRef([0,0]),r=_.useRef(),i=_.useState(Ua++)[0],a=_.useState(pa)[0],o=_.useRef(e);_.useEffect(function(){o.current=e},[e]),_.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Hi([e.lockRef.current],(e.shards||[]).map(Ba),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=_.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=Ra(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=ja(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=ja(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return La(h,t,e,h===`h`?s:c,!0)},[]),c=_.useCallback(function(e){var n=e;if(!(!Wa.length||Wa[Wa.length-1]!==a)){var r=`deltaY`in n?za(n):Ra(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&Va(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(Ba).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=_.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:Ka(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=_.useCallback(function(e){n.current=Ra(e),r.current=void 0},[]),d=_.useCallback(function(t){l(t.type,za(t),t.target,s(t,e.lockRef.current))},[]),f=_.useCallback(function(t){l(t.type,Ra(t),t.target,s(t,e.lockRef.current))},[]);_.useEffect(function(){return Wa.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,Ea),document.addEventListener(`touchmove`,c,Ea),document.addEventListener(`touchstart`,u,Ea),function(){Wa=Wa.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,Ea),document.removeEventListener(`touchmove`,c,Ea),document.removeEventListener(`touchstart`,u,Ea)}},[]);var p=e.removeScrollBar,m=e.inert;return _.createElement(_.Fragment,null,m?_.createElement(a,{styles:Ha(i)}):null,p?_.createElement(Ca,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ka(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var qa=na(ra,Ga),Ja=_.forwardRef(function(e,t){return _.createElement(aa,Bi({},e,{ref:t,sideCar:qa}))});Ja.classNames=aa.classNames;var Ya=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Xa=new WeakMap,Za=new WeakMap,Qa={},$a=0,eo=function(e){return e&&(e.host||eo(e.parentNode))},to=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=eo(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},no=function(e,t,n,r){var i=to(t,Array.isArray(e)?e:[e]);Qa[n]||(Qa[n]=new WeakMap);var a=Qa[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Xa.get(e)||0)+1,l=(a.get(e)||0)+1;Xa.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Za.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),$a++,function(){o.forEach(function(e){var t=Xa.get(e)-1,i=a.get(e)-1;Xa.set(e,t),a.set(e,i),t||(Za.has(e)||e.removeAttribute(r),Za.delete(e)),i||e.removeAttribute(n)}),$a--,$a||(Xa=new WeakMap,Xa=new WeakMap,Za=new WeakMap,Qa={})}},ro=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Ya(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),no(r,i,n,`aria-hidden`)):function(){return null}},io=Object.defineProperty,ao=(e,t)=>io(e,`name`,{value:t,configurable:!0}),oo=`Dialog`,[so,co]=Zn(oo),[lo,uo]=so(oo),H=ao(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=_.useRef(null),c=_.useRef(null),[l,u]=Or({prop:r,defaultProp:i??!1,onChange:a,caller:oo}),[d,f]=_.useState(0),[p,m]=_.useState(0);return(0,R.jsx)(lo,{scope:t,triggerRef:s,contentRef:c,contentId:Kr(),titleId:Kr(),descriptionId:Kr(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:m,open:l,o
Line truncated
|
||||
// ===== epay patch: 桌面侧栏当前菜单自动滚入可见区 =====
|
||||
(function(){
|
||||
function scrollActiveIntoView(){
|
||||
var nav=document.querySelector("aside nav[aria-label=\"主导航\"]");
|
||||
if(!nav) return false;
|
||||
var link=nav.querySelector("a[aria-current=\"page\"]");
|
||||
if(!link) return false;
|
||||
var view=link.parentElement;
|
||||
while(view && view!==document.documentElement){
|
||||
var s=getComputedStyle(view);
|
||||
if(view.scrollHeight>view.clientHeight+4 && (s.overflowY==="auto"||s.overflowY==="scroll"||s.overflowY==="hidden")) break;
|
||||
view=view.parentElement;
|
||||
}
|
||||
if(!view || view===document.documentElement) return true;
|
||||
var lr=link.getBoundingClientRect(), vr=view.getBoundingClientRect();
|
||||
view.scrollTop += (lr.top-vr.top)-(view.clientHeight/2-lr.height/2);
|
||||
return true;
|
||||
}
|
||||
var tries=0;
|
||||
var timer=setInterval(function(){
|
||||
tries++;
|
||||
if(scrollActiveIntoView()||tries>60) clearInterval(timer);
|
||||
},100);
|
||||
})();
|
||||
// ===== end patch =====
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
$nosession = true;
|
||||
require './includes/common.php';
|
||||
$act=isset($_GET['act'])?daddslashes($_GET['act']):null;
|
||||
|
||||
@header('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
if(!checkRefererHost())exit('{"code":403}');
|
||||
|
||||
switch($act){
|
||||
case 'captcha_verify':
|
||||
$pid=$_POST['pid'];
|
||||
$trade_no=$_POST['trade_no'];
|
||||
if(!$pid || !$trade_no)exit(json_encode(['code'=>-1, 'msg'=>'参数不完整']));
|
||||
$captcha_result = verify_captcha4();
|
||||
if($captcha_result !== true){
|
||||
echo json_encode(['code'=>-1, 'msg'=>'验证失败,请重新验证']);
|
||||
exit;
|
||||
}
|
||||
$key = time().getDefendKey($pid, $trade_no).random_int(111111,999999);
|
||||
echo json_encode(['code'=>0, 'key'=>$key]);
|
||||
break;
|
||||
default:
|
||||
$trade_no=isset($_GET['trade_no'])?daddslashes($_GET['trade_no']):exit('{"code":-2,"msg":"No trade_no!"}');
|
||||
|
||||
$row=$DB->getRow("SELECT * FROM pre_order WHERE trade_no=:trade_no limit 1", [':trade_no'=>$trade_no]);
|
||||
|
||||
// 异步回调延迟兜底:微信支付订单未入账时主动向微信查单(插件内10秒节流)
|
||||
if($row && intval($row['status']) < 1 && intval($row['type']) == 2){
|
||||
try{ \lib\Plugin::loadForPay('checkpaid/'.$trade_no.'/'); }catch(Throwable $e){}
|
||||
$row=$DB->getRow("SELECT * FROM pre_order WHERE trade_no=:trade_no limit 1", [':trade_no'=>$trade_no]);
|
||||
}
|
||||
|
||||
if($row['status']>=1){
|
||||
// 支付完成5分钟后禁止跳转回网站
|
||||
if(!empty($row['endtime']) && time() - strtotime($row['endtime']) > 300){
|
||||
$jumpurl = '/payok.html';
|
||||
}else{
|
||||
$url=creat_callback($row);
|
||||
$jumpurl = $url['return'];
|
||||
}
|
||||
if($row['status'] == 2){
|
||||
$jumpurl = '/payerr.html';
|
||||
}
|
||||
echo json_encode(['code'=>1, 'msg'=>'付款成功', 'backurl'=>$jumpurl]);
|
||||
}else{
|
||||
echo json_encode(['code'=>-1, 'msg'=>'未付款']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/** 后台统一 shadcn 应用壳。所有后台入口通过 data-epay-view 交给 React 渲染。 */
|
||||
@header('Content-Type: text/html; charset=UTF-8');
|
||||
if(!isset($_SESSION['admin_csrf_token'])) $_SESSION['admin_csrf_token'] = bin2hex(random_bytes(32));
|
||||
$admin_csrf_token = $_SESSION['admin_csrf_token'];
|
||||
$epay_ui_view = isset($epay_ui_view) ? (string)$epay_ui_view : 'admin-dashboard';
|
||||
$epay_ui_config = isset($epay_ui_config) && is_array($epay_ui_config) ? $epay_ui_config : [];
|
||||
$epay_ui_config['csrf_token'] = $admin_csrf_token;
|
||||
if(!isset($epay_ui_config['title'])) $epay_ui_config['title'] = isset($title) ? $title : '平台运营';
|
||||
if(!isset($epay_ui_config['sitename'])) $epay_ui_config['sitename'] = $conf['sitename'] ?? 'Rainbow Pay';
|
||||
$epay_ui_config['features'] = array_merge([
|
||||
'domain' => (int)($conf['pay_domain_forbid'] ?? 0) === 1 || (int)($conf['pay_domain_open'] ?? 0) === 1,
|
||||
'invitecode' => (int)($conf['reg_open'] ?? 0) === 2,
|
||||
'satf' => class_exists('\\lib\\AlipaySATF\\AlipaySATF') && file_exists(__DIR__.'/satf_transfer.php'),
|
||||
'applyments' => class_exists('\\lib\\Applyments\\CommUtil') && file_exists(__DIR__.'/applyments_channel.php') && file_exists(__DIR__.'/applyments_merchant.php'),
|
||||
'complain' => class_exists('\\lib\\Complain\\CommUtil') && file_exists(__DIR__.'/complain.php'),
|
||||
'mchrisk' => class_exists('\\lib\\WxMchRisk') && file_exists(__DIR__.'/mchrisk.php'),
|
||||
], isset($epay_ui_config['features']) && is_array($epay_ui_config['features']) ? $epay_ui_config['features'] : []);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<title><?php echo htmlspecialchars((string)$epay_ui_config['title'], ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
<link href="../assets/dist/epay-ui.css?v=20261021c" rel="stylesheet" />
|
||||
<script type="module" src="../assets/dist/epay-ui.js?v=20261021c"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="epay-react-root" data-epay-view="<?php echo htmlspecialchars($epay_ui_view, ENT_QUOTES, 'UTF-8'); ?>" data-epay-config="<?php echo htmlspecialchars(json_encode($epay_ui_config, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE), ENT_QUOTES, 'UTF-8'); ?>"></div>
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
$is_defend=true;
|
||||
include("../includes/common.php");
|
||||
if(!$conf['test_open'])sysmsg("未开启测试支付");
|
||||
$csrf_token = '';
|
||||
if(isset($_GET['ok']) && isset($_GET['trade_no'])){
|
||||
$trade_no=is_string($_GET['trade_no'])?trim($_GET['trade_no']):'';
|
||||
$row=$DB->getRow("SELECT * FROM pre_order WHERE trade_no=:trade_no AND uid=:uid limit 1", [':trade_no'=>$trade_no, ':uid'=>(int)$conf['test_pay_uid']]);
|
||||
if(!$row)sysmsg('订单号不存在');
|
||||
if($row['status']!=1)sysmsg('订单未完成支付');
|
||||
$money = $row['money'];
|
||||
}else{
|
||||
$trade_no=date("YmdHis").rand(111,999);
|
||||
$userrow = $DB->getRow("SELECT uid,gid FROM pre_user WHERE uid=:uid limit 1", [':uid'=>(int)$conf['test_pay_uid']]);
|
||||
if(!$userrow)sysmsg("测试支付商户不存在");
|
||||
$paytype = \lib\Channel::getTypes($userrow['uid'], $userrow['gid']);
|
||||
$csrf_token = bin2hex(random_bytes(16));
|
||||
$_SESSION['csrf_token'] = $csrf_token;
|
||||
$money = 1;
|
||||
}
|
||||
$epay_ui_view='test-payment';
|
||||
$epay_ui_config=[
|
||||
'sitename'=>$conf['sitename'],
|
||||
'csrf_token'=>$csrf_token,
|
||||
'trade_no'=>$trade_no,
|
||||
'money'=>$money,
|
||||
'paid'=>isset($_GET['ok']),
|
||||
'captcha'=>(int)$conf['captcha_open_test']===1 && !isset($_GET['ok']),
|
||||
'paytype'=>array_values(array_map(function($channel){
|
||||
return ['id'=>$channel['id'], 'name'=>$channel['name'], 'showname'=>$channel['showname']];
|
||||
}, isset($paytype) && is_array($paytype) ? $paytype : [])),
|
||||
];
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
|
||||
<title><?php echo h($conf['sitename'])?> - 测试支付</title>
|
||||
<link href="<?php echo $cdnpublic?>twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link rel="stylesheet" href="./assets/css/captcha.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../assets/dist/epay-ui.css" type="text/css" />
|
||||
<script type="module" src="../assets/dist/epay-ui.js"></script>
|
||||
<style>.form-group{margin-bottom:18px} #captcha{margin: auto;margin-bottom:16px}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="epay-react-root" data-epay-view="<?php echo htmlspecialchars($epay_ui_view, ENT_QUOTES, 'UTF-8');?>" data-epay-config="<?php echo htmlspecialchars(json_encode($epay_ui_config, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE), ENT_QUOTES, 'UTF-8');?>"></div>
|
||||
<?php if(!$epay_ui_view){?>
|
||||
<div class="container">
|
||||
<div class="col-xs-12 col-sm-10 col-lg-8 center-block" style="float: none;">
|
||||
<div class="page-header">
|
||||
<h4><?php echo h($conf['sitename'])?> - 测试支付<a href="/" class="pull-right"><small>返回首页</small></a></h4>
|
||||
</div>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-body">
|
||||
|
||||
<form name="alipayment">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo h($csrf_token)?>">
|
||||
<div class="form-group"><div class="input-group">
|
||||
<span class="input-group-addon"><span class="glyphicon glyphicon-barcode"></span></span>
|
||||
<input class="form-control" placeholder="商户订单号" value="<?php echo h($trade_no)?>" name="trade_no" type="text" disabled="">
|
||||
</div></div>
|
||||
<div class="form-group"><div class="input-group">
|
||||
<span class="input-group-addon"><span class="glyphicon glyphicon-shopping-cart"></span></span>
|
||||
<input class="form-control" placeholder="商品名称" value="支付测试" name="name" type="text" disabled="" >
|
||||
</div></div>
|
||||
<div class="form-group"><div class="input-group">
|
||||
<span class="input-group-addon"><span class="glyphicon glyphicon-yen"></span></span>
|
||||
<input class="form-control" placeholder="付款金额" value="<?php echo h($money)?>" name="money" type="text" <?php echo isset($_GET['ok'])?'disabled=""':'required=""'?> >
|
||||
</div></div>
|
||||
<center>
|
||||
<?php if(isset($_GET['ok'])){?>
|
||||
<div class="alert alert-success"><i class="glyphicon glyphicon-ok-circle"></i> 订单已支付成功!</div>
|
||||
<?php }else{?>
|
||||
<?php if($conf['captcha_open_test']==1){?>
|
||||
<div class="list-group-item" id="captcha"><div id="captcha_text">
|
||||
正在加载验证码
|
||||
</div>
|
||||
<div id="captcha_wait">
|
||||
<div class="loading">
|
||||
<div class="loading-dot"></div>
|
||||
<div class="loading-dot"></div>
|
||||
<div class="loading-dot"></div>
|
||||
<div class="loading-dot"></div>
|
||||
</div>
|
||||
</div></div>
|
||||
<div id="captchaform"></div>
|
||||
<?php }?>
|
||||
<div class="btn-group btn-group-justified" role="group" aria-label="...">
|
||||
<?php foreach($paytype as $rows){?>
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" name="type" value="<?php echo h($rows['id'])?>" class="btn btn-default" onclick="submitPay(this)"><img src="/assets/icon/<?php echo h($rows['name'])?>.ico" height="18" alt=""> <?php echo h($rows['showname'])?></button>
|
||||
</div>
|
||||
<?php }?>
|
||||
</div>
|
||||
<?php }?>
|
||||
</center>
|
||||
</form>
|
||||
</div>
|
||||
<div class="panel-footer text-center">
|
||||
<?php echo h($conf['sitename'])?> © <?php echo date("Y")?> All Rights Reserved.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php }?>
|
||||
<script src="<?php echo $cdnpublic?>jquery/3.4.1/jquery.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic?>twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic?>layer/3.1.1/layer.js"></script>
|
||||
<script src="//static.geetest.com/static/tools/gt.js"></script>
|
||||
<script>
|
||||
window.appendChildOrg = Element.prototype.appendChild;
|
||||
Element.prototype.appendChild = function() {
|
||||
if(arguments[0].tagName == 'SCRIPT'){
|
||||
arguments[0].setAttribute('referrerpolicy', 'no-referrer');
|
||||
}
|
||||
return window.appendChildOrg.apply(this, arguments);
|
||||
};
|
||||
</script>
|
||||
<script src="//static.geetest.com/v4/gt4.js"></script>
|
||||
<script>
|
||||
var captcha_open = 0;
|
||||
var handlerEmbed = function (captchaObj) {
|
||||
captchaObj.appendTo('#captcha');
|
||||
captchaObj.onReady(function () {
|
||||
$("#captcha_wait").hide();
|
||||
}).onSuccess(function () {
|
||||
var result = captchaObj.getValidate();
|
||||
if (!result) {
|
||||
return alert('请完成验证');
|
||||
}
|
||||
$.captchaResult = result;
|
||||
$.captchaObj = captchaObj;
|
||||
});
|
||||
};
|
||||
function submitPay(obj){
|
||||
var csrf_token=$("input[name='csrf_token']").val();
|
||||
var money=$("input[name='money']").val();
|
||||
var typeid=$(obj).val();
|
||||
if(money==''){
|
||||
layer.alert("金额不能为空");
|
||||
return false;
|
||||
}
|
||||
if(captcha_open == 1 && !$.captchaResult){
|
||||
layer.alert('请先完成滑动验证!'); return false;
|
||||
}
|
||||
var ii = layer.load();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: {money:money, typeid:typeid, csrf_token:csrf_token, ...$.captchaResult},
|
||||
url: "ajax.php?act=testpay",
|
||||
success: function (data, textStatus) {
|
||||
layer.close(ii);
|
||||
if (data.code == 0) {
|
||||
window.location.href=data.url;
|
||||
}else{
|
||||
layer.alert(data.msg, {icon: 2});
|
||||
if($.captchaObj && typeof $.captchaObj.reset === 'function') $.captchaObj.reset();
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
layer.msg('服务器错误', {icon: 2});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
$(document).ready(function(){
|
||||
if($("#captcha").length>0) captcha_open=1;
|
||||
if(captcha_open==1){
|
||||
$.ajax({
|
||||
url: "ajax.php?act=captcha",
|
||||
type: "get",
|
||||
cache: false,
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
$('#captcha_text').hide();
|
||||
$('#captcha_wait').show();
|
||||
if(data.version == 1){
|
||||
initGeetest4({
|
||||
captchaId: data.gt,
|
||||
product: 'popup',
|
||||
protocol: 'https://',
|
||||
riskType: 'ai',
|
||||
hideSuccess: true,
|
||||
nativeButton: {width: '100%'}
|
||||
}, handlerEmbed);
|
||||
}else{
|
||||
initGeetest({
|
||||
gt: data.gt,
|
||||
challenge: data.challenge,
|
||||
new_captcha: data.new_captcha,
|
||||
product: "popup",
|
||||
width: "100%",
|
||||
offline: !data.success,
|
||||
}, handlerEmbed);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
@@ -0,0 +1,81 @@
|
||||
# plugins/ — Payment Channel Plugins
|
||||
|
||||
## OVERVIEW
|
||||
65 payment channel plugins. Each plugin is a self-contained directory with a class file following strict naming conventions. Plugins are dynamically discovered by `\lib\Plugin::loadForSubmit()` and `\lib\Plugin::loadForPay()`. No registry or DB — directory presence is activation.
|
||||
|
||||
## STRUCTURE
|
||||
```
|
||||
plugins/
|
||||
├── {plugin_name}/ # Plugin directory (e.g. alipay, wxpay, stripe, douyinpay)
|
||||
│ ├── {plugin_name}_plugin.php # REQUIRED: Plugin class (e.g. alipay_plugin.php)
|
||||
│ └── inc/
|
||||
│ └── config.php # OPTIONAL: Channel-specific config
|
||||
├── alipay/ # 支付宝 (native)
|
||||
├── alipaycode/ # 支付宝当面付
|
||||
├── alipayd/ # 支付宝当面付 (daifu)
|
||||
├── alipayg/ # 支付宝国际
|
||||
├── alipayhk/ # 支付宝香港
|
||||
├── wxpay/ # 微信支付 (official)
|
||||
├── wxpayn/ # 微信支付 (non-official, NPD)
|
||||
├── wxpaysl/ # 微信支付 (扫呗)
|
||||
├── wxpayng/ # 微信支付 (non-official, NG)
|
||||
├── wxpaynp/ # 微信支付 (non-official, NP)
|
||||
├── qqpay/ # QQ钱包
|
||||
├── unionpay/ # 银联支付
|
||||
├── stripe/ # Stripe (international)
|
||||
├── paypal/ # PayPal
|
||||
├── douyinpay/ # 抖音支付
|
||||
├── jdpay/ # 京东支付
|
||||
├── bepusdt/ # USDT (TRC20)
|
||||
├── xorpay/ # XOR支付
|
||||
├── epay/ / epayn/ # 彩虹易支付(中转代理)
|
||||
├── jeepay/ # Jeepay聚合支付
|
||||
└── ... # 65 total
|
||||
```
|
||||
|
||||
## PLUGIN CONVENTION
|
||||
Each plugin must follow this pattern:
|
||||
|
||||
**File**: `plugins/{name}/{name}_plugin.php`
|
||||
**Class**: `{name}_plugin` (lowercase, underscore suffix)
|
||||
**Optional config**: `plugins/{name}/inc/config.php`
|
||||
|
||||
**Plugin lifecycle hooks** (methods the class should implement):
|
||||
- `submit()` — Called by `loadForSubmit`: returns payment page content
|
||||
- `pay()` — Called by `loadForPay`: handles payment page display
|
||||
- `callback()` — Called on payment gateway callback (async notify)
|
||||
- `return()` — Called on payment gateway return (sync redirect)
|
||||
- `settle()` — Called for settlement/transfer processing
|
||||
- `cron()` — Called by `cron.php` for scheduled tasks
|
||||
|
||||
**Plugin class is loaded via**:
|
||||
```php
|
||||
\lib\Plugin::loadForSubmit($channel_type) // step 1: submit order
|
||||
\lib\Plugin::loadForPay($plugin_id) // step 2: display payment page
|
||||
\lib\Plugin::loadForSettle($channel_type) // settlement
|
||||
```
|
||||
|
||||
## WHERE TO LOOK
|
||||
| Task | Location |
|
||||
|------|----------|
|
||||
| Plugin loader logic | `includes/lib/Plugin.php` |
|
||||
| Channel type definitions | `includes/lib/Channel.php` |
|
||||
| Plugin config in DB | `pre_channel` table |
|
||||
| Payment page fragments | `includes/pages/` |
|
||||
| Example plugin structure | `plugins/alipay/` or `plugins/epay/` |
|
||||
|
||||
## CONVENTIONS
|
||||
- **Directory name = plugin name**: `plugins/alipay/` → class `alipay_plugin`
|
||||
- **One class per plugin**: All logic in `{name}_plugin.php`, no subclasses outside this file
|
||||
- **Config in `inc/config.php`**: Channel-specific settings (app ID, secret, gateway URL) — returns PHP array
|
||||
- **Payment return/callback**: Two URLs — sync return (`return_url`) and async notify (`notify_url`)
|
||||
- **Error handling**: Use `\lib\Payment` helper methods, throw `\Exception` on failure
|
||||
- **Logging**: Write to DB via `$DB`, notify via `\lib\MsgNotice`
|
||||
- **No Composer autoloading for plugins**: Plugin classes are `require`d directly by `Plugin.php`
|
||||
|
||||
## ANTI-PATTERNS
|
||||
- **DON'T modify `Plugin.php` for a single channel**: Plugin loader is generic. Channel-specific logic goes in the plugin class.
|
||||
- **DON'T create subclasses outside `{name}_plugin.php`**: Keep each plugin self-contained in one file.
|
||||
- **DON'T hardcode plugin paths**: Always use `PLUGIN_ROOT` constant.
|
||||
- **DON'T commit API keys/secrets**: Use DB-stored config values, not hardcoded in plugin files.
|
||||
- **DON'T mix plugin and core code**: Plugin files should only be loaded via `Plugin.php`, never `include`d directly by core.
|
||||
@@ -0,0 +1,567 @@
|
||||
<?php
|
||||
|
||||
class adapay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'adapay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => 'AdaPay聚合支付', //支付插件显示名称
|
||||
'author' => 'AdaPay', //支付插件作者
|
||||
'link' => 'https://www.adapay.tech/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '应用App_ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => 'prod模式API_KEY',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户RSA私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '子商户API_KEY',
|
||||
'type' => 'input',
|
||||
'note' => '非进件模式请留空',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
'3' => '托管小程序支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '自有公众号/小程序支付',
|
||||
'2' => '动态二维码支付',
|
||||
'3' => '托管小程序支付',
|
||||
],
|
||||
'select_bank' => [
|
||||
'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(in_array('1',$channel['apptype']) && checkwechat()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
if(in_array('3',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/bank/'.TRADE_NO.'/'];
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/quickpay/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/unionpay/'.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(in_array('1',$channel['apptype']) && $mdevice=='wechat'){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile'){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
if(in_array('3',$channel['apptype'])){
|
||||
return self::bank();
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
return self::quickpay();
|
||||
}else{
|
||||
return self::unionpay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//通用创建订单
|
||||
static private function addOrder($pay_channel, $openid = null){
|
||||
global $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require PAY_ROOT . 'inc/AdapayClient.php';
|
||||
if(!empty($channel['appmchid']))$channel['appkey'] = $channel['appmchid'];
|
||||
$client = new AdapayClient($channel['appkey'], $channel['appsecret'], $channel['appid']);
|
||||
|
||||
$params = [
|
||||
'order_no' => TRADE_NO,
|
||||
'pay_channel' => $pay_channel,
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'goods_title' => $ordername,
|
||||
'goods_desc' => $ordername,
|
||||
'currency' => 'cny',
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
];
|
||||
if ($pay_channel === 'wx_pub' || $pay_channel === 'wx_lite') {
|
||||
$params['expend'] = [
|
||||
'openid' => $openid,
|
||||
];
|
||||
}elseif ($pay_channel === 'alipay_pub' || $pay_channel === 'alipay_lite') {
|
||||
$params['expend'] = [
|
||||
'buyer_id' => $openid,
|
||||
];
|
||||
}
|
||||
if($order['profits'] > 0){
|
||||
$params['pay_mode'] = 'delay';
|
||||
}
|
||||
if($order['profits'] > 0){
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver && $psreceiver['mode'] == 0){
|
||||
$psmoney = round(floor($order['realmoney'] * $psreceiver['rate']) / 100, 2);
|
||||
$psmoney2 = round($order['realmoney']-$psmoney, 2);
|
||||
$div_members = [];
|
||||
$div_members[] = ['member_id'=>$psreceiver['account'], 'amount' => sprintf('%.2f' , $psmoney), 'fee_flag'=>'N'];
|
||||
if($psmoney2 > 0){
|
||||
$div_members[] = ['member_id'=>'0', 'amount' => sprintf('%.2f' , $psmoney2), 'fee_flag'=>'Y'];
|
||||
}else{
|
||||
$div_members[0]['fee_flag'] = 'Y';
|
||||
}
|
||||
$params['div_members'] = $div_members;
|
||||
}
|
||||
}
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->createPayment($params);
|
||||
return $result['expend'];
|
||||
});
|
||||
}
|
||||
|
||||
//跳转支付创建订单
|
||||
static private function pagepay($func_code, $pay_channel){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require PAY_ROOT . 'inc/AdapayClient.php';
|
||||
if(!empty($channel['appmchid']))$channel['appkey'] = $channel['appmchid'];
|
||||
$client = new AdapayClient($channel['appkey'], $channel['appsecret'], $channel['appid']);
|
||||
$params = [
|
||||
'adapay_func_code' => $func_code,
|
||||
'order_no' => TRADE_NO,
|
||||
'pay_channel' => $pay_channel,
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'goods_title' => $ordername,
|
||||
'goods_desc' => $ordername,
|
||||
'currency' => 'cny',
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'callback_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$params['pay_mode'] = 'delay';
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->queryAdapay($params);
|
||||
return $result['expend'];
|
||||
});
|
||||
}
|
||||
|
||||
//收银台创建订单
|
||||
static private function checkout($pay_channel, $member_id = null){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require PAY_ROOT . 'inc/AdapayClient.php';
|
||||
if(!empty($channel['appmchid']))$channel['appkey'] = $channel['appmchid'];
|
||||
$client = new AdapayClient($channel['appkey'], $channel['appsecret'], $channel['appid']);
|
||||
$params = [
|
||||
'adapay_func_code' => 'checkout',
|
||||
'order_no' => TRADE_NO,
|
||||
'pay_channel' => $pay_channel,
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'goods_title' => $ordername,
|
||||
'goods_desc' => $ordername,
|
||||
'currency' => 'cny',
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'callback_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if($member_id){
|
||||
$params['member_id'] = $member_id;
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->queryAdapay($params);
|
||||
return $result['expend'];
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype']) || empty($channel['apptype'][0])){
|
||||
try{
|
||||
$result = self::addOrder('alipay_qr');
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$code_url = $result['qrcode_url'];
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
try{
|
||||
$result = self::pagepay('prePay.preOrder', 'alipay_lite');
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$code_url = $result['ali_h5_pay_url'];
|
||||
if(checkalipay() || $mdevice=='alipay'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}elseif(checkmobile() || $device=='mobile'){
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>'data.backurl']];
|
||||
}
|
||||
}
|
||||
|
||||
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 $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_pub', $user_id);
|
||||
$payinfo = json_decode($result['pay_info'], true);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
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 $siteurl, $channel, $device, $mdevice;
|
||||
|
||||
if(in_array('2',$channel['apptype'])){
|
||||
try{
|
||||
$result = self::pagepay('qrPrePay.qrPreOrder', '');
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$code_url = $result['qr_pay_url'];
|
||||
}elseif(in_array('3',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
//①、获取用户openid
|
||||
if(!empty($order['sub_openid'])){
|
||||
$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($order['is_applet'] == 1 ? 'wx_lite' : 'wx_pub', $openid);
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
$jsApiParameters = $result['pay_info'];
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$jsApiParameters];
|
||||
}
|
||||
|
||||
if($_GET['d']==1){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$jsApiParameters, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if($channel['appwxa']>0 && in_array('1',$channel['apptype'])){
|
||||
$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(in_array('3',$channel['apptype'])){ //托管小程序支付
|
||||
try{
|
||||
$result = self::pagepay('wxpay.createOrder', 'wx_lite');
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$code_url = $result['scheme_code'];
|
||||
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$code_url];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}
|
||||
|
||||
//微信小程序支付
|
||||
static public function wxminipay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$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('wx_lite', $openid);
|
||||
}catch (Exception $e) {
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$e->getMessage().'"}');
|
||||
}
|
||||
|
||||
$jsApiParameters = $result['pay_info'];
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($jsApiParameters, true)]));
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function unionpay(){
|
||||
try{
|
||||
$result = self::addOrder('union_qr');
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
$code_url = $result['qrcode_url'];
|
||||
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//快捷支付
|
||||
static public function quickpay(){
|
||||
if(!empty($_COOKIE['adapay_user_id'])){
|
||||
$user_id = $_COOKIE['adapay_user_id'];
|
||||
}else{
|
||||
$user_id = substr(getSid(), 0, 10);
|
||||
setcookie('adapay_user_id', $user_id, time()+3600*24*365, '/', '', true, true);
|
||||
}
|
||||
try{
|
||||
$result = self::checkout('fast_pay', $user_id);
|
||||
$code_url = $result['pay_url'];
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'快捷支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}
|
||||
|
||||
//网银支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$result = self::checkout('online_pay');
|
||||
$code_url = $result['pay_url'];
|
||||
}catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'网银支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
//file_put_contents('logs.txt',http_build_query($_POST));
|
||||
if(!isset($_POST['sign']) || !isset($_POST['data'])){
|
||||
return ['type'=>'html','data'=>'No'];
|
||||
}
|
||||
|
||||
require PAY_ROOT . 'inc/AdapayClient.php';
|
||||
if(!empty($channel['appmchid']))$channel['appkey'] = $channel['appmchid'];
|
||||
$client = new AdapayClient($channel['appkey'], $channel['appsecret'], $channel['appid']);
|
||||
if ($client->verifySign($_POST['sign'] , $_POST['data'])) {
|
||||
$_data = json_decode($_POST['data'] , true);
|
||||
if ($_data['status'] == 'succeeded') {
|
||||
$api_trade_no = $_data['id'];
|
||||
$trade_no = $_data['order_no'];
|
||||
$orderAmount = $_data['pay_amt'];
|
||||
$buyer = $_data['expend']['sub_open_id'];
|
||||
$bill_trade_no = $_data['out_trans_id'];
|
||||
$bill_mch_trade_no = $_data['party_order_id'];
|
||||
if ($trade_no == TRADE_NO) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'Ok'];
|
||||
} else {
|
||||
return ['type'=>'html','data'=>'No'];
|
||||
}
|
||||
} else {
|
||||
return ['type'=>'html','data'=>'No'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
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 PAY_ROOT . 'inc/AdapayClient.php';
|
||||
if(!empty($channel['appmchid']))$channel['appkey'] = $channel['appmchid'];
|
||||
$client = new AdapayClient($channel['appkey'], $channel['appsecret'], $channel['appid']);
|
||||
$params = [
|
||||
'payment_id' => $order['api_trade_no'],
|
||||
'refund_order_no' => $order['refund_no'],
|
||||
'refund_amt' => $order['refundmoney']
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$psorder = \lib\ProfitSharing\CommUtil::getOrder($order['trade_no']);
|
||||
if($psorder && ($psorder['status'] == 1 || $psorder['status'] == 2)){
|
||||
$div_members = [];
|
||||
if($psorder['rdata']){
|
||||
$allmoney = 0;
|
||||
$leftmoney = (float)$order['refundmoney'];
|
||||
foreach($psorder['rdata'] as $receiver){
|
||||
$money = $receiver['money'] > $leftmoney ? $leftmoney : $receiver['money'];
|
||||
$div_members[] = ['member_id'=>$receiver['account'], 'amount' => sprintf('%.2f' , $money)];
|
||||
$allmoney += $receiver['money'];
|
||||
$leftmoney = round($leftmoney - $money, 2);
|
||||
if($leftmoney <= 0) break;
|
||||
}
|
||||
if($order['refundmoney'] > $allmoney && $leftmoney > 0){
|
||||
$psmoney2 = round($order['refundmoney']-$allmoney, 2);
|
||||
$psmoney2 = $psmoney2 > $leftmoney ? $leftmoney : $psmoney2;
|
||||
$div_members[] = ['member_id'=>'0', 'amount' => sprintf('%.2f' , $psmoney2)];
|
||||
}
|
||||
}else{
|
||||
$amount = $psorder['money'] > $order['refundmoney'] ? $order['refundmoney'] : $psorder['money'];
|
||||
$div_members[] = [
|
||||
'member_id' => $psorder['account'],
|
||||
'amount' => sprintf('%.2f' , $amount),
|
||||
];
|
||||
if($order['refundmoney'] > $psorder['money']){
|
||||
$amount = round($order['refundmoney'] - $psorder['money'], 2);
|
||||
$div_members[] = [
|
||||
'member_id' => '0',
|
||||
'amount' => sprintf('%.2f' , $amount),
|
||||
];
|
||||
}
|
||||
}
|
||||
$params['payment_id'] = $psorder['settle_no'];
|
||||
$params['div_members'] = $div_members;
|
||||
}else{
|
||||
$params = [
|
||||
'payment_id' => $order['api_trade_no'],
|
||||
'order_no' => $order['refund_no'],
|
||||
'reverse_amt' => $order['refundmoney']
|
||||
];
|
||||
try{
|
||||
$res = $client->createPaymentReverse($params);
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
if($res['status']=='succeeded'||$res['status']=='pending'){
|
||||
$result = ['code'=>0, 'trade_no'=>$res['id']];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>'['.$res["error_code"].']'.$res["error_msg"]];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
try{
|
||||
$res = $client->createRefund($params);
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
if($res['status']=='succeeded'||$res['status']=='pending'){
|
||||
$result = ['code'=>0, 'trade_no'=>$res['id'], 'refund_fee'=>$res['refund_amt']];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>'['.$res["error_code"].']'.$res["error_msg"]];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://doc.adapay.tech/document/api/#/
|
||||
*/
|
||||
class AdapayClient
|
||||
{
|
||||
const SDK_VERSION = 'v1.0.0';
|
||||
private $gateWayUrl = 'https://api.adapay.tech'; //网关地址
|
||||
private $rsaPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
|
||||
private $api_key;
|
||||
private $rsaPrivateKey;
|
||||
private $app_id;
|
||||
|
||||
public function __construct($api_key_live, $rsa_private_key, $app_id = null)
|
||||
{
|
||||
$this->api_key = $api_key_live;
|
||||
$this->rsaPrivateKey = $rsa_private_key;
|
||||
$this->app_id = $app_id;
|
||||
}
|
||||
|
||||
public function request($method, $endpoint, $params = null, $json = true)
|
||||
{
|
||||
$req_url = $this->gateWayUrl . $endpoint;
|
||||
$headers = [];
|
||||
$postData = '';
|
||||
if($method == 'GET'){
|
||||
$signstr = '';
|
||||
if($params){
|
||||
ksort($params);
|
||||
$req_url .= '?' . http_build_query($params);
|
||||
$signstr = http_build_query($params);
|
||||
}
|
||||
}elseif($json){
|
||||
$postData = json_encode($params);
|
||||
$signstr = $postData;
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
}else{
|
||||
$postData = $params;
|
||||
if(is_array($postData)){
|
||||
$signstr = $this->createLinkstring($postData);
|
||||
}else{
|
||||
$signstr = $postData;
|
||||
}
|
||||
}
|
||||
$headers[] = 'Authorization: ' . $this->api_key;
|
||||
$headers[] = 'Signature: ' . $this->generateSignature($endpoint , $signstr);
|
||||
$headers[] = 'sdk_version: ' . self::SDK_VERSION;
|
||||
|
||||
$response = get_curl($req_url, $postData, 0, 0, 0, 0, 0, $headers);
|
||||
|
||||
if (!$response || !($result = json_decode($response , true))) {
|
||||
throw new Exception('返回内容为空或解析失败');
|
||||
}
|
||||
if(!isset($result['data']) && isset($result['message'])){
|
||||
throw new Exception($result['message']);
|
||||
}
|
||||
$data = json_decode($result['data'], true);
|
||||
|
||||
if ($data['status'] !== 'succeeded' && $data['status'] !== 'pending' && empty($data['expend'])) {
|
||||
throw new Exception('['.$data['error_code'].']'.$data['error_msg']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
//创建支付对象
|
||||
public function createPayment($params)
|
||||
{
|
||||
$endpoint = '/v1/payments';
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//通用请求
|
||||
public function queryAdapay($params)
|
||||
{
|
||||
$this->gateWayUrl = "https://page.adapay.tech";
|
||||
$adapayFuncCode = $params["adapay_func_code"];
|
||||
$endpoint = '/v1/'.str_replace(".", "/",$adapayFuncCode);
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//通用请求
|
||||
public function requestAdapay($params)
|
||||
{
|
||||
$adapayFuncCode = $params["adapay_func_code"];
|
||||
$endpoint = '/v1/'.str_replace(".", "/",$adapayFuncCode);
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付对象
|
||||
public function queryPayment($id)
|
||||
{
|
||||
$endpoint = '/v1/payments/'.$id;
|
||||
return $this->request('GET', $endpoint, null);
|
||||
}
|
||||
|
||||
//创建退款对象
|
||||
public function createRefund($params){
|
||||
$charge_id = isset($params['payment_id']) ? $params['payment_id'] : '';
|
||||
$endpoint = '/v1/payments/'.$charge_id.'/refunds';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询退款对象
|
||||
public function queryRefund($params){
|
||||
$endpoint = '/v1/payments/refunds';
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建用户对象
|
||||
public function createMember($member_id){
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id,
|
||||
];
|
||||
$endpoint = '/v1/members';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建结算账户对象
|
||||
public function createSettleAccount($member_id, $account_info){
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id,
|
||||
'channel' => 'bank_account',
|
||||
'account_info' => $account_info
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询结算账户对象
|
||||
public function querySettleAccount($member_id, $settle_account_id){
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id,
|
||||
'settle_account_id' => $settle_account_id
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts/'.$settle_account_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//删除结算账户对象
|
||||
public function deleteSettleAccount($member_id, $settle_account_id){
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id,
|
||||
'settle_account_id' => $settle_account_id
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts/delete';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建支付确认对象
|
||||
public function createPaymentConfirm($params){
|
||||
$endpoint = '/v1/payments/confirm';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付确认对象
|
||||
public function queryPaymentConfirm($payment_confirm_id){
|
||||
$params = [
|
||||
'payment_confirm_id' => $payment_confirm_id
|
||||
];
|
||||
$endpoint = '/v1/payments/confirm/'.$payment_confirm_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建支付撤销对象
|
||||
public function createPaymentReverse($params){
|
||||
$endpoint = '/v1/payments/reverse';
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付确认对象
|
||||
public function queryPaymentReverse($reverse_id){
|
||||
$params = [
|
||||
'reverse_id' => $reverse_id
|
||||
];
|
||||
$endpoint = '/v1/payments/reverse/'.$reverse_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建取现对象
|
||||
public function createDrawCash($params){
|
||||
$endpoint = '/v1/cashs';
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询取现对象
|
||||
public function queryDrawCash($order_no){
|
||||
$endpoint = '/v1/cashs/stat';
|
||||
$params = [
|
||||
'order_no' => $order_no,
|
||||
];
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询账户余额
|
||||
public function queryBalance($member_id, $settle_account_id = null){
|
||||
$endpoint = '/v1/settle_accounts/balance';
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id
|
||||
];
|
||||
if($settle_account_id){
|
||||
$params['settle_account_id'] = $settle_account_id;
|
||||
}
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//钱包登录
|
||||
public function walletLogin($member_id, $ip){
|
||||
$endpoint = '/v1/walletLogin';
|
||||
$params = [
|
||||
'app_id' => $this->app_id,
|
||||
'member_id' => $member_id,
|
||||
'ip' => $ip
|
||||
];
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//账户转账
|
||||
public function createTransfer($params){
|
||||
$endpoint = '/v1/settle_accounts/transfer';
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//账户转账查询
|
||||
public function queryTransfer($params){
|
||||
$endpoint = '/v1/settle_accounts/transfer/list';
|
||||
$public_params = [
|
||||
'app_id' => $this->app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
private function generateSignature($endpoint , $postData):string
|
||||
{
|
||||
$data = $this->gateWayUrl . $endpoint . $postData;
|
||||
$sign = $this->SHA1withRSA($data);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
private function createLinkstring($params)
|
||||
{
|
||||
ksort($params);
|
||||
$arg = "";
|
||||
foreach ($params as $key => $val){
|
||||
if($val instanceof \CURLFile || $val === '' || $val === null) continue;
|
||||
$arg .= $key . "=" . $val . "&";
|
||||
}
|
||||
$arg = substr($arg, 0, -1);
|
||||
return $arg;
|
||||
}
|
||||
|
||||
private function SHA1withRSA($data)
|
||||
{
|
||||
$privKey = trim($this->rsaPrivateKey);
|
||||
$key = "-----BEGIN PRIVATE KEY-----\n" . wordwrap($privKey, 64, "\n", true) . "\n-----END PRIVATE KEY-----";
|
||||
$keyid = openssl_pkey_get_private($key);
|
||||
if(!$keyid){
|
||||
throw new \Exception('签名失败,商户私钥不正确');
|
||||
}
|
||||
openssl_sign($data , $signature , $keyid , OPENSSL_ALGO_SHA1);
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
public function verifySign($signature , $data)
|
||||
{
|
||||
$pubKey = trim($this->rsaPublicKey);
|
||||
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($pubKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
|
||||
$keyid = openssl_pkey_get_public($key);
|
||||
if(!$keyid){
|
||||
throw new \Exception('验签失败,AdaPay公钥不正确');
|
||||
}
|
||||
$result = openssl_verify($data , base64_decode($signature) , $keyid , OPENSSL_ALGO_SHA1);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
public function getPublicKey()
|
||||
{
|
||||
$privKey = trim($this->rsaPrivateKey);
|
||||
$key = "-----BEGIN PRIVATE KEY-----\n" . wordwrap($privKey, 64, "\n", true) . "\n-----END PRIVATE KEY-----";
|
||||
$keyid = openssl_pkey_get_private($key);
|
||||
if(!$keyid){
|
||||
throw new \Exception('商户私钥不正确');
|
||||
}
|
||||
$details = openssl_pkey_get_details($keyid);
|
||||
return pemToBase64($details['key']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
Class AdaTools
|
||||
{
|
||||
public $rsaPrivateKeyFilePath;
|
||||
public $rsaPublicKeyFilePath;
|
||||
public $rsaPrivateKey;
|
||||
public $rsaPublicKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function generateSignature($url , $params = []):string
|
||||
{
|
||||
$data = '';
|
||||
if (is_array($params)) {
|
||||
$data .= $url . json_encode($params);
|
||||
} else {
|
||||
$data .= $url . $params;
|
||||
}
|
||||
$sign = $this->SHA1withRSA($data);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
public function SHA1withRSA($data)
|
||||
{
|
||||
if ($this->checkEmpty($this->rsaPrivateKeyFilePath)) {
|
||||
$privKey = trim($this->rsaPrivateKey);
|
||||
$key = "-----BEGIN PRIVATE KEY-----\n" . wordwrap($privKey, 64, "\n", true) . "\n-----END PRIVATE KEY-----";
|
||||
} else {
|
||||
$privKey = file_get_contents($this->rsaPrivateKeyFilePath);
|
||||
$key = openssl_get_privatekey($privKey);
|
||||
}
|
||||
openssl_sign($data , $signature , $key , OPENSSL_ALGO_SHA1);
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
public function verifySign($signature , $data)
|
||||
{
|
||||
if ($this->checkEmpty($this->rsaPublicKeyFilePath)) {
|
||||
$pubKey = trim($this->rsaPublicKey);
|
||||
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($pubKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
|
||||
} else {
|
||||
$pubKey = file_get_contents($this->rsaPublicKeyFilePath);
|
||||
$key = openssl_get_publickey($pubKey);
|
||||
}
|
||||
if (openssl_verify($data , base64_decode($signature) , $key , OPENSSL_ALGO_SHA1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkEmpty($value)
|
||||
{
|
||||
if (!isset($value) || ('' === trim($value)) || is_null($value)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
class AdaPay
|
||||
{
|
||||
const SDK_VERSION = 'v1.0.0';
|
||||
static $gateWayUrl = 'https://api.adapay.tech'; //网关地址
|
||||
static $header = ['Content-Type:application/json'];
|
||||
static $headerText = ['Content-Type:text/html'];
|
||||
static $rsaPrivateKey;
|
||||
static $rsaPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
|
||||
static $signType = 'RSA2';
|
||||
static $app_id;
|
||||
static $api_key;
|
||||
public $ada_tools;
|
||||
|
||||
public function __construct($config_info)
|
||||
{
|
||||
if (empty($config_info) || !is_array($config_info)) {
|
||||
throw new \Exception('缺少SDK配置信息');
|
||||
}
|
||||
if (empty($config_info['app_id'])) {
|
||||
throw new \Exception('应用AppID不能为空');
|
||||
}
|
||||
if (empty($config_info['api_key_live'])) {
|
||||
throw new \Exception('API_KEY不能为空');
|
||||
}
|
||||
if (empty($config_info['rsa_private_key'])) {
|
||||
throw new \Exception('商户RSA私钥不能为空');
|
||||
}
|
||||
|
||||
$sdk_version = self::SDK_VERSION;
|
||||
array_push(self::$header , "sdk_version:{$sdk_version}");
|
||||
array_push(self::$headerText , "sdk_version:{$sdk_version}");
|
||||
|
||||
self::$app_id = trim($config_info['app_id']);
|
||||
self::$api_key = trim($config_info['api_key_live']);
|
||||
self::$rsaPrivateKey = trim($config_info['rsa_private_key']);
|
||||
|
||||
$this->ada_tools = new AdaTools();
|
||||
$this->ada_tools->rsaPrivateKey = self::$rsaPrivateKey;
|
||||
$this->ada_tools->rsaPublicKey = self::$rsaPublicKey;
|
||||
}
|
||||
|
||||
static function config($config = [])
|
||||
{
|
||||
return new static($config);
|
||||
}
|
||||
|
||||
private function get_headers($req_url , $postData , array $header = [])
|
||||
{
|
||||
array_push($header , 'Authorization:' . self::$api_key);
|
||||
array_push($header , 'Signature:' . $this->ada_tools->generateSignature($req_url , $postData));
|
||||
return $header;
|
||||
}
|
||||
|
||||
private function request($method, $endpoint, $params = null)
|
||||
{
|
||||
$req_url = self::$gateWayUrl . $endpoint;
|
||||
if($method == 'GET'){
|
||||
if($params){
|
||||
ksort($params);
|
||||
$headers = $this->get_headers($req_url , http_build_query($params) , self::$headerText);
|
||||
$req_url .= '?' . http_build_query($params);
|
||||
}else{
|
||||
$headers = $this->get_headers($req_url , "" , self::$headerText);
|
||||
}
|
||||
$response = $this->curl($req_url , null , $headers);
|
||||
}else{
|
||||
$headers = $this->get_headers($req_url , $params , self::$header);
|
||||
$response = $this->curl($req_url , $params , $headers);
|
||||
}
|
||||
|
||||
if (!$response || !($result = json_decode($response , true))) {
|
||||
throw new Exception('返回内容为空或解析失败');
|
||||
}
|
||||
if(!isset($result['data']) && isset($result['message'])){
|
||||
throw new Exception($result['message']);
|
||||
}
|
||||
$data = json_decode($result['data'], true);
|
||||
|
||||
if ($data['status'] !== 'succeeded' && $data['status'] !== 'pending' && empty($data['expend'])) {
|
||||
throw new Exception('['.$data['error_code'].']'.$data['error_msg']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//创建支付对象
|
||||
public function createPayment($params)
|
||||
{
|
||||
$endpoint = '/v1/payments';
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
'sign_type' => self::$signType,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//通用请求
|
||||
public function queryAdapay($params)
|
||||
{
|
||||
self::$gateWayUrl = "https://page.adapay.tech";
|
||||
$adapayFuncCode = $params["adapay_func_code"];
|
||||
$endpoint = '/v1/'.str_replace(".", "/",$adapayFuncCode);
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//通用请求
|
||||
public function requestAdapay($params)
|
||||
{
|
||||
$adapayFuncCode = $params["adapay_func_code"];
|
||||
$endpoint = '/v1/'.str_replace(".", "/",$adapayFuncCode);
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付对象
|
||||
public function queryPayment($id)
|
||||
{
|
||||
$endpoint = '/v1/payments/'.$id;
|
||||
return $this->request('GET', $endpoint, null);
|
||||
}
|
||||
|
||||
//创建退款对象
|
||||
public function createRefund($params){
|
||||
$charge_id = isset($params['payment_id']) ? $params['payment_id'] : '';
|
||||
$endpoint = '/v1/payments/'.$charge_id.'/refunds';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询退款对象
|
||||
public function queryRefund($params){
|
||||
$endpoint = '/v1/payments/refunds';
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建用户对象
|
||||
public function createMember($member_id){
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id,
|
||||
];
|
||||
$endpoint = '/v1/members';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建结算账户对象
|
||||
public function createSettleAccount($member_id, $account_info){
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id,
|
||||
'channel' => 'bank_account',
|
||||
'account_info' => $account_info
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询结算账户对象
|
||||
public function querySettleAccount($member_id, $settle_account_id){
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id,
|
||||
'settle_account_id' => $settle_account_id
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts/'.$settle_account_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//删除结算账户对象
|
||||
public function deleteSettleAccount($member_id, $settle_account_id){
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id,
|
||||
'settle_account_id' => $settle_account_id
|
||||
];
|
||||
$endpoint = '/v1/settle_accounts/delete';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建支付确认对象
|
||||
public function createPaymentConfirm($params){
|
||||
$endpoint = '/v1/payments/confirm';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付确认对象
|
||||
public function queryPaymentConfirm($payment_confirm_id){
|
||||
$params = [
|
||||
'payment_confirm_id' => $payment_confirm_id
|
||||
];
|
||||
$endpoint = '/v1/payments/confirm/'.$payment_confirm_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建支付撤销对象
|
||||
public function createPaymentReverse($params){
|
||||
$endpoint = '/v1/payments/reverse';
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询支付确认对象
|
||||
public function queryPaymentReverse($reverse_id){
|
||||
$params = [
|
||||
'reverse_id' => $reverse_id
|
||||
];
|
||||
$endpoint = '/v1/payments/reverse/'.$reverse_id;
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//创建取现对象
|
||||
public function createDrawCash($params){
|
||||
$endpoint = '/v1/cashs';
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询取现对象
|
||||
public function queryDrawCash($order_no){
|
||||
$endpoint = '/v1/cashs/stat';
|
||||
$params = [
|
||||
'order_no' => $order_no,
|
||||
];
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//查询账户余额
|
||||
public function queryBalance($member_id, $settle_account_id = null){
|
||||
$endpoint = '/v1/settle_accounts/balance';
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id
|
||||
];
|
||||
if($settle_account_id){
|
||||
$params['settle_account_id'] = $settle_account_id;
|
||||
}
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//钱包登录
|
||||
public function walletLogin($member_id, $ip){
|
||||
$endpoint = '/v1/walletLogin';
|
||||
$params = [
|
||||
'app_id' => self::$app_id,
|
||||
'member_id' => $member_id,
|
||||
'ip' => $ip
|
||||
];
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
//账户转账
|
||||
public function createTransfer($params){
|
||||
$endpoint = '/v1/settle_accounts/transfer';
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
];
|
||||
$params = array_merge($params, $public_params);
|
||||
return $this->request('POST', $endpoint, $params);
|
||||
}
|
||||
|
||||
//账户转账查询
|
||||
public function queryTransfer($params){
|
||||
$endpoint = '/v1/settle_accounts/transfer/list';
|
||||
$public_params = [
|
||||
'app_id' => self::$app_id,
|
||||
];
|
||||
$params = array_merge($public_params, $params);
|
||||
return $this->request('GET', $endpoint, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param null $post
|
||||
* @param null $cookie
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function curl($url, $post = null, array $headers = [])
|
||||
{
|
||||
$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_TIMEOUT, 10);
|
||||
if (!is_null($post)) {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if (is_array($post)) {
|
||||
$postData = json_encode($post);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
return [
|
||||
'app_id' => trim($channel['appid']),
|
||||
'api_key_live' => trim($channel['appkey']),
|
||||
'rsa_private_key' => trim($channel['appsecret']),
|
||||
];
|
||||
?>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//应用ID
|
||||
'app_id' => $channel['appid'],
|
||||
|
||||
//支付宝公钥
|
||||
'alipay_public_key' => $channel['appkey'],
|
||||
|
||||
//应用私钥
|
||||
'app_private_key' => $channel['appsecret'],
|
||||
|
||||
//签名方式,默认为RSA2
|
||||
'sign_type' => "RSA2",
|
||||
|
||||
//编码格式
|
||||
'charset' => "UTF-8",
|
||||
|
||||
//支付宝网关
|
||||
'gateway_url' => "https://openapi.alipay.com/gateway.do",
|
||||
|
||||
//日志记录位置
|
||||
'log_path' => dirname(__FILE__).'/log/',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayRootCert.crt';
|
||||
}
|
||||
elseif(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayRootCert.crt';
|
||||
}
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
class alipaycode_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'alipaycode', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '支付宝免签约码支付', //支付插件显示名称
|
||||
'author' => '支付宝', //支付插件作者
|
||||
'link' => 'https://open.alipay.com/', //支付插件作者链接
|
||||
'types' => ['alipay'], //支付插件支持的支付方式,可选的有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' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '支付宝UID',
|
||||
'type' => 'input',
|
||||
'note' => '2088开头的16位纯数字',
|
||||
],
|
||||
'apptoken' => [
|
||||
'name' => '商户授权token',
|
||||
'type' => 'input',
|
||||
'note' => '只有第三方应用需要填写,非第三方应用必须留空',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '支付类型',
|
||||
'type' => 'select',
|
||||
'options' => [0 => '普通转账', 1 => '转账确认单'],
|
||||
],
|
||||
],
|
||||
'note' => '<p>可不签约支付产品,支付宝开放平台应用需要已上线,不能开启余额宝自动转入。如果是第三方应用类型,还需要填写商户授权token。</p><p>需添加守护进程,运行目录:<u>[basedir]plugins/alipaycode/</u> 启动命令:<u>php server.php [channel]</u> </p>', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static public function qrcode(){
|
||||
global $siteurl, $cdnpublic, $order, $conf;
|
||||
|
||||
$code_url = $siteurl.'pay/pay/'.TRADE_NO.'/';
|
||||
|
||||
$paytime = strtotime($order['addtime']) + 300 - time();
|
||||
|
||||
if(!empty($conf['alipay_qrcode_url'])){
|
||||
$code_url = $conf['alipay_qrcode_url'].'pay/pay/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
include PAY_ROOT.'inc/qrcode.page.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function pay()
|
||||
{
|
||||
global $siteurl, $order, $channel, $conf;
|
||||
|
||||
if($conf['alipay_wappaylogin']==1){
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
}
|
||||
|
||||
if($channel['appswitch'] == 1){
|
||||
$params = [
|
||||
'productCode' => 'TRANSFER_TO_ALIPAY_ACCOUNT',
|
||||
'bizScene' => 'YUEBAO',
|
||||
'transAmount' => $order['realmoney'],
|
||||
'remark' => $order['trade_no'],
|
||||
'businessParams' => [
|
||||
'returnUrl' => 'alipays://platformapi/startapp?appId=2021001167654035&nbupdate=syncforce',
|
||||
],
|
||||
'payeeInfo' => [
|
||||
'identity' => $channel['appmchid'],
|
||||
'identityType' => 'ALIPAY_USER_ID',
|
||||
],
|
||||
];
|
||||
$url = 'https://render.alipay.com/p/yuyan/180020010001206672/rent-index.html?formData='.rawurlencode(json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
header("Location: $url");
|
||||
exit;
|
||||
}
|
||||
|
||||
include PAY_ROOT.'inc/pay.page.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//应用ID
|
||||
'app_id' => $channel['appid'],
|
||||
|
||||
//支付宝公钥
|
||||
'alipay_public_key' => $channel['appkey'],
|
||||
|
||||
//应用私钥
|
||||
'app_private_key' => $channel['appsecret'],
|
||||
|
||||
//商户授权token
|
||||
'app_auth_token' => $channel['apptoken'],
|
||||
|
||||
//签名方式,默认为RSA2
|
||||
'sign_type' => "RSA2",
|
||||
|
||||
//编码格式
|
||||
'charset' => "UTF-8",
|
||||
|
||||
//支付宝网关
|
||||
'gateway_url' => "https://openapi.alipay.com/gateway.do",
|
||||
|
||||
//日志记录位置
|
||||
'log_path' => dirname(__FILE__).'/log/',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayRootCert.crt';
|
||||
}
|
||||
elseif(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayRootCert.crt';
|
||||
}
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
if(!defined('IN_PLUGIN'))exit();?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>收银台</title>
|
||||
<script src="//gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var userId = "<?php echo $channel['appmchid']?>";
|
||||
var money = "<?php echo $order['realmoney']?>";
|
||||
var remark = "请勿添加备注-<?php echo $order['trade_no']?>";
|
||||
|
||||
function returnApp() {
|
||||
AlipayJSBridge.call("exitApp")
|
||||
}
|
||||
|
||||
function ready(a) {
|
||||
window.AlipayJSBridge ? a && a() : document.addEventListener("AlipayJSBridgeReady", a, !1)
|
||||
}
|
||||
|
||||
ready(function () {
|
||||
try {
|
||||
var a = {
|
||||
actionType: "scan",
|
||||
u: userId,
|
||||
a: money,
|
||||
m: remark,
|
||||
biz_data: {
|
||||
s: "money",
|
||||
u: userId,
|
||||
a: money,
|
||||
m: remark
|
||||
}
|
||||
}
|
||||
} catch (b) {
|
||||
returnApp()
|
||||
}
|
||||
AlipayJSBridge.call("startApp", {
|
||||
appId: "20000123",
|
||||
param: a
|
||||
}, function (a) { })
|
||||
});
|
||||
document.addEventListener("resume", function (a) {
|
||||
returnApp()
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
// 支付宝扫码支付页面
|
||||
if (!defined('IN_PLUGIN')) exit();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="Content-Language" content="zh-cn">
|
||||
<meta name="renderer" content="webkit">
|
||||
<title>支付宝扫码支付</title>
|
||||
<link href="/assets/css/alipay_pay.css?v=3" rel="stylesheet" media="screen">
|
||||
<style>
|
||||
.countdown-container {
|
||||
margin: 15px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.countdown-title {
|
||||
font-size: 16px;
|
||||
color: #e8501c;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.countdown-timer {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.countdown-box {
|
||||
background-color: #1E9FFF;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
padding: 5px 8px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.countdown-box span {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.countdown-label {
|
||||
margin-left: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.qr-expired-overlay {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
z-index: 10;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.qr-expired-text {
|
||||
color: #fff;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.qr-expired-icon {
|
||||
font-size: 40px;
|
||||
color: #FF5722;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.qr-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<img src="/assets/img/guide1.png" alt="引导图" class="top-guide" style="max-width: 100%;margin: auto;display:none">
|
||||
<div class="guide" style="display:none"><img src="/assets/img/guide2.png" alt="引导图" style="width: 96%;"></div>
|
||||
<div class="body">
|
||||
<h1 class="mod-title">
|
||||
<span class="ico-wechat"></span><span class="text">支付宝扫码支付</span>
|
||||
</h1>
|
||||
<div class="mod-ct">
|
||||
<div class="order">
|
||||
</div>
|
||||
<div class="amount">¥<?php echo $order['realmoney'] ?></div>
|
||||
<div class="qr-container" style="margin-top: 20px;">
|
||||
<div class="qr-image" id="qrcode" style="margin-top: 0px;"></div>
|
||||
<!-- 二维码过期蒙层 -->
|
||||
<div class="qr-expired-overlay" id="qrExpiredOverlay">
|
||||
<div class="qr-expired-icon">×</div>
|
||||
<div class="qr-expired-text">二维码已失效</div>
|
||||
<div class="qr-expired-text">请返回重新发起支付</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 倒计时 -->
|
||||
<div class="countdown-container">
|
||||
<div class="countdown-title">支付剩余时间</div>
|
||||
<div class="countdown-timer">
|
||||
<div class="countdown-box">
|
||||
<span id="hours">00</span>
|
||||
<span class="countdown-label">时</span>
|
||||
</div>
|
||||
<div class="countdown-box">
|
||||
<span id="minutes">00</span>
|
||||
<span class="countdown-label">分</span>
|
||||
</div>
|
||||
<div class="countdown-box">
|
||||
<span id="seconds">00</span>
|
||||
<span class="countdown-label">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="open_app" style="display: none;">
|
||||
<a class="btn-open-app">打开支付宝APP继续付款</a><br /><br /><br />
|
||||
<a onclick="checkresult()" class="btn-check">我已付款,返回查看订单</a>
|
||||
</div>
|
||||
<div class="detail" id="orderDetail" style="margin-top: 0px;">
|
||||
<dl class="detail-ct" style="display: none;">
|
||||
<dt>购买物品</dt>
|
||||
<dd id="productName"><?php echo $order['name'] ?></dd>
|
||||
<dt>商户订单号</dt>
|
||||
<dd id="billId"><?php echo $order['trade_no'] ?></dd>
|
||||
<dt>创建时间</dt>
|
||||
<dd id="createTime"><?php echo $order['addtime'] ?></dd>
|
||||
</dl>
|
||||
<a href="javascript:void(0)" class="arrow"><i class="ico-arrow"></i></a>
|
||||
</div>
|
||||
<div class="tip">
|
||||
<span class="dec dec-left"></span>
|
||||
<span class="dec dec-right"></span>
|
||||
<div class="ico-scan"></div>
|
||||
<div class="tip-text">
|
||||
<p>请使用支付宝扫一扫</p>
|
||||
<p>扫描二维码完成支付</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="<?php echo $cdnpublic ?>jquery/1.12.4/jquery.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>layer/3.1.1/layer.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
|
||||
<script>
|
||||
var code_url = '<?php echo $code_url ?>';
|
||||
var code_type = code_url.indexOf('data:image/') > -1 ? 1 : 0;
|
||||
if (code_type == 0) {
|
||||
var url_scheme = 'alipays://platformapi/startapp?appId=20000067&url=' + encodeURIComponent(code_url);
|
||||
$('#qrcode').qrcode({
|
||||
text: code_url,
|
||||
width: 230,
|
||||
height: 230,
|
||||
foreground: "#000000",
|
||||
background: "#ffffff",
|
||||
typeNumber: -1
|
||||
});
|
||||
} else {
|
||||
$('#qrcode').html('<img src="' + code_url + '"/>');
|
||||
}
|
||||
// 订单详情
|
||||
$('#orderDetail .arrow').click(function(event) {
|
||||
if ($('#orderDetail').hasClass('detail-open')) {
|
||||
$('#orderDetail .detail-ct').slideUp(500, function() {
|
||||
$('#orderDetail').removeClass('detail-open');
|
||||
});
|
||||
} else {
|
||||
$('#orderDetail .detail-ct').slideDown(500, function() {
|
||||
$('#orderDetail').addClass('detail-open');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function loadmsg() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/getshop.php",
|
||||
data: {
|
||||
type: "alipay",
|
||||
trade_no: "<?php echo $order['trade_no'] ?>"
|
||||
},
|
||||
success: function(data) {
|
||||
if (data.code == 1) {
|
||||
layer.msg('支付成功,正在跳转中...', {
|
||||
icon: 16,
|
||||
shade: 0.1,
|
||||
time: 15000
|
||||
});
|
||||
setTimeout(window.location.href = data.backurl, 1000);
|
||||
} else {
|
||||
setTimeout("loadmsg()", 2000);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
setTimeout("loadmsg()", 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkresult() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/getshop.php",
|
||||
data: {
|
||||
type: "alipay",
|
||||
trade_no: "<?php echo $order['trade_no'] ?>"
|
||||
},
|
||||
success: function(data) {
|
||||
if (data.code == 1) {
|
||||
layer.msg('支付成功,正在跳转中...', {
|
||||
icon: 16,
|
||||
shade: 0.1,
|
||||
time: 15000
|
||||
});
|
||||
setTimeout(window.location.href = data.backurl, 1000);
|
||||
} else {
|
||||
layer.msg('您还未完成付款,请继续付款', {
|
||||
shade: 0,
|
||||
time: 1500
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.msg('服务器错误');
|
||||
}
|
||||
});
|
||||
}
|
||||
var isMobile = function() {
|
||||
var ua = navigator.userAgent;
|
||||
var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
|
||||
isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
|
||||
isAndroid = ua.match(/(Android)\s+([\d.]+)/);
|
||||
return isIphone || isAndroid;
|
||||
}
|
||||
|
||||
function wx_open() {
|
||||
$(".guide").show();
|
||||
//layer.alert('请点击屏幕右上角,<b>在浏览器打开</b>即可跳转支付。<br/><font color="red">支付成功后,回到微信查看结果</font>', {title:'支付提示'});
|
||||
}
|
||||
window.onload = function() {
|
||||
if (isMobile()) {
|
||||
window.onpopstate = function(e) {
|
||||
if (e.state == 'forward' || confirm('是否取消支付并返回?')) {
|
||||
window.history.back();
|
||||
} else {
|
||||
e.preventDefault();
|
||||
window.history.pushState('forward', null, '');
|
||||
}
|
||||
};
|
||||
window.history.pushState('forward', null, '');
|
||||
}
|
||||
if (isMobile() && code_type == 0) {
|
||||
$('.open_app').show();
|
||||
if (navigator.userAgent.indexOf('MicroMessenger/') > 0) {
|
||||
$(".top-guide").show();
|
||||
$('.btn-open-app').attr('href', 'javascript:wx_open()');
|
||||
} else {
|
||||
$('.btn-open-app').attr('href', url_scheme)
|
||||
if (navigator.userAgent.indexOf('EdgA/') == -1) {
|
||||
setTimeout(window.location.href = url_scheme, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
$("body").click(function() {
|
||||
if (!$(".guide").is(":hidden")) {
|
||||
$(".guide").hide();
|
||||
}
|
||||
});
|
||||
setTimeout("loadmsg()", 2000);
|
||||
startCountdown(<?php echo $paytime; ?>);
|
||||
}
|
||||
|
||||
// 倒计时功能
|
||||
function startCountdown(duration) {
|
||||
var timer = duration;
|
||||
var hoursElement = document.getElementById('hours');
|
||||
var minutesElement = document.getElementById('minutes');
|
||||
var secondsElement = document.getElementById('seconds');
|
||||
var qrExpiredOverlay = document.getElementById('qrExpiredOverlay');
|
||||
if(duration <= 0){
|
||||
qrExpiredOverlay.style.display = 'flex';
|
||||
return;
|
||||
}
|
||||
|
||||
var countdown = function() {
|
||||
var hours = Math.floor(timer / 3600);
|
||||
var minutes = Math.floor((timer % 3600) / 60);
|
||||
var seconds = timer % 60;
|
||||
// 填充前导零
|
||||
hours = hours < 10 ? "0" + hours : hours;
|
||||
minutes = minutes < 10 ? "0" + minutes : minutes;
|
||||
seconds = seconds < 10 ? "0" + seconds : seconds;
|
||||
// 更新显示
|
||||
hoursElement.textContent = hours;
|
||||
minutesElement.textContent = minutes;
|
||||
secondsElement.textContent = seconds;
|
||||
// 计时器递减
|
||||
if (--timer < 0) {
|
||||
// 时间到,清除定时器并显示过期蒙层
|
||||
clearInterval(window.countdownInterval);
|
||||
qrExpiredOverlay.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
countdown();
|
||||
window.countdownInterval = setInterval(countdown, 1000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') {
|
||||
die("This Programe can only be run in CLI mode");
|
||||
}
|
||||
@chdir(dirname(__FILE__));
|
||||
$nosession = true;
|
||||
include("../../includes/common.php");
|
||||
|
||||
$channelid = isset($argv[1]) ? intval($argv[1]) : exit('支付通道ID不能为空');
|
||||
$channel = \lib\Channel::get($channelid);
|
||||
if(!$channel || $channel['plugin'] != 'alipaycode') exit('支付通道不存在');
|
||||
$sql = "";
|
||||
if(substr($channel['apptoken'], 0, 1) == '['){
|
||||
$channel = \lib\Channel::getSub($channelid);
|
||||
if(!$channel || $channel['plugin'] != 'alipaycode') exit('子通道不存在');
|
||||
$sql = " AND subchannel='{$channel['subid']}'";
|
||||
}
|
||||
$alipay_config = require(PLUGIN_ROOT.$channel['plugin'].'/inc/config.php');
|
||||
$aop = new \Alipay\AlipayBillService($alipay_config);
|
||||
|
||||
while(true){
|
||||
$now = time();
|
||||
$list = $DB->getAll("SELECT trade_no,realmoney FROM pre_order WHERE channel='{$channel['id']}'{$sql} AND status=0 AND addtime>=DATE_SUB(NOW(), INTERVAL 8 MINUTE)");
|
||||
if(empty($list)){
|
||||
echo '暂无未支付订单...'.PHP_EOL;
|
||||
goto WAIT;
|
||||
}
|
||||
$start_time = date('Y-m-d H:i:s', time()-180);
|
||||
$end_time = date('Y-m-d H:i:s', time()+60);
|
||||
try{
|
||||
$result = $aop->accountlogQuery($start_time, $end_time, 1, 2000);
|
||||
}catch(Exception $e){
|
||||
echo '查询账务明细失败,'.$e->getMessage().PHP_EOL;
|
||||
goto WAIT;
|
||||
}
|
||||
if(empty($result['detail_list'])){
|
||||
echo '共查询到0条账务明细'.PHP_EOL;
|
||||
goto WAIT;
|
||||
}
|
||||
echo '共查询到'.count($result['detail_list']).'条账务明细'.PHP_EOL;
|
||||
foreach($result['detail_list'] as $item){
|
||||
if(isset($item['trans_memo']) && isset($item['trans_amount'])){
|
||||
$trade_no = str_replace('请勿添加备注-', '', $item['trans_memo']);
|
||||
$money = $item['trans_amount'];
|
||||
$orders = array_filter($list, function($v) use($trade_no, $money){
|
||||
return $v['trade_no'] == $trade_no && $v['realmoney'] == $money;
|
||||
});
|
||||
if(!empty($orders)){
|
||||
$order = $DB->getRow("SELECT A.*,B.name typename,B.showname typeshowname FROM pre_order A left join pre_type B on A.type=B.id WHERE trade_no=:trade_no limit 1", [':trade_no'=>$trade_no]);
|
||||
$order['plugin'] = $channel['plugin'];
|
||||
$buyer = empty($order['buyer']) ? $item['other_account'] : null;
|
||||
processNotify($order, $item['alipay_order_no'], $buyer);
|
||||
echo '订单'.$trade_no.'('.$item['trans_amount'].'元)支付成功'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
WAIT:
|
||||
$time = time()-$now;
|
||||
if($time < 3){
|
||||
sleep(3-$time);
|
||||
}
|
||||
}
|
||||
echo 'stop!';
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//应用ID
|
||||
'app_id' => $channel['appid'],
|
||||
|
||||
//支付宝公钥
|
||||
'alipay_public_key' => $channel['appkey'],
|
||||
|
||||
//应用私钥
|
||||
'app_private_key' => $channel['appsecret'],
|
||||
|
||||
//子商户SMID
|
||||
'smid' => $channel['appmchid'],
|
||||
|
||||
//签名方式,默认为RSA2
|
||||
'sign_type' => "RSA2",
|
||||
|
||||
//编码格式
|
||||
'charset' => "UTF-8",
|
||||
|
||||
//支付宝网关
|
||||
'gateway_url' => "https://openapi.alipay.com/gateway.do",
|
||||
|
||||
//日志记录位置
|
||||
'log_path' => dirname(__FILE__).'/log/',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayRootCert.crt';
|
||||
}
|
||||
elseif(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayRootCert.crt';
|
||||
}
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
class alipayg_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'alipayg', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '支付宝国际版', //支付插件显示名称
|
||||
'author' => 'Antom', //支付插件作者
|
||||
'link' => 'https://www.antom.com/', //支付插件作者链接
|
||||
'types' => ['alipay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '应用Client ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => 'Antom公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '填错也可以支付成功但会无法回调',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '应用私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '选择网关地址',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
0=>'亚洲(https://open-sea-global.alipay.com)',
|
||||
1=>'北美(https://open-na-global.alipay.com)',
|
||||
2=>'欧洲(https://open-de-global.alipay.com)',
|
||||
],
|
||||
],
|
||||
'currency_code' => [
|
||||
'name' => '结算货币',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'CNY' => '人民币 (CNY)',
|
||||
'HKD' => '港币 (HKD)',
|
||||
'EUR' => '欧元 (EUR)',
|
||||
'USD' => '美元 (USD)',
|
||||
'AUD' => '澳元 (AUD)',
|
||||
'CAD' => '加拿大元 (CAD)',
|
||||
'GBP' => '英镑 (GBP)',
|
||||
'BRL' => '巴西雷亚尔 (BRL)',
|
||||
'CZK' => '克朗 (CZK)',
|
||||
'DKK' => '丹麦克朗(DKK)',
|
||||
'HUF' => '匈牙利福林 (HUF)',
|
||||
'INR' => '印度卢比 (INR)',
|
||||
'ILS' => '以色列新谢克尔 (ILS)',
|
||||
'JPY' => '日元 (JPY)',
|
||||
'MYR' => '马来西亚林吉特 (MYR)',
|
||||
'MXN' => '墨西哥比索 (MXN)',
|
||||
'TWD' => '新台币 (TWD)',
|
||||
'NZD' => '新西兰元 (NZD)',
|
||||
'NOK' => '挪威克朗 (NOK)',
|
||||
'PHP' => '菲律宾比索 (PHP)',
|
||||
'PLN' => '波兰兹罗提 (PLN)',
|
||||
'RUB' => '俄罗斯卢布 (RUB)',
|
||||
'SGD' => '新加坡元 (SGD)',
|
||||
'SEK' => '瑞典克朗 (SEK)',
|
||||
'CHF' => '瑞士法郎 (CHF)',
|
||||
'THB' => '泰铢 (THB)',
|
||||
],
|
||||
],
|
||||
'currency_rate' => [
|
||||
'name' => '货币汇率',
|
||||
'type' => 'input',
|
||||
'note' => '例如1元人民币兑换0.137美元(USD),则此处填0.137',
|
||||
],
|
||||
],
|
||||
'note' => '<p>默认使用Antom在线支付的收银台支付</p>', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $submit2, $conf, $clientip;
|
||||
|
||||
return ['type'=>'jump','url'=>'/pay/pay/'.TRADE_NO.'/'];
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice, $method;
|
||||
|
||||
return self::pay();
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static public function pay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT.'inc/AlipayGlobalClient.php');
|
||||
|
||||
if(!$channel['currency_rate']) $channel['currency_rate'] = 1;
|
||||
if(!$channel['currency_code']) $channel['currency_code'] = 'CNY';
|
||||
$amount = intval(round($order['realmoney'] * $channel['currency_rate'] * 100));
|
||||
|
||||
$osType = '';
|
||||
$terminalType = 'WEB';
|
||||
if(checkmobile() || $device == 'mobile'){
|
||||
$terminalType = 'WAP';
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false){
|
||||
$osType = 'IOS';
|
||||
}else{
|
||||
$osType = 'ANDROID';
|
||||
}
|
||||
}
|
||||
|
||||
$client = new AlipayGlobalClient($channel['appswitch'], $channel['appid'], $channel['appsecret'], $channel['appkey']);
|
||||
$params = [
|
||||
'env' => [
|
||||
'terminalType' => $terminalType,
|
||||
'osType' => $osType
|
||||
],
|
||||
'order' => [
|
||||
'orderAmount' => [
|
||||
'currency' => $channel['currency_code'],
|
||||
'value' => $amount,
|
||||
],
|
||||
'referenceOrderId' => TRADE_NO,
|
||||
'orderDescription' => $ordername,
|
||||
],
|
||||
'paymentRequestId' => TRADE_NO,
|
||||
'paymentAmount' => [
|
||||
'currency' => $channel['currency_code'],
|
||||
'value' => $amount,
|
||||
],
|
||||
'settlementStrategy' => [
|
||||
'settlementCurrency' => $channel['currency_code'],
|
||||
],
|
||||
'paymentMethod' => [
|
||||
'paymentMethodType' => 'ALIPAY_CN',
|
||||
],
|
||||
'paymentNotifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'paymentRedirectUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'productCode' => 'CASHIER_PAYMENT',
|
||||
];
|
||||
try{
|
||||
$result = $client->execute('/v1/payments/pay', $params);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
if(!empty($result['normalUrl'])){
|
||||
return ['type'=>'jump','url'=>$result['normalUrl']];
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!未获取到支付链接'];
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr){
|
||||
return ['type'=>'json','data'=>['result'=>['resultCode'=>'FAIL','resultStatus'=>'F','resultMessage'=>'data error']]];
|
||||
}
|
||||
|
||||
require(PAY_ROOT.'inc/AlipayGlobalClient.php');
|
||||
$client = new AlipayGlobalClient($channel['appswitch'], $channel['appid'], $channel['appsecret'], $channel['appkey']);
|
||||
|
||||
$verify_result = $client->check($json);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
$out_trade_no = $arr['paymentRequestId'];
|
||||
$trade_no = $arr['paymentId'];
|
||||
$buyer_id = $arr['pspCustomerInfo']['pspCustomerId'];
|
||||
$total_amount = $arr['paymentAmount']['value'];
|
||||
|
||||
if ($arr['result']['resultStatus'] == 'S') {
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $trade_no, $buyer_id);
|
||||
}
|
||||
}
|
||||
return ['type'=>'json','data'=>['result'=>['resultCode'=>'SUCCESS','resultStatus'=>'S','resultMessage'=>'success']]];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'json','data'=>['result'=>['resultCode'=>'FAIL','resultStatus'=>'F','resultMessage'=>'sign error']]];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
if(!$channel['currency_rate']) $channel['currency_rate'] = 1;
|
||||
if(!$channel['currency_code']) $channel['currency_code'] = 'CNY';
|
||||
$amount = intval(round($order['refundmoney'] * $channel['currency_rate'] * 100));
|
||||
|
||||
require(PAY_ROOT.'inc/AlipayGlobalClient.php');
|
||||
$client = new AlipayGlobalClient($channel['appswitch'], $channel['appid'], $channel['appsecret'], $channel['appkey']);
|
||||
$params = [
|
||||
'refundRequestId' => $order['refund_no'],
|
||||
'paymentId' => $order['api_trade_no'],
|
||||
'refundAmount' => [
|
||||
'currency' => $channel['currency_code'],
|
||||
'value' => $amount,
|
||||
]
|
||||
];
|
||||
try{
|
||||
$result = $client->execute('/v1/payments/refund', $params);
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['refundId'], 'refund_fee'=>$result['refundAmount']['value']];
|
||||
}
|
||||
|
||||
//关闭订单
|
||||
static public function close($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT.'inc/AlipayGlobalClient.php');
|
||||
$client = new AlipayGlobalClient($channel['appswitch'], $channel['appid'], $channel['appsecret'], $channel['appkey']);
|
||||
$params = [
|
||||
'paymentRequestId' => $order['trade_no'],
|
||||
];
|
||||
try{
|
||||
$client->execute('/v1/payments/cancel', $params);
|
||||
return ['code'=>0];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
class AlipayGlobalClient
|
||||
{
|
||||
|
||||
const DEFAULT_KEY_VERSION = 1;
|
||||
private $gatewayUrl;
|
||||
private $clientId;
|
||||
private $merchantPrivateKey;
|
||||
private $alipayPublicKey;
|
||||
private $agentToken;
|
||||
private $isSandboxMode;
|
||||
|
||||
public function __construct($gatewayUrl, $clientId, $merchantPrivateKey, $alipayPublicKey, $agentToken = null)
|
||||
{
|
||||
$this->gatewayUrl = $gatewayUrl;
|
||||
if(is_numeric($this->gatewayUrl)){
|
||||
$this->gatewayUrl = $this->getGatewayUrl($this->gatewayUrl);
|
||||
}
|
||||
$this->clientId = $clientId;
|
||||
$this->merchantPrivateKey = $merchantPrivateKey;
|
||||
$this->alipayPublicKey = $alipayPublicKey;
|
||||
$this->agentToken = $agentToken;
|
||||
|
||||
if (strpos($clientId, "SANDBOX_") === 0) {
|
||||
$this->isSandboxMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
//获取网关地址
|
||||
private function getGatewayUrl($code){
|
||||
if($code == 2){
|
||||
return 'https://open-de-global.alipay.com';
|
||||
}elseif($code == 1){
|
||||
return 'https://open-na-global.alipay.com';
|
||||
}else{
|
||||
return 'https://open-sea-global.alipay.com';
|
||||
}
|
||||
}
|
||||
|
||||
public function execute($path, $params, $httpMethod = 'POST')
|
||||
{
|
||||
$path = ($this->isSandboxMode ? '/ams/sandbox/api' : '/ams/api') . $path;
|
||||
$reqUrl = $this->gatewayUrl . $path;
|
||||
$reqTime = $this->getMillisecond();
|
||||
$reqBody = json_encode($params);
|
||||
|
||||
$signValue = $this->genSignValue($httpMethod, $path, $reqTime, $reqBody);
|
||||
$headers = $this->buildBaseHeader($reqTime, $this->clientId, $signValue);
|
||||
|
||||
[$headerContent, $rspBody] = $this->sendRequest($reqUrl, $reqBody, $headers);
|
||||
|
||||
$repHeaders = $this->getHeaderParams($headerContent);
|
||||
$arr = json_decode($rspBody, true);
|
||||
|
||||
if(!$arr || !isset($arr['result'])){
|
||||
throw new Exception('接口响应数据错误');
|
||||
}
|
||||
|
||||
if(!empty($repHeaders['signature'])){
|
||||
if(!$this->checkRspSign($httpMethod, $path, $repHeaders['responseTime'], $rspBody, $repHeaders['signature'])){
|
||||
throw new Exception('响应数据验签失败');
|
||||
}
|
||||
}
|
||||
|
||||
if($arr['result']['resultStatus'] == 'S' || $arr['result']['resultStatus'] == 'U' && $arr['result']['resultCode'] == 'PAYMENT_IN_PROCESS'){
|
||||
return $arr;
|
||||
}else{
|
||||
throw new Exception('['.$arr['result']['resultCode'].']'.$arr['result']['resultMessage']);
|
||||
}
|
||||
}
|
||||
|
||||
public function check($body){
|
||||
$signature = $_SERVER['HTTP_SIGNATURE'];
|
||||
$responseTime = $_SERVER['HTTP_REQUEST_TIME'];
|
||||
if(empty($signature)) return false;
|
||||
$httpMethod = 'POST';
|
||||
$path = $_SERVER['REQUEST_URI'];
|
||||
$signatureValue = trim(substr($signature, strrpos($signature, "=") + 1));
|
||||
if($this->checkRspSign($httpMethod, $path, $responseTime, $body, $signatureValue)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//生成请求头部
|
||||
private function buildBaseHeader($requestTime, $clientId, $signValue)
|
||||
{
|
||||
$baseHeader = array();
|
||||
$baseHeader[] = "Content-Type:application/json; charset=UTF-8";
|
||||
$baseHeader[] = "User-Agent:global-alipay-sdk-php";
|
||||
$baseHeader[] = "Request-Time:" . $requestTime;
|
||||
$baseHeader[] = "client-id:" . $clientId;
|
||||
|
||||
if(!empty($this->agentToken)){
|
||||
$baseHeader[] = "agent-token: " . $this->agentToken;
|
||||
}
|
||||
|
||||
$signatureHeader = "algorithm=RSA256,keyVersion=" . self::DEFAULT_KEY_VERSION . ",signature=" . $signValue;
|
||||
$baseHeader[] = "Signature:" . $signatureHeader;
|
||||
return $baseHeader;
|
||||
}
|
||||
|
||||
//解析返回头部参数
|
||||
private function getHeaderParams($header){
|
||||
if (preg_match('/signature=(.*?)\r\n/i', $header, $signature)) {
|
||||
$signature = trim($signature[1]);
|
||||
}
|
||||
if (preg_match('/client-id: (.*?)\r\n/i', $header, $clientId)) {
|
||||
$clientId = trim($clientId[1]);
|
||||
}
|
||||
if (preg_match('/response-time: (.*?)\r\n/i', $header, $responseTime)) {
|
||||
$responseTime = trim($responseTime[1]);
|
||||
}
|
||||
return ['signature'=>$signature, 'clientId'=>$clientId, 'responseTime'=>$responseTime];
|
||||
}
|
||||
|
||||
private function genSignContent($httpMethod, $path, $timeString, $content)
|
||||
{
|
||||
$payload = $httpMethod . " " . $path . "\n" . $this->clientId . "." . $timeString . "." . $content;
|
||||
return $payload;
|
||||
}
|
||||
|
||||
private function genSignValue($httpMethod, $path, $reqTime, $reqBody)
|
||||
{
|
||||
$signContent = $this->genSignContent($httpMethod, $path, $reqTime, $reqBody);
|
||||
$signValue = $this->signWithSHA256RSA($signContent, $this->merchantPrivateKey);
|
||||
return urlencode($signValue);
|
||||
}
|
||||
|
||||
private function checkRspSign($httpMethod, $path, $rspTime, $rspBody, $rspSignValue)
|
||||
{
|
||||
$rspContent = $this->genSignContent($httpMethod, $path, $rspTime, $rspBody);
|
||||
return $this->verifySignatureWithSHA256RSA($rspContent, $rspSignValue, $this->alipayPublicKey);
|
||||
}
|
||||
|
||||
private function signWithSHA256RSA($signContent, $merchantPrivateKey)
|
||||
{
|
||||
$priKey = "-----BEGIN RSA PRIVATE KEY-----\n" .
|
||||
wordwrap($merchantPrivateKey, 64, "\n", true) .
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
$res = openssl_pkey_get_private($priKey);
|
||||
if (!$res) {
|
||||
throw new \Exception("签名失败,应用私钥不正确");
|
||||
}
|
||||
openssl_sign($signContent, $signValue, $res, OPENSSL_ALGO_SHA256);
|
||||
return base64_encode($signValue);
|
||||
}
|
||||
|
||||
private function verifySignatureWithSHA256RSA($rspContent, $rspSignValue, $alipayPublicKey)
|
||||
{
|
||||
$pubKey = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($alipayPublicKey, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$res = openssl_get_publickey($pubKey);
|
||||
if(!$res){
|
||||
throw new \Exception('验签失败,Antom公钥不正确');
|
||||
}
|
||||
if (strstr($rspSignValue, "=")
|
||||
|| strstr($rspSignValue, "+")
|
||||
|| strstr($rspSignValue, "/")
|
||||
|| $rspSignValue == base64_encode(base64_decode($rspSignValue))) {
|
||||
$originalRspSignValue = base64_decode($rspSignValue);
|
||||
} else {
|
||||
$originalRspSignValue = base64_decode(urldecode($rspSignValue));
|
||||
}
|
||||
$verifyResult = openssl_verify($rspContent, $originalRspSignValue, $res, OPENSSL_ALGO_SHA256);
|
||||
return $verifyResult === 1;
|
||||
}
|
||||
|
||||
//发送请求
|
||||
private function sendRequest($url, $body, $headers){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
|
||||
$rspContent = curl_exec($ch);
|
||||
|
||||
if (curl_errno($ch) > 0) {
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new \Exception($errmsg, 0);
|
||||
}
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
curl_close($ch);
|
||||
if (empty($rspContent)) {
|
||||
$rspContent = "HTTP Code: " . $httpCode;
|
||||
}
|
||||
throw new \Exception($rspContent, $httpCode);
|
||||
}
|
||||
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$headerContent = substr($rspContent, 0, $headerSize);
|
||||
$rspBody = substr($rspContent, $headerSize);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return [$headerContent, $rspBody];
|
||||
}
|
||||
|
||||
private function getMillisecond()
|
||||
{
|
||||
list($s1, $s2) = explode(' ', microtime());
|
||||
return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//PID
|
||||
'partner' => $channel['appid'],
|
||||
|
||||
//MD5密钥
|
||||
'key' => $channel['appkey'],
|
||||
|
||||
//签名方式
|
||||
'sign_type' => 'MD5',
|
||||
];
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
class alipayhk_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'alipayhk', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => 'AlipayHK', //支付插件显示名称
|
||||
'author' => '支付宝', //支付插件作者
|
||||
'link' => 'https://global.alipay.com/', //支付插件作者链接
|
||||
'types' => ['alipay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => 'Partner ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => 'MD5 Key',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '支付时选择钱包类型',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'0' => '否',
|
||||
'1' => '是',
|
||||
],
|
||||
],
|
||||
],
|
||||
'select' => [ //选择已开启的支付方式
|
||||
'1' => 'PC支付',
|
||||
'2' => 'WAP支付',
|
||||
'3' => 'APP支付',
|
||||
],
|
||||
'note' => '支付时选择钱包类型开启后,支付时可选择Alipay或AlipayHK,关闭则默认使用Alipay', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static private $trade_information = ['business_type'=>'5','other_business_type'=>'在线充值'];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $submit2, $conf;
|
||||
|
||||
if(checkwechat()){
|
||||
if(!$submit2){
|
||||
return ['type'=>'jump','url'=>'/pay/submit/'.TRADE_NO.'/'];
|
||||
}
|
||||
return ['type'=>'page','page'=>'wxopen'];
|
||||
}
|
||||
|
||||
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
|
||||
}
|
||||
|
||||
static public function alipay(){
|
||||
global $channel, $order, $cdnpublic, $siteurl;
|
||||
|
||||
if($channel['appswitch'] == 1 && empty($_GET['type'])){
|
||||
include PAY_ROOT.'select.page.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if(checkmobile()){
|
||||
if(in_array('2',$channel['apptype'])){
|
||||
return self::wappay();
|
||||
}elseif(in_array('1',$channel['apptype'])){
|
||||
return self::submitpc();
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
if(checkalipay()){
|
||||
return self::apppay();
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/apppay/'.TRADE_NO.'/?type='.$_GET['type'];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
$code_url = '/pay/submitpc/'.TRADE_NO.'/?type='.$_GET['type'];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcodepc','url'=>$code_url];
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/wappay/'.TRADE_NO.'/?type='.$_GET['type'];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/apppay/'.TRADE_NO.'/?type='.$_GET['type'];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public function submitpc(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $conf;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
$parameter = array(
|
||||
'service' => 'create_forex_trade',
|
||||
'partner' => trim($alipay_config['partner']),
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'subject' => $ordername,
|
||||
'currency' => 'HKD',
|
||||
'rmb_fee' => $order['realmoney'],
|
||||
'refer_url' => $siteurl,
|
||||
'product_code' => 'NEW_WAP_OVERSEAS_SELLER',
|
||||
'qr_pay_mode' => '4',
|
||||
'qrcode_width' => '230',
|
||||
'trade_information' => json_encode(self::$trade_information),
|
||||
'_input_charset' => 'utf-8'
|
||||
);
|
||||
if(!empty($_GET['type'])){
|
||||
$parameter['payment_inst'] = trim($_GET['type']);
|
||||
}
|
||||
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
if(checkmobile() && !checkalipay()){
|
||||
try{
|
||||
$url = $client->buildRequestForm($parameter, 'REDIRECT');
|
||||
$html = get_curl($url, 0, 0, 0, 0, 0, 0, 0, 1);
|
||||
$html = mb_convert_encoding($html, 'utf-8', 'gbk');
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}
|
||||
if(preg_match('!<input name="qrCode" type="hidden" value="(.*?)"!i', $html, $match)){
|
||||
$code_url = $match[1];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!获取二维码失败'];
|
||||
}
|
||||
}else{
|
||||
$html_text = $client->buildRequestForm($parameter);
|
||||
$html_text = '<!DOCTYPE html><html><body><style>body{margin:0;padding:0}.waiting{position:absolute;width:100%;height:100%;background:#fff url(/assets/img/load.gif) no-repeat fixed center/80px;}</style><div class="waiting"></div>'.$html_text.'</body></html>';
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
}
|
||||
|
||||
static public function wappay(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $conf;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
$parameter = array(
|
||||
'service' => 'create_forex_trade_wap',
|
||||
'partner' => trim($alipay_config['partner']),
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'subject' => $ordername,
|
||||
'currency' => 'HKD',
|
||||
'rmb_fee' => $order['realmoney'],
|
||||
'refer_url' => $siteurl,
|
||||
'product_code' => 'NEW_WAP_OVERSEAS_SELLER',
|
||||
'trade_information' => json_encode(self::$trade_information),
|
||||
'_input_charset' => 'utf-8'
|
||||
);
|
||||
if(!empty($_GET['type'])){
|
||||
$parameter['payment_inst'] = trim($_GET['type']);
|
||||
}
|
||||
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
$html_text = $client->buildRequestForm($parameter);
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
|
||||
static public function apppay(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $conf, $method;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
$parameter = array(
|
||||
'service' => 'mobile.securitypay.pay',
|
||||
'partner' => trim($alipay_config['partner']),
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'subject' => $ordername,
|
||||
'payment_type' => '1',
|
||||
'seller_id' => trim($alipay_config['partner']),
|
||||
'currency' => 'HKD',
|
||||
'rmb_fee' => $order['realmoney'],
|
||||
'forex_biz' => 'FP',
|
||||
'refer_url' => $siteurl,
|
||||
'product_code' => 'NEW_WAP_OVERSEAS_SELLER',
|
||||
'trade_information' => json_encode(self::$trade_information),
|
||||
'_input_charset' => 'utf-8'
|
||||
);
|
||||
if(!empty($_GET['type'])){
|
||||
$parameter['payment_inst'] = trim($_GET['type']);
|
||||
}
|
||||
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
$result = $client->buildSdkParam($parameter);
|
||||
if($method == 'app'){
|
||||
return ['type'=>'app','data'=>$result];
|
||||
}
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
$code_url = 'alipays://platformapi/startApp?appId=20000125&orderSuffix='.urlencode($result).'#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end';
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
$verify_result = $client->verify($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_POST['out_trade_no'];
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = $_POST['trade_no'];
|
||||
|
||||
//买家支付宝
|
||||
$buyer_id = $_POST['buyer_id'];
|
||||
|
||||
//交易金额
|
||||
$total_fee = $_POST['total_fee'];
|
||||
|
||||
if ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $trade_no, $buyer_id);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
$verify_result = $client->verify($_GET);
|
||||
if($verify_result) {
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//买家支付宝
|
||||
$buyer_id = $_GET['buyer_id'];
|
||||
|
||||
//交易金额
|
||||
$total_fee = $_GET['total_fee'];
|
||||
|
||||
if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processReturn($order, $trade_no, $buyer_id);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'trade_status='.$_GET['trade_status']];
|
||||
}
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'error','msg'=>'签名验证失败!'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
require(PAY_ROOT."inc/AlipayGlobalClient.php");
|
||||
|
||||
$params = [
|
||||
'service' => 'forex_refund',
|
||||
'partner' => trim($alipay_config['partner']),
|
||||
'out_return_no' => $order['refund_no'],
|
||||
'out_trade_no' => $order['trade_no'],
|
||||
'return_rmb_amount' => $order['refundmoney'],
|
||||
'currency' => 'HKD',
|
||||
'gmt_return' => date('Y-m-d H:i:s'),
|
||||
'_input_charset' => 'utf-8'
|
||||
];
|
||||
$client = new AlipayGlobalClient($alipay_config);
|
||||
$result = $client->sendRequest($params);
|
||||
if(isset($result['is_success']) && $result['is_success'] == 'T'){
|
||||
return ['code'=>0];
|
||||
}elseif(isset($result['error'])){
|
||||
return ['code'=>1,'msg'=>$result['error']];
|
||||
}else{
|
||||
return ['code'=>1,'msg'=>'未知错误'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://global.alipay.com/docs/ac/legacy/legacydoc
|
||||
*/
|
||||
class AlipayGlobalClient
|
||||
{
|
||||
private $gateway_url = 'https://intlmapi.alipay.com/gateway.do';
|
||||
private $partner;
|
||||
private $key;
|
||||
private $private_key;
|
||||
private $ali_public_key;
|
||||
private $sign_type = 'MD5';
|
||||
private $input_charset = 'utf-8';
|
||||
|
||||
public function __construct($alipay_config)
|
||||
{
|
||||
$this->partner = $alipay_config['partner'];
|
||||
if(!empty($alipay_config['sign_type'])){
|
||||
$this->sign_type = $alipay_config['sign_type'];
|
||||
}
|
||||
if($this->sign_type == 'RSA'){
|
||||
$this->private_key = $alipay_config['private_key'];
|
||||
$this->ali_public_key = $alipay_config['ali_public_key'];
|
||||
}else{
|
||||
$this->key = $alipay_config['key'];
|
||||
}
|
||||
if(!empty($alipay_config['gateway_url'])){
|
||||
$this->gateway_url = $alipay_config['gateway_url'];
|
||||
}
|
||||
}
|
||||
|
||||
public function buildRequestForm($params, $method = 'POST'){
|
||||
$data = $this->buildRequestParam($params);
|
||||
|
||||
if($method == 'REDIRECT'){
|
||||
$requestUrl = $this->gateway_url.'?'.http_build_query($data);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $requestUrl);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new Exception($errmsg, 0);
|
||||
}
|
||||
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpStatusCode == 301 || $httpStatusCode == 302) {
|
||||
$redirect_url = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
|
||||
curl_close($ch);
|
||||
return $redirect_url;
|
||||
} elseif ($httpStatusCode == 200) {
|
||||
curl_close($ch);
|
||||
$response = mb_convert_encoding($response, 'UTF-8', 'GB2312');
|
||||
if(preg_match('/<div\s+class="Todo">([^<]+)<\/div>/i', $response, $matchers)) {
|
||||
throw new Exception($matchers[1]);
|
||||
}
|
||||
}
|
||||
throw new Exception('返回数据解析失败', $httpStatusCode);
|
||||
}
|
||||
|
||||
$url = $this->gateway_url.'?_input_charset='.$this->input_charset;
|
||||
|
||||
$html = "<form id='alipaysubmit' name='alipaysubmit' action='{$url}' method='".$method."'>";
|
||||
foreach ($data as $key => $value) {
|
||||
$value = htmlentities($value, ENT_QUOTES | ENT_HTML5);
|
||||
$html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
|
||||
}
|
||||
$html .= "<input type='submit' value='ok' style='display:none;'></form>";
|
||||
$html .= "<script>document.forms['alipaysubmit'].submit();</script>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function sendRequest($params){
|
||||
$data = $this->buildRequestParam($params);
|
||||
$url = $this->gateway_url.'?_input_charset='.$this->input_charset;
|
||||
$response = $this->curl($url, http_build_query($data));
|
||||
$arr = $this->xml2array($response);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function buildSdkParam($params){
|
||||
$data = $this->buildRequestParam($params);
|
||||
return http_build_query($data);
|
||||
}
|
||||
|
||||
public function verify($param){
|
||||
if(!isset($param['sign'])) return false;
|
||||
$sign = $param['sign'];
|
||||
$signstr = $this->getSignContent($param);
|
||||
if($this->sign_type == 'MD5'){
|
||||
$mysign = md5($signstr . $this->key);
|
||||
return $mysign === $sign;
|
||||
}else{
|
||||
return $this->rsaPubilcVerify($signstr, $sign, $this->sign_type);
|
||||
}
|
||||
}
|
||||
|
||||
private function buildRequestParam($param){
|
||||
$param['sign'] = $this->getSign($param);
|
||||
$param['sign_type'] = $this->sign_type;
|
||||
return $param;
|
||||
}
|
||||
|
||||
private function getSign($param){
|
||||
$signstr = $this->getSignContent($param);
|
||||
if($this->sign_type == 'MD5'){
|
||||
$sign = md5($signstr . $this->key);
|
||||
}else{
|
||||
$sign = $this->rsaPrivateSign($signstr, $this->sign_type);
|
||||
}
|
||||
return $sign;
|
||||
}
|
||||
|
||||
private function getSignContent($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $k != "sign_type" && !$this->isEmpty($v)){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr,0,-1);
|
||||
return $signstr;
|
||||
}
|
||||
|
||||
private function isEmpty($value)
|
||||
{
|
||||
return $value === null || trim($value) === '';
|
||||
}
|
||||
|
||||
private function xml2array($xml)
|
||||
{
|
||||
if (!$xml) {
|
||||
return false;
|
||||
}
|
||||
LIBXML_VERSION < 20900 && libxml_disable_entity_loader(true);
|
||||
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
|
||||
}
|
||||
|
||||
public static function getMillisecond()
|
||||
{
|
||||
list($s1, $s2) = explode(' ', microtime());
|
||||
return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
//使用商户私钥签名
|
||||
private function rsaPrivateSign($data, $signType = 'RSA2'){
|
||||
$priKey = "-----BEGIN RSA PRIVATE KEY-----\n" .
|
||||
wordwrap($this->private_key, 64, "\n", true) .
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
$res = openssl_get_privatekey($priKey);
|
||||
if(!$res){
|
||||
throw new Exception('签名失败,商户私钥不正确');
|
||||
}
|
||||
|
||||
if($signType == 'RSA2'){
|
||||
openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
|
||||
}else{
|
||||
openssl_sign($data, $sign, $res);
|
||||
}
|
||||
openssl_free_key($res);
|
||||
return base64_encode($sign);
|
||||
}
|
||||
|
||||
//使用支付宝公钥验签
|
||||
private function rsaPubilcVerify($data, $sign, $signType = 'RSA2'){
|
||||
$pubKey = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($this->ali_public_key, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$res = openssl_get_publickey($pubKey);
|
||||
if(!$res){
|
||||
throw new Exception('验签失败,支付宝公钥不正确');
|
||||
}
|
||||
|
||||
if($signType == 'RSA2'){
|
||||
$result = openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256);
|
||||
}else{
|
||||
$result = openssl_verify($data, base64_decode($sign), $res);
|
||||
}
|
||||
openssl_free_key($res);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
private function curl($url, $post = false, $timeout = 10){
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
|
||||
$httpheader[] = "Connection: close";
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
if($post){
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//PID
|
||||
'partner' => $channel['appid'],
|
||||
|
||||
//MD5密钥
|
||||
'key' => $channel['appkey'],
|
||||
|
||||
//签名方式
|
||||
'sign_type' => 'MD5',
|
||||
];
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
if(!defined('IN_PLUGIN'))exit();?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="Content-Language" content="zh-cn">
|
||||
<meta name="renderer" content="webkit">
|
||||
<title>支付宝支付</title>
|
||||
<link href="/assets/css/alipay_pay.css?v=2" rel="stylesheet" media="screen">
|
||||
<style>
|
||||
.alipay-row{display:flex;justify-content:center;align-items:center;margin-top:35px}
|
||||
.alipay-col{margin:0 25px;text-align:center}
|
||||
.alipay-col p{margin:3px 0 10px;font-size:14px;color:#000}
|
||||
.alipay-logo{width:100px}
|
||||
.alipay-logo:hover{box-shadow:1px 3px 10px #888}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="body">
|
||||
<h1 class="mod-title">
|
||||
<span class="ico-wechat"></span><span class="text">支付宝支付</span>
|
||||
</h1>
|
||||
<div class="mod-ct">
|
||||
<div class="order">
|
||||
</div>
|
||||
<div class="amount">¥<?php echo $order['realmoney']?></div>
|
||||
<div style="margin-top: 30px">
|
||||
<div style="font-size:16px">请选择付款APP</div>
|
||||
<div style="font-size:14px;color:#999">Please select your wallet region</div>
|
||||
<div class="alipay-row">
|
||||
<div class="alipay-col">
|
||||
<a href="?type=ALIPAYCN"><img class="alipay-logo" src="https://payment.pa-sys.com/imgs/alipay-cn-20240905.png">
|
||||
<p>支付宝(中国)</p></a>
|
||||
</div>
|
||||
<div class="alipay-col">
|
||||
<a href="?type=ALIPAYHK"><img class="alipay-logo" src="https://payment.pa-sys.com/imgs/alipay-hk-20240905.png">
|
||||
<p>AlipayHK</p></a>
|
||||
</div>
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
<div class="detail detail-open" id="orderDetail">
|
||||
<dl class="detail-ct">
|
||||
<dt>购买物品</dt>
|
||||
<dd id="productName"><?php echo $order['name']?></dd>
|
||||
<dt>商户订单号</dt>
|
||||
<dd id="billId"><?php echo $order['trade_no']?></dd>
|
||||
<dt>创建时间</dt>
|
||||
<dd id="createTime"><?php echo $order['addtime']?></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="tip">
|
||||
<span class="dec dec-left"></span>
|
||||
<span class="dec dec-right"></span>
|
||||
</div>
|
||||
<div class="tip-text">
|
||||
</div>
|
||||
</div>
|
||||
<script src="<?php echo $cdnpublic?>jquery/1.12.4/jquery.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic?>layer/3.1.1/layer.js"></script>
|
||||
<script src="<?php echo $cdnpublic?>jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
|
||||
<script>
|
||||
function loadmsg() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/getshop.php",
|
||||
data: {type: "alipay", trade_no: "<?php echo $order['trade_no']?>"},
|
||||
success: function (data) {
|
||||
if (data.code == 1) {
|
||||
layer.msg('支付成功,正在跳转中...', {icon: 16,shade: 0.1,time: 15000});
|
||||
setTimeout(window.location.href=data.backurl, 1000);
|
||||
}else{
|
||||
setTimeout("loadmsg()", 2000);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
setTimeout("loadmsg()", 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
window.onload = function(){
|
||||
setTimeout("loadmsg()", 2000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
class alipayrp_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'alipayrp', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '支付宝现金红包', //支付插件显示名称
|
||||
'author' => '支付宝', //支付插件作者
|
||||
'link' => 'https://b.alipay.com/signing/productSetV2.htm', //支付插件作者链接
|
||||
'types' => ['alipay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '应用APPID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '应用私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '收款方支付宝UID',
|
||||
'type' => 'input',
|
||||
'note' => '留空则使用商户绑定的支付宝UID',
|
||||
],
|
||||
],
|
||||
'note' => '<p>需要签约支付宝现金红包才能使用!</p><p>使用公钥证书模式,需将<font color="red">应用公钥证书、支付宝公钥证书、支付宝根证书</font>3个crt文件放置于<font color="red">/plugins/alipayrp/cert/</font>文件夹(或<font color="red">/plugins/alipayrp/cert/应用APPID/</font>文件夹)</p><p>订阅“资金单据状态变更通知”,应用网关地址:[siteurl]pay/notify/[channel]/</p>', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $submit2;
|
||||
|
||||
if(checkalipay()){
|
||||
return ['type'=>'jump','url'=>'/pay/pagepay/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $mdevice;
|
||||
if($mdevice=='alipay'){
|
||||
return ['type'=>'jump','url'=>'/pay/pagepay/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return self::qrcode();
|
||||
}
|
||||
}
|
||||
|
||||
static private function getPayee(){
|
||||
global $order, $channel, $DB;
|
||||
|
||||
if(!empty($channel['appmchid'])) return $channel['appmchid'];
|
||||
$alipay_uid = $DB->findColumn('user', 'alipay_uid', ['uid'=>$order['uid']]);
|
||||
return $alipay_uid;
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static public function qrcode(){
|
||||
global $siteurl, $order, $DB;
|
||||
|
||||
if(empty(self::getPayee())){
|
||||
return ['type'=>'error','msg'=>'当前商户未绑定支付宝账号'];
|
||||
}
|
||||
|
||||
$code_url = $siteurl.'pay/pagepay/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//红包转账页面支付
|
||||
static public function pagepay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
if($user_type == 'openid'){
|
||||
return ['type'=>'error','msg'=>'支付宝快捷登录获取uid失败,需将用户标识切换到uid模式'];
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_biz_no' => TRADE_NO,
|
||||
'trans_amount' => $order['realmoney'],
|
||||
'product_code' => 'STD_RED_PACKET',
|
||||
'biz_scene' => 'PERSONAL_PAY',
|
||||
'order_title' => $ordername,
|
||||
'business_params' => json_encode(['sub_biz_scene'=>'REDPACKET','payer_binded_alipay_uid'=>$user_id], JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->transAppPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
$code_url = 'alipays://platformapi/startApp?appId=20000125&orderSuffix='.urlencode($result).'#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end';
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//订单查询
|
||||
static public function query($trade_no){
|
||||
global $order, $channel;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$bizContent = [
|
||||
'product_code' => 'STD_RED_PACKET',
|
||||
'biz_scene' => 'PERSONAL_PAY',
|
||||
'out_biz_no' => $trade_no
|
||||
];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTransferService($alipay_config);
|
||||
$result = $aop->aopExecute('alipay.fund.trans.common.query', $bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'订单查询失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order, $DB, $conf;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$aop = new \Alipay\AlipayTransferService($alipay_config);
|
||||
|
||||
$verify_result = $aop->client->verify($_POST);
|
||||
if($verify_result) {
|
||||
if($_POST['msg_method'] == 'alipay.fund.trans.order.changed'){
|
||||
$bizContent = json_decode($_POST['biz_content'], true);
|
||||
if($bizContent && $bizContent['product_code'] == 'STD_RED_PACKET' && $bizContent['biz_scene'] == 'PERSONAL_PAY'){
|
||||
$out_trade_no = $bizContent['out_biz_no']; //商户订单号
|
||||
$order_id = $bizContent['order_id']; //支付宝转账单据号
|
||||
$trans_amount = $bizContent['trans_amount']; //转账金额
|
||||
|
||||
$order = $DB->getRow("SELECT * FROM pre_order WHERE trade_no=:trade_no limit 1", [':trade_no'=>$out_trade_no]);
|
||||
if($order && $bizContent['status'] == 'SUCCESS'){
|
||||
if($order['settle']<=1){
|
||||
usleep(300000);
|
||||
$out_biz_no = date("YmdHis").rand(11111,99999);
|
||||
$payee_user_id = self::getPayee();
|
||||
try{
|
||||
$aop->redPacketTansfer($out_biz_no, $trans_amount, $payee_user_id, $conf['sitename'], $order_id);
|
||||
$order['settle'] = 2;
|
||||
}catch(Exception $e){
|
||||
$aop->writeLog('redPacketTansfer:'.$e->getMessage());
|
||||
$order['settle'] = 3;
|
||||
}
|
||||
}
|
||||
processNotify($order, $order_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$out_biz_no = date("YmdHis").rand(11111,99999);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTransferService($alipay_config);
|
||||
$result = $aop->redPacketRefund($out_biz_no, $order['api_trade_no'], $order['refundmoney']);
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['refund_order_id'], 'refund_fee'=>$result['refund_amount'], 'refund_time'=>$result['refund_date']];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//应用ID
|
||||
'app_id' => $channel['appid'],
|
||||
|
||||
//支付宝公钥
|
||||
'alipay_public_key' => $channel['appkey'],
|
||||
|
||||
//应用私钥
|
||||
'app_private_key' => $channel['appsecret'],
|
||||
|
||||
//子商户SMID
|
||||
'smid' => $channel['appmchid'],
|
||||
|
||||
//签名方式,默认为RSA2
|
||||
'sign_type' => "RSA2",
|
||||
|
||||
//编码格式
|
||||
'charset' => "UTF-8",
|
||||
|
||||
//支付宝网关
|
||||
'gateway_url' => "https://openapi.alipay.com/gateway.do",
|
||||
|
||||
//日志记录位置
|
||||
'log_path' => dirname(__FILE__).'/log/',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayRootCert.crt';
|
||||
}
|
||||
elseif(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayRootCert.crt';
|
||||
}
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,802 @@
|
||||
<?php
|
||||
|
||||
class alipaysl_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'alipaysl', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '支付宝官方支付服务商版', //支付插件显示名称
|
||||
'author' => '支付宝', //支付插件作者
|
||||
'link' => 'https://b.alipay.com/signing/productSetV2.htm', //支付插件作者链接
|
||||
'types' => ['alipay'], //支付插件支持的支付方式,可选的有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' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户授权token',
|
||||
'type' => 'input',
|
||||
'note' => '在第三方应用-商家授权页面获取',
|
||||
],
|
||||
],
|
||||
'select' => [ //选择已开启的支付方式
|
||||
'1' => '电脑网站支付',
|
||||
'2' => '手机网站支付',
|
||||
'3' => '当面付扫码',
|
||||
'4' => '当面付JS',
|
||||
'5' => '预授权支付',
|
||||
'6' => 'APP支付',
|
||||
'7' => 'JSAPI支付',
|
||||
'8' => '订单码支付',
|
||||
],
|
||||
'note' => '<p>在支付宝第三方应用商家授权页面,可查看商户授权token。</p><p>如果使用公钥证书模式,需将<font color="red">应用公钥证书、支付宝公钥证书、支付宝根证书</font>3个crt文件放置于<font color="red">/plugins/alipaysl/cert/</font>文件夹(或<font color="red">/plugins/alipaysl/cert/应用APPID/</font>文件夹)</p>', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $submit2, $conf, $clientip;
|
||||
|
||||
$isMobile = checkmobile();
|
||||
$isAlipay = checkalipay();
|
||||
if($isAlipay && in_array('4',$channel['apptype']) && !in_array('2',$channel['apptype'])){
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
return ['type'=>'jump','url'=>$conf['localurl_alipay'].'pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>'/pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}
|
||||
elseif($isMobile && (in_array('3',$channel['apptype'])||in_array('4',$channel['apptype'])||in_array('8',$channel['apptype'])) && !in_array('2',$channel['apptype']) || !$isMobile && !in_array('1',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
else{
|
||||
|
||||
if(checkwechat()){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/?wap=1'];
|
||||
}
|
||||
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
return ['type'=>'jump','url'=>$conf['localurl_alipay'].'pay/submit/'.TRADE_NO.'/'];
|
||||
}
|
||||
|
||||
if($isMobile && in_array('2',$channel['apptype'])){
|
||||
if($conf['alipay_wappaylogin']==1){
|
||||
if($isAlipay){
|
||||
return ['type'=>'jump','url'=>'/pay/submitwap/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
$_GET['d']='1';
|
||||
return self::submitwap();
|
||||
}elseif(in_array('1',$channel['apptype'])){
|
||||
if($conf['alipay_paymode'] == 1 || $isMobile){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcodepc/'.TRADE_NO.'/'];
|
||||
}
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$alipay_config['return_url'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
self::handleExtUser($bizContent);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$html = $aop->pagePay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'html','data'=>$html];
|
||||
}elseif(in_array('6',$channel['apptype'])){
|
||||
if($conf['alipay_wappaylogin']==1 && !$isAlipay || $isMobile && !$isAlipay){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>'/pay/apppay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(in_array('7',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/minipay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(in_array('5',$channel['apptype'])){
|
||||
if($conf['alipay_wappaylogin']==1 && !$isAlipay){
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>'/pay/preauth/'.TRADE_NO.'/?d=1'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice, $method;
|
||||
|
||||
if($method=='app'){
|
||||
return self::apppay();
|
||||
}
|
||||
elseif($method=='jsapi'){
|
||||
if(in_array('7',$channel['apptype']) && $order['is_applet'] == 1){
|
||||
return self::jsapipay();
|
||||
}else{
|
||||
return self::jspay();
|
||||
}
|
||||
}elseif($method=='scan'){
|
||||
return self::scanpay();
|
||||
}
|
||||
elseif($mdevice=='alipay' && in_array('4',$channel['apptype']) && !in_array('2',$channel['apptype'])){
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
return ['type'=>'jump','url'=>$conf['localurl_alipay'].'pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}
|
||||
elseif($device=='mobile' && (in_array('3',$channel['apptype'])||in_array('4',$channel['apptype'])||in_array('8',$channel['apptype'])) && !in_array('2',$channel['apptype']) || $device=='pc' && !in_array('1',$channel['apptype'])){
|
||||
return self::qrcode();
|
||||
}else{
|
||||
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
return ['type'=>'jump','url'=>$conf['localurl_alipay'].'pay/submit/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/submit/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static private function handleExtUser(&$bizContent){
|
||||
global $order;
|
||||
if(!empty($order['cert_no']) || !empty($order['cert_name']) || !empty($order['min_age'])){
|
||||
$ext_user_info = ['need_check_info'=>'T'];
|
||||
if(!empty($order['cert_no'])){
|
||||
$ext_user_info['cert_type'] = 'IDENTITY_CARD';
|
||||
$ext_user_info['cert_no'] = $order['cert_no'];
|
||||
}
|
||||
if(!empty($order['cert_name'])){
|
||||
$ext_user_info['name'] = $order['cert_name'];
|
||||
}
|
||||
if(!empty($order['min_age'])){
|
||||
$ext_user_info['min_age'] = $order['min_age'];
|
||||
}
|
||||
$bizContent['ext_user_info'] = $ext_user_info;
|
||||
}
|
||||
}
|
||||
|
||||
//电脑网站支付扫码
|
||||
static public function qrcodepc(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if(checkmobile()){
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$alipay_config['return_url'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
$alipay_config['pageMethod'] = '2';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'qr_pay_mode' => '4'
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
self::handleExtUser($bizContent);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$url = $aop->pagePay($bizContent);
|
||||
$html = get_curl($url, 0, 0, 0, 0, 0, 0, 0, 1);
|
||||
$html = mb_convert_encoding($html, 'utf-8', 'gbk');
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
if(preg_match('!<input name="qrCode" type="hidden" value="(.*?)"!i', $html, $match)){
|
||||
$code_url = $match[1];
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!获取二维码失败'];
|
||||
}
|
||||
|
||||
}else{
|
||||
$code_url = '/pay/submitpc/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcodepc','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//电脑网站支付扫码跳转
|
||||
static public function submitpc(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$alipay_config['return_url'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'qr_pay_mode' => '4',
|
||||
'qrcode_width' => '230'
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
self::handleExtUser($bizContent);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$html = $aop->pagePay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
$html = '<!DOCTYPE html><html><body><style>body{margin:0;padding:0}.waiting{position:absolute;width:100%;height:100%;background:#fff url(/assets/img/load.gif) no-repeat fixed center/80px;}</style><div class="waiting"></div>'.$html.'</body></html>';
|
||||
return ['type'=>'html','data'=>$html];
|
||||
}
|
||||
|
||||
//手机网站支付扫码跳转
|
||||
static public function submitwap(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
|
||||
if($conf['alipay_wappaylogin']==1 && checkalipay()){
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
}
|
||||
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
if($_GET['d']=='1'){
|
||||
$alipay_config['return_url'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$alipay_config['return_url'] = $siteurl.'pay/ok/'.TRADE_NO.'/';
|
||||
}
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
self::handleExtUser($bizContent);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$html = $aop->wapPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'html','data'=>$html];
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static public function qrcode(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $mdevice;
|
||||
if(!in_array('3',$channel['apptype']) && in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/submitwap/'.TRADE_NO.'/';
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
$code_url = $conf['localurl_alipay'].'pay/submitwap/'.TRADE_NO.'/';
|
||||
}
|
||||
if(isset($_GET['wap']) && !$conf['alipay_wappaylogin'] && checkmobile() && !checkwechat()){
|
||||
return self::submitwap();
|
||||
}
|
||||
}elseif(!in_array('3',$channel['apptype']) && in_array('4',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/jspay/'.TRADE_NO.'/';
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
$code_url = $conf['localurl_alipay'].'pay/jspay/'.TRADE_NO.'/';
|
||||
}
|
||||
}elseif(!in_array('3',$channel['apptype']) && in_array('6',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/apppay/'.TRADE_NO.'/';
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
$code_url = $conf['localurl_alipay'].'pay/apppay/'.TRADE_NO.'/';
|
||||
}
|
||||
}elseif(!in_array('3',$channel['apptype']) && in_array('7',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/minipay/'.TRADE_NO.'/';
|
||||
}elseif(!in_array('3',$channel['apptype']) && in_array('5',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/preauth/'.TRADE_NO.'/';
|
||||
if(!empty($conf['localurl_alipay']) && !strpos($conf['localurl_alipay'],$_SERVER['HTTP_HOST'])){
|
||||
$code_url = $conf['localurl_alipay'].'pay/preauth/'.TRADE_NO.'/';
|
||||
}
|
||||
}else{
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername
|
||||
];
|
||||
if(!in_array('3',$channel['apptype']) && in_array('8',$channel['apptype'])){
|
||||
$bizContent['product_code'] = 'QR_CODE_OFFLINE';
|
||||
}
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->qrPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$code_url = $result['qr_code'];
|
||||
|
||||
}
|
||||
if(checkalipay() || $mdevice=='alipay'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//APP支付
|
||||
static public function apppay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $method;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
|
||||
if($conf['alipay_wappaylogin']==1 && checkalipay()){
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
}
|
||||
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
self::handleExtUser($bizContent);
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->appPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
if($method == 'app'){
|
||||
return ['type'=>'app','data'=>$result];
|
||||
}
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
$code_url = 'alipays://platformapi/startApp?appId=20000125&orderSuffix='.urlencode($result).'#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end';
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//预授权支付
|
||||
static public function preauth(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
|
||||
if($conf['alipay_wappaylogin']==1 && checkalipay()){
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
}
|
||||
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/preauthnotify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_order_no' => TRADE_NO,
|
||||
'out_request_no' => TRADE_NO,
|
||||
'order_title' => $ordername,
|
||||
'amount' => $order['realmoney'],
|
||||
'product_code' => 'PREAUTH_PAY'
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->preAuthFreeze($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
$code_url = 'alipays://platformapi/startApp?appId=20000125&orderSuffix='.urlencode($result).'#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end';
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//当面付JS支付
|
||||
static public function jspay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $method;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
|
||||
if(!empty($order['sub_openid'])){
|
||||
$user_id = $order['sub_openid'];
|
||||
$user_type = is_numeric($user_id) && substr($user_id, 0, 4) == '2088' ? 'userid' : 'openid';
|
||||
}else{
|
||||
[$user_type, $user_id] = alipay_oauth($alipay_config);
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername
|
||||
];
|
||||
if($user_type == 'userid'){
|
||||
$bizContent['buyer_id'] = $user_id;
|
||||
}else{
|
||||
$bizContent['buyer_open_id'] = $user_id;
|
||||
}
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->jsPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$alipay_trade_no = $result['trade_no'];
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$alipay_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'=>$alipay_trade_no, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//JSAPI支付
|
||||
static public function jsapipay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $method;
|
||||
|
||||
$user_id = $order['sub_openid'];
|
||||
$user_type = is_numeric($user_id) && substr($user_id, 0, 4) == '2088' ? 'userid' : 'openid';
|
||||
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'product_code' => 'JSAPI_PAY',
|
||||
'op_app_id' => $order['sub_appid'] ? $order['sub_appid'] : $alipay_config['app_id']
|
||||
];
|
||||
if($user_type == 'openid'){
|
||||
$bizContent['buyer_open_id'] = $user_id;
|
||||
}else{
|
||||
$bizContent['buyer_id'] = $user_id;
|
||||
}
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->jsPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$alipay_trade_no = $result['trade_no'];
|
||||
return ['type'=>'jsapi','data'=>$alipay_trade_no];
|
||||
}
|
||||
|
||||
//支付宝小程序支付
|
||||
static public function alipaymini(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$auth_code = isset($_GET['auth_code'])?trim($_GET['auth_code']):exit('{"code":-1,"msg":"auth_code不能为空"}');
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
|
||||
try{
|
||||
[$app_id, $user_type, $user_id] = alipay_mini_oauth($auth_code, $alipay_config);
|
||||
}catch(Exception $e){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>$e->getMessage()]));
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($user_id, TRADE_NO);
|
||||
if($blocks)exit('{"code":-1,"msg":"'.$blocks['msg'].'"}');
|
||||
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'product_code' => 'JSAPI_PAY',
|
||||
'op_app_id' => $app_id
|
||||
];
|
||||
if($user_type == 'openid'){
|
||||
$bizContent['buyer_open_id'] = $user_id;
|
||||
}else{
|
||||
$bizContent['buyer_id'] = $user_id;
|
||||
}
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->jsPay($bizContent);
|
||||
$alipay_trade_no = $result['trade_no'];
|
||||
}catch(Exception $e){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'支付宝下单失败!'.$e->getMessage()]));
|
||||
}
|
||||
exit(json_encode(['code'=>0, 'data'=>$alipay_trade_no]));
|
||||
}
|
||||
|
||||
//H5跳转小程序支付
|
||||
static public function minipay(){
|
||||
global $siteurl, $channel, $conf;
|
||||
|
||||
$code_url = alipaymini_jump_scheme(TRADE_NO, $channel['appid']);
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'alipay_h5','data'=>['code_url'=>$code_url, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//付款码支付
|
||||
static public function scanpay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'auth_code' => $order['auth_code'],
|
||||
'scene' => 'bar_code',
|
||||
];
|
||||
$bizContent['business_params'] = ['mc_create_trade_ip' => $clientip];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->scanPay($bizContent);
|
||||
if(!empty($result['buyer_user_id'])){
|
||||
$buyer_id = $result['buyer_user_id'];
|
||||
}else{
|
||||
$buyer_id = $result['buyer_open_id'];
|
||||
}
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>$result['out_trade_no'], 'api_trade_no'=>$result['trade_no'], 'buyer'=>$buyer_id, 'money'=>$result['total_amount']]];
|
||||
}catch(\Alipay\Aop\AlipayResponseException $e){
|
||||
$code = $e->getRetCode();
|
||||
if($code == '10003' || $code == '20000'){
|
||||
if($code == '10003') sleep(2);
|
||||
$retry = 0;
|
||||
$success = false;
|
||||
while($retry < 6){
|
||||
sleep(3);
|
||||
try{
|
||||
$result = $aop->query(null, TRADE_NO);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝支付失败!订单查询失败:'.$e->getMessage()];
|
||||
}
|
||||
if($result['trade_status'] == 'TRADE_SUCCESS'){
|
||||
$success = true;
|
||||
break;
|
||||
}elseif($result['trade_status'] != 'WAIT_BUYER_PAY'){
|
||||
return ['type'=>'error','msg'=>'支付宝支付失败!订单超时或用户取消支付'];
|
||||
}
|
||||
$retry++;
|
||||
}
|
||||
if($success){
|
||||
if(!empty($result['buyer_user_id'])){
|
||||
$buyer_id = $result['buyer_user_id'];
|
||||
}else{
|
||||
$buyer_id = $result['buyer_open_id'];
|
||||
}
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>$result['out_trade_no'], 'api_trade_no'=>$result['trade_no'], 'buyer'=>$buyer_id, 'money'=>$result['total_amount']]];
|
||||
}else{
|
||||
try{
|
||||
$aop->cancel(['out_trade_no'=>TRADE_NO]);
|
||||
}catch(Exception $e){
|
||||
}
|
||||
return ['type'=>'error','msg'=>'支付宝支付失败!订单已超时'];
|
||||
}
|
||||
}
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
|
||||
$verify_result = $aop->client->verify($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_POST['out_trade_no'];
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = $_POST['trade_no'];
|
||||
|
||||
//买家支付宝
|
||||
$buyer_id = $_POST['buyer_id'];
|
||||
if(empty($buyer_id))$buyer_id = $_POST['buyer_open_id'];
|
||||
|
||||
//交易金额
|
||||
$total_amount = $_POST['total_amount'];
|
||||
|
||||
if($_POST['trade_status'] == 'TRADE_FINISHED') {
|
||||
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
|
||||
}
|
||||
else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if($out_trade_no == TRADE_NO && round($total_amount,2)==round($order['realmoney'],2)){
|
||||
processNotify($order, $trade_no, $buyer_id);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
|
||||
$verify_result = $aop->client->verify($_GET);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//交易金额
|
||||
$total_amount = $_GET['total_amount'];
|
||||
|
||||
if($out_trade_no == TRADE_NO && round($total_amount,2)==round($order['realmoney'],2)){
|
||||
processReturn($order, $trade_no);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'error','msg'=>'支付宝返回验证失败'];
|
||||
}
|
||||
}
|
||||
|
||||
//预授权支付回调
|
||||
static public function preauthnotify(){
|
||||
global $channel, $order, $conf, $ordername, $clientip;
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$alipay_config['notify_url'] = $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$aop = new \Alipay\AlipayService($alipay_config);
|
||||
|
||||
$verify_result = $aop->client->verify($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_POST['out_order_no'];
|
||||
|
||||
//资金授权订单号
|
||||
$auth_no = $_POST['auth_no'];
|
||||
|
||||
$buyer_id = $result['payer_user_id'];
|
||||
|
||||
if($out_trade_no == TRADE_NO){
|
||||
$bizContent = [
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'subject' => $ordername,
|
||||
'product_code' => 'PREAUTH_PAY',
|
||||
'auth_no' => $auth_no,
|
||||
'auth_confirm_mode' => 'COMPLETE'
|
||||
];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->scanPay($bizContent);
|
||||
}catch(Exception $e){
|
||||
\lib\Payment::updateOrder(TRADE_NO, $auth_no, $buyer_id, 4);
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
//return ['type'=>'error','msg'=>'支付宝下单失败!'.$e->getMessage()];
|
||||
}
|
||||
$trade_no = $result['trade_no'];
|
||||
$buyer_id = $result['buyer_user_id'];
|
||||
$total_amount = $result['total_amount'];
|
||||
|
||||
processNotify($order, $trade_no, $buyer_id);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$bizContent = [
|
||||
'trade_no' => $order['api_trade_no'],
|
||||
'refund_amount' => $order['refundmoney'],
|
||||
'out_request_no' => $order['refund_no']
|
||||
];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$result = $aop->refund($bizContent);
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['trade_no'], 'refund_fee'=>$result['refund_fee'], 'refund_time'=>$result['gmt_refund_pay'], 'buyer'=>$result['buyer_user_id']];
|
||||
}
|
||||
|
||||
//关闭订单
|
||||
static public function close($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$bizContent = [
|
||||
'out_trade_no' => $order['trade_no'],
|
||||
];
|
||||
try{
|
||||
$aop = new \Alipay\AlipayTradeService($alipay_config);
|
||||
$aop->close($bizContent);
|
||||
return ['code'=>0];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝应用网关
|
||||
static public function appgw(){
|
||||
global $channel,$DB;
|
||||
$alipay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$aop = new \Alipay\AlipayService($alipay_config);
|
||||
$verify_result = $aop->client->verify($_POST);
|
||||
if($verify_result){
|
||||
if($_POST['msg_method'] == 'alipay.merchant.tradecomplain.changed'){
|
||||
$bizContent = json_decode($_POST['biz_content'], true);
|
||||
if($bizContent && isset($bizContent['complain_event_id'])){
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($bizContent['complain_event_id']);
|
||||
}
|
||||
}elseif($_POST['notify_type'] == 'open_app_auth_notify'){
|
||||
$bizContent = json_decode($_POST['biz_content'], true);
|
||||
if($bizContent && isset($bizContent['detail']['app_auth_token'])){
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
$model->callback($bizContent);
|
||||
}
|
||||
}
|
||||
/*if($_POST['service']=='alipay.adatabus.risk.end.push' || $_POST['service']=='alipay.riskgo.risk.push'){
|
||||
if($_POST['charset'] == 'GBK'){
|
||||
$_POST['risktype'] = mb_convert_encoding($_POST['risktype'], "UTF-8", "GBK");
|
||||
$_POST['risklevel'] = mb_convert_encoding($_POST['risklevel'], "UTF-8", "GBK");
|
||||
$_POST['riskDesc'] = mb_convert_encoding($_POST['riskDesc'], "UTF-8", "GBK");
|
||||
$_POST['complainText'] = mb_convert_encoding($_POST['complainText'], "UTF-8", "GBK");
|
||||
}
|
||||
$DB->exec("INSERT INTO `pre_alipayrisk` (`channel`,`pid`,`smid`,`tradeNos`,`risktype`,`risklevel`,`riskDesc`,`complainTime`,`complainText`,`date`,`status`) VALUES (:channel, :pid, :smid, :tradeNos, :risktype, :risklevel, :riskDesc, :complainTime, :complainText, NOW(), 0)", [':channel'=>$channelid, ':pid'=>$_POST['pid'], ':smid'=>$_POST['smid']?$_POST['smid']:$_POST['merchantId'], ':tradeNos'=>$_POST['tradeNos'], ':risktype'=>$_POST['risktype'], ':risklevel'=>$_POST['risklevel'], ':riskDesc'=>$_POST['riskDesc'], ':complainTime'=>$_POST['complainTime'], ':complainText'=>$_POST['complainText']]);
|
||||
}*/
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'check sign fail'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
$alipay_config = [
|
||||
//应用ID
|
||||
'app_id' => $channel['appid'],
|
||||
|
||||
//支付宝公钥
|
||||
'alipay_public_key' => $channel['appkey'],
|
||||
|
||||
//应用私钥
|
||||
'app_private_key' => $channel['appsecret'],
|
||||
|
||||
//商户授权token
|
||||
'app_auth_token' => $channel['appmchid'],
|
||||
|
||||
//签名方式,默认为RSA2
|
||||
'sign_type' => "RSA2",
|
||||
|
||||
//编码格式
|
||||
'charset' => "UTF-8",
|
||||
|
||||
//支付宝网关
|
||||
'gateway_url' => "https://openapi.alipay.com/gateway.do",
|
||||
|
||||
//日志记录位置
|
||||
'log_path' => dirname(__FILE__).'/log/',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appid'].'/alipayRootCert.crt';
|
||||
}
|
||||
elseif(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt')){
|
||||
$alipay_config['app_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/appCertPublicKey_'.$channel['appid'].'.crt';
|
||||
$alipay_config['alipay_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayCertPublicKey_RSA2.crt';
|
||||
$alipay_config['root_cert_path'] = PLUGIN_ROOT.$channel['plugin'].'/cert/alipayRootCert.crt';
|
||||
}
|
||||
return $alipay_config;
|
||||
@@ -0,0 +1,579 @@
|
||||
<?php
|
||||
|
||||
class allinpay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'allinpay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '通联支付', //支付插件显示名称
|
||||
'author' => '通联', //支付插件作者
|
||||
'link' => 'https://www.allinpay.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','qqpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appmchid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appid' => [
|
||||
'name' => '应用ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '通联公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'orgid' => [
|
||||
'name' => '代理商商户号',
|
||||
'type' => 'input',
|
||||
'note' => '仅代理商需要填写',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
],
|
||||
'select_bank' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'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){
|
||||
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
|
||||
}
|
||||
}elseif($order['typename']=='qqpay'){
|
||||
return ['type'=>'jump','url'=>'/pay/qqpay/'.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']=='bank'){
|
||||
return self::bankjs();
|
||||
}
|
||||
}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']=='qqpay'){
|
||||
return self::qqpay();
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//统一支付接口
|
||||
static private function addOrder($paytype, $sub_appid = null, $openid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$apiurl = 'https://vsp.allinpay.com/apiweb/unitorder/pay';
|
||||
|
||||
$params = [
|
||||
'trxamt' => strval($order['realmoney']*100),
|
||||
'reqsn' => TRADE_NO,
|
||||
'paytype' => $paytype,
|
||||
'body' => $ordername,
|
||||
'validtime' => '30',
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'cusip' => $clientip,
|
||||
];
|
||||
if($sub_appid) $params['sub_appid'] = $sub_appid;
|
||||
if($openid){
|
||||
$params['acct'] = $openid;
|
||||
$params['front_url'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
}
|
||||
if($order['profits'] > 0){
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$asinfo = '';
|
||||
foreach($psreceiver['info'] as $receiver) {
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']));
|
||||
$asinfo .= $receiver['account'].':01:'.$psmoney.';';
|
||||
}
|
||||
$asinfo = rtrim($asinfo, ';');
|
||||
}
|
||||
}
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->submit($apiurl, $params);
|
||||
if($result['trxstatus'] == '0000') {
|
||||
return $result['payinfo'];
|
||||
}else{
|
||||
throw new Exception($result['errmsg']);
|
||||
}
|
||||
}
|
||||
|
||||
//H5收银台
|
||||
static private function cashier(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$apiurl = 'https://syb.allinpay.com/apiweb/h5unionpay/unionorder';
|
||||
|
||||
$params = [
|
||||
'trxamt' => strval($order['realmoney']*100),
|
||||
'reqsn' => TRADE_NO,
|
||||
'body' => $ordername,
|
||||
'validtime' => '30',
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'returl' => $siteurl . 'pay/return/' . TRADE_NO . '/',
|
||||
'charset' => 'UTF-8',
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$asinfo = '';
|
||||
foreach($psreceiver['info'] as $receiver) {
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']));
|
||||
$asinfo .= $receiver['account'].':01:'.$psmoney.';';
|
||||
}
|
||||
$asinfo = rtrim($asinfo, ';');
|
||||
}
|
||||
}
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$data = $client->cashier($params);
|
||||
|
||||
$html_text = '<form action="'.$apiurl.'" method="post" id="dopay">';
|
||||
foreach($data as $k => $v) {
|
||||
$html_text .= "<input type=\"hidden\" name=\"{$k}\" value=\"{$v}\" />\n";
|
||||
}
|
||||
$html_text .= '<input type="submit" value="正在跳转"></form><script>document.getElementById("dopay").submit();</script>';
|
||||
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
|
||||
//小程序收银台
|
||||
static private function applet($paytype){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$params = [
|
||||
'trxamt' => strval($order['realmoney']*100),
|
||||
'reqsn' => TRADE_NO,
|
||||
'paytype' => $paytype,
|
||||
'body' => $ordername,
|
||||
'validtime' => '30',
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$asinfo = '';
|
||||
foreach($psreceiver['info'] as $receiver) {
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']));
|
||||
$asinfo .= $receiver['account'].':01:'.$psmoney.';';
|
||||
}
|
||||
$asinfo = rtrim($asinfo, ';');
|
||||
}
|
||||
}
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$data = $client->cashier($params);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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('A01');
|
||||
}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 $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{
|
||||
$alipay_trade_no = self::addOrder('A02', null, $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$alipay_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'=>$alipay_trade_no, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $siteurl, $device, $mdevice;
|
||||
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
if($channel['appwxmp']>0){
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::addOrder('W01');
|
||||
}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 wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
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 wxjspay(){
|
||||
global $siteurl, $channel, $method, $order;
|
||||
|
||||
//①、获取用户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 ? 'W06' : 'W02', $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 wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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{
|
||||
$payinfo = self::addOrder('W06', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($payinfo, true)]));
|
||||
}
|
||||
|
||||
//QQ扫码支付
|
||||
static public function qqpay(){
|
||||
try{
|
||||
$code_url = self::addOrder('Q01');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'QQ钱包支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if(checkmobbileqq()){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
} elseif(checkmobile() && !isset($_GET['qrcode'])){
|
||||
return ['type'=>'qrcode','page'=>'qqpay_wap','url'=>$code_url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'qqpay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::addOrder('U01');
|
||||
}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];
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付JS支付
|
||||
static public function bankjs(){
|
||||
global $order;
|
||||
try{
|
||||
$code_url = self::addOrder('U02', null, $order['sub_openid']);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}
|
||||
|
||||
static public function get_unionpay_userid($channel, $userAuthCode){
|
||||
require_once(PLUGIN_ROOT."allinpay/inc/PayService.class.php");
|
||||
|
||||
$apiurl = 'https://vsp.allinpay.com/apiweb/unitorder/authcodetouserid';
|
||||
$params = [
|
||||
'authcode' => $userAuthCode,
|
||||
'authtype' => '02',
|
||||
'identify' => get_unionpay_ua(),
|
||||
];
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
try{
|
||||
$result = $client->submit($apiurl, $params);
|
||||
return ['code'=>0, 'data'=>$result['acct']];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1,'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->verifySign($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
if ($_POST['trxstatus'] == '0000') {
|
||||
$out_trade_no = $_POST['cusorderid'];
|
||||
$api_trade_no = $_POST['trxid'];
|
||||
$money = $_POST['initamt'];
|
||||
$buyer = $_POST['acct'];
|
||||
$bill_trade_no = $_POST['chnltrxid'];
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$apiurl = 'https://vsp.allinpay.com/apiweb/tranx/refund';
|
||||
|
||||
$params = [
|
||||
'trxamt' => strval($order['refundmoney']*100),
|
||||
'reqsn' => $order['refund_no'],
|
||||
'oldtrxid' => $order['api_trade_no'],
|
||||
];
|
||||
|
||||
try{
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->submit($apiurl, $params);
|
||||
if($result['trxstatus']!='0000'&&$result['trxstatus']!='2008'&&$result['trxstatus']!='2000'){
|
||||
return ['code'=>-1, 'msg'=>$result['errmsg']];
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['trxid'], 'refund_fee'=>$result['fee']];
|
||||
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//投诉通知
|
||||
static public function complainnotify(){
|
||||
global $channel;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->verifySign($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$data = json_decode($_POST['resource'], true);
|
||||
if($_POST['risktype'] == 'VIOLATION'){
|
||||
if(class_exists('\\lib\\WxMchRisk')){
|
||||
$model = new \lib\WxMchRisk($channel);
|
||||
$model->notify($data);
|
||||
}
|
||||
}elseif($_POST['risktype'] == 'COMPLAINT'){
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($data['complaint_id'], $data['action_type']);
|
||||
}elseif($_POST['risktype'] == 'COMPLAINTV2'){
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($data['complaint_id']);
|
||||
}
|
||||
|
||||
return ['type'=>'html','data'=>'sccuess'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//进件通知
|
||||
static public function applynotify(){
|
||||
global $channel;
|
||||
|
||||
require_once(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$client = new PayService($channel['orgid'],$channel['appmchid'],$channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->verifySign($_POST);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($_POST);
|
||||
|
||||
return ['type'=>'html','data'=>'sccuess'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://prodoc.allinpay.com/
|
||||
*/
|
||||
class PayService
|
||||
{
|
||||
private $sign_type = 'RSA';
|
||||
private $version = '11';
|
||||
private $orgid;
|
||||
private $cusid;
|
||||
private $appid;
|
||||
private $platform_public_key;
|
||||
private $merchant_private_key;
|
||||
|
||||
public function __construct($orgid, $cusid, $appid, $platform_public_key, $merchant_private_key)
|
||||
{
|
||||
$this->orgid = $orgid;
|
||||
$this->cusid = $cusid;
|
||||
$this->appid = $appid;
|
||||
$this->platform_public_key = $platform_public_key;
|
||||
$this->merchant_private_key = $merchant_private_key;
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function submit($requrl, $params, $file = false){
|
||||
$public_params = [
|
||||
'orgid' => $this->orgid,
|
||||
'appid' => $this->appid,
|
||||
'cusid' => $this->cusid,
|
||||
'version' => $this->version,
|
||||
'randomstr' => getSid(),
|
||||
'signtype' => $this->sign_type,
|
||||
];
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->generateSign($params);
|
||||
|
||||
$response = get_curl($requrl, $file ? $params : http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['retcode']) && $result['retcode']=='SUCCESS'){
|
||||
return $result;
|
||||
}elseif(isset($result['retmsg'])){
|
||||
throw new Exception($result['retmsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//获取收银台参数
|
||||
public function cashier($params){
|
||||
$public_params = [
|
||||
'orgid' => $this->orgid,
|
||||
'cusid' => $this->cusid,
|
||||
'appid' => $this->appid,
|
||||
'version' => '12',
|
||||
'randomstr' => getSid(),
|
||||
'signtype' => $this->sign_type,
|
||||
];
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->generateSign($params);
|
||||
return $params;
|
||||
}
|
||||
|
||||
//获取待签名字符串
|
||||
private function getSignContent($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && !$v instanceof \CURLFile && $v!=='' && $v!==null){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr,0,-1);
|
||||
return $signstr;
|
||||
}
|
||||
|
||||
//请求参数签名
|
||||
private function generateSign($param){
|
||||
return $this->rsaPrivateSign($this->getSignContent($param));
|
||||
}
|
||||
|
||||
//验签方法
|
||||
public function verifySign($param){
|
||||
if(empty($param['sign'])) return false;
|
||||
return $this->rsaPubilcVerify($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);
|
||||
$signature = base64_encode($signature);
|
||||
return $signature;
|
||||
}
|
||||
|
||||
//平台公钥验签
|
||||
private function rsaPubilcVerify($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);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,679 @@
|
||||
<?php
|
||||
|
||||
class baofu_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'baofu', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '宝付支付', //支付插件显示名称
|
||||
'author' => '宝付', //支付插件作者
|
||||
'link' => 'https://www.baofu.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'transtypes' => ['bank'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appurl' => [
|
||||
'name' => '终端号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '私钥密码',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '聚合交易商户号',
|
||||
'type' => 'input',
|
||||
'note' => '在微信/支付宝报备的商户号',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '聚合码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
],
|
||||
'select_bank' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'note' => '需要将商户私钥证书client.pfx(或商户号.pfx)放到 /plugins/baofu/cert/ 文件夹下', //支付密钥填写说明
|
||||
'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() && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile() && $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']=='bank'){
|
||||
return self::bankjs();
|
||||
}
|
||||
}elseif($order['typename']=='alipay'){
|
||||
if($mdevice=='alipay' && in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/alipayjs/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return self::alipay();
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($mdevice=='wechat' && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile' && $channel['appwxa']>0){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//统一下单
|
||||
static private function addOrder($pay_code, $sub_openid = null, $sub_appid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
$subMchId = $channel['appmchid'];
|
||||
if(strpos($subMchId, '|')){
|
||||
$subMchIds = explode('|', $subMchId);
|
||||
$subMchId = $subMchIds[array_rand($subMchIds)];
|
||||
}
|
||||
|
||||
require_once PAY_ROOT.'inc/BaofuClient.php';
|
||||
|
||||
if($pay_code == 'WECHAT_JSAPI'){
|
||||
$pay_extend = [
|
||||
'body' => $ordername,
|
||||
'area_info' => '110101',
|
||||
'sub_appid' => $sub_appid,
|
||||
'sub_openid' => $sub_openid,
|
||||
];
|
||||
}elseif($pay_code == 'WECHAT_APP'){
|
||||
$pay_extend = [
|
||||
'body' => $ordername,
|
||||
'area_info' => '110101',
|
||||
'sub_appid' => $sub_appid,
|
||||
];
|
||||
}elseif($pay_code == 'WECHAT_MICROPAY'){
|
||||
$pay_extend = [
|
||||
'body' => $ordername,
|
||||
'area_info' => '110101',
|
||||
'auth_code' => $order['auth_code'],
|
||||
];
|
||||
}elseif($pay_code == 'ALIPAY_NATIVE'){
|
||||
$pay_extend = [
|
||||
'subject' => $ordername,
|
||||
];
|
||||
}elseif($pay_code == 'ALIPAY_JSAPI'){
|
||||
$pay_extend = [
|
||||
'subject' => $ordername,
|
||||
'buyer_id' => $sub_openid,
|
||||
];
|
||||
}elseif($pay_code == 'ALIPAY_MICROPAY'){
|
||||
$pay_extend = [
|
||||
'subject' => $ordername,
|
||||
'auth_code' => $order['auth_code'],
|
||||
];
|
||||
}elseif($pay_code == 'QUICK_PASS_NATIVE'){
|
||||
$pay_extend = [
|
||||
'areaInfo' => '1560001',
|
||||
];
|
||||
}elseif($pay_code == 'QUICK_PASS_NATIVE_JS'){
|
||||
$pay_extend = [
|
||||
'userId' => $sub_openid,
|
||||
'areaInfo' => '1560001',
|
||||
'customerIp' => $clientip,
|
||||
'orderDesc' => $ordername,
|
||||
];
|
||||
}
|
||||
|
||||
$params = [
|
||||
'merId' => $channel['appid'],
|
||||
'terId' => $channel['appurl'],
|
||||
'outTradeNo' => TRADE_NO,
|
||||
'txnAmt' => intval(round($order['realmoney'] * 100)),
|
||||
'txnTime' => date('YmdHis'),
|
||||
'totalAmt' => intval(round($order['realmoney'] * 100)),
|
||||
'prodType' => 'ORDINARY',
|
||||
//'orderType' => '7',
|
||||
'payCode' => $pay_code,
|
||||
'payExtend' => $pay_extend,
|
||||
'subMchId' => $subMchId,
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'pageUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'riskInfo' => ['clientIp'=>$clientip],
|
||||
];
|
||||
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('unified_order', $params);
|
||||
if($result['resultCode'] == 'SUCCESS'){
|
||||
return $result['chlRetParam'];
|
||||
}else{
|
||||
throw new Exception('['.$result['errCode'].']'.$result['errMsg']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static private function qrcode($pay_code){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
$subMchId = $channel['appmchid'];
|
||||
if(strpos($subMchId, '|')){
|
||||
$subMchIds = explode('|', $subMchId);
|
||||
$subMchId = $subMchIds[array_rand($subMchIds)];
|
||||
}
|
||||
|
||||
require_once PAY_ROOT.'inc/BaofuClient.php';
|
||||
|
||||
$pay_extend = [
|
||||
'goods_name' => $ordername,
|
||||
'merchant_name' => '聚合商户',
|
||||
'area_info' => '110101',
|
||||
];
|
||||
if($pay_code == 'WECHAT_JSAPI'){
|
||||
$pay_extend['wechat_sub_member_id'] = $subMchId;
|
||||
}else{
|
||||
$pay_extend['alipay_sub_member_id'] = $subMchId;
|
||||
}
|
||||
$params = [
|
||||
'merId' => $channel['appid'],
|
||||
'terId' => $channel['appurl'],
|
||||
'outTradeNo' => TRADE_NO,
|
||||
'txnAmt' => intval(round($order['realmoney'] * 100)),
|
||||
'txnTime' => date('YmdHis'),
|
||||
'totalAmt' => intval(round($order['realmoney'] * 100)),
|
||||
'prodType' => 'ORDINARY',
|
||||
//'orderType' => '7',
|
||||
'cashierFlag' => '0',
|
||||
'payCode' => $pay_code,
|
||||
'payExtend' => $pay_extend,
|
||||
'subMchId' => $subMchId,
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'pageUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'riskInfo' => ['clientIp'=>$clientip],
|
||||
];
|
||||
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('pre_unified_order', $params);
|
||||
if($result['resultCode'] == 'SUCCESS'){
|
||||
return $result['token'];
|
||||
}else{
|
||||
throw new Exception('['.$result['errCode'].']'.$result['errMsg']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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{
|
||||
$result = self::addOrder('ALIPAY_NATIVE');
|
||||
$code_url = $result['qr_code'];
|
||||
}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{
|
||||
$result = self::addOrder('ALIPAY_JSAPI', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['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'=>$result['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{
|
||||
$code_url = self::qrcode('WECHAT_JSAPI');
|
||||
}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, $ordername, $conf, $method;
|
||||
|
||||
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_JSAPI', $openid, $wxinfo['appid']);
|
||||
$pay_info = $result['wc_pay_data'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$pay_info];
|
||||
}
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$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{
|
||||
$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_JSAPI', $openid, $wxinfo['appid']);
|
||||
$pay_info = $result['wc_pay_data'];
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'微信支付下单失败 '.$ex->getMessage()]));
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($pay_info, 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(){
|
||||
try{
|
||||
$code_url = self::addOrder('QUICK_PASS_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 bankjs(){
|
||||
global $method, $order;
|
||||
try{
|
||||
$result = self::addOrder('QUICK_PASS_NATIVE_JS', $order['sub_openid']);
|
||||
$code_url = $result['redirectUrl'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}
|
||||
|
||||
static public function get_unionpay_userid($channel, $userAuthCode){
|
||||
require_once PLUGIN_ROOT.'baofu/inc/BaofuClient.php';
|
||||
|
||||
$param = [
|
||||
'merId' => $channel['appid'],
|
||||
'terId' => $channel['appurl'],
|
||||
'userAuthCode' => $userAuthCode,
|
||||
'appUpIdentifier' => get_unionpay_ua(),
|
||||
];
|
||||
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
try{
|
||||
$result = $client->execute('quick_pass_auth', $param);
|
||||
if($result['resultCode'] == 'SUCCESS'){
|
||||
return ['code'=>0, 'data'=>$result['userId']];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>'['.$result['errCode'].']'.$result['errMsg']];
|
||||
}
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1,'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
if(!isset($_POST['dataContent'])) return ['type'=>'html','data'=>'NO'];
|
||||
|
||||
require_once PAY_ROOT.'inc/BaofuClient.php';
|
||||
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
$verify_result = $client->verifyNotify($_POST['dataContent'], $_POST['signStr']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$params = json_decode($_POST['dataContent'], true);
|
||||
if ($params['txnState'] == 'SUCCESS') {
|
||||
if($params['outTradeNo'] == TRADE_NO){
|
||||
if(strpos($params['payCode'], 'ALIPAY_') !== false){
|
||||
$buyer = $params['chlRetParam']['buyer_id'];
|
||||
$bill_trade_no = $params['chlRetParam']['trade_no'];
|
||||
}elseif(strpos($params['payCode'], 'WECHAT_') !== false){
|
||||
$buyer = null;
|
||||
$bill_trade_no = $params['chlRetParam']['transaction_id'];
|
||||
}elseif(strpos($params['payCode'], 'QUICK_PASS_') !== false){
|
||||
$buyer = null;
|
||||
$bill_trade_no = $params['chlRetParam']['voucherNum'];
|
||||
}
|
||||
$bill_mch_trade_no = $params['reqChlNo'];
|
||||
/*if(!empty($channel['share_merid'])){
|
||||
self::share($client, $params['tradeNo']);
|
||||
}*/
|
||||
processNotify($order, $params['tradeNo'], $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'OK'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'FAIL'];
|
||||
}
|
||||
}
|
||||
|
||||
static private function share($client, $originTradeNo){
|
||||
global $channel, $order;
|
||||
$param = [
|
||||
'merId' => $channel['appid'],
|
||||
'terId' => $channel['appurl'],
|
||||
'originTradeNo' => $originTradeNo,
|
||||
'txnTime' => date('YmdHis'),
|
||||
'outTradeNo' => TRADE_NO,
|
||||
'sharingDetails' => [
|
||||
[
|
||||
'sharingMerId' => $channel['share_merid'],
|
||||
'sharingAmt' => intval(round($order['realmoney'] * 100)),
|
||||
]
|
||||
],
|
||||
];
|
||||
usleep(500000);
|
||||
try{
|
||||
$result = $client->execute('share_after_pay', $param);
|
||||
if($result['resultCode'] == 'SUCCESS'){
|
||||
return ['code'=>0];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>'['.$result['errCode'].']'.$result['errMsg']];
|
||||
}
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $conf;
|
||||
if(empty($order))exit();
|
||||
|
||||
require_once PAY_ROOT.'inc/BaofuClient.php';
|
||||
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
$param = [
|
||||
'merId' => $channel['appid'],
|
||||
'terId' => $channel['appurl'],
|
||||
'originTradeNo' => $order['api_trade_no'],
|
||||
'outTradeNo' => $order['refund_no'],
|
||||
'refundAmt' => intval(round($order['refundmoney'] * 100)),
|
||||
'totalAmt' => intval(round($order['refundmoney'] * 100)),
|
||||
'txnTime' => date('YmdHis'),
|
||||
'refundReason' => '申请退款',
|
||||
];
|
||||
|
||||
try{
|
||||
$result = $client->execute('order_refund', $param);
|
||||
if($result['resultCode'] == 'SUCCESS'){
|
||||
return ['code'=>0, 'trade_no'=>$result['tradeNo'], 'refund_fee'=>$result['refundAmt']/100];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>'['.$result['errCode'].']'.$result['errMsg']];
|
||||
}
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//进件通知
|
||||
static public function applynotify(){
|
||||
global $channel;
|
||||
|
||||
if(!isset($_POST['data_content'])) {
|
||||
return ['type'=>'html','data'=>'NO'];
|
||||
}
|
||||
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($_POST['data_content']);
|
||||
|
||||
return ['type'=>'html','data'=>'OK'];
|
||||
}
|
||||
|
||||
//转账
|
||||
static public function transfer($channel, $bizParam){
|
||||
global $conf, $clientip;
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
try{
|
||||
$bank_info = getBankCardInfo($bizParam['payee_account']);
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
require_once(PLUGIN_ROOT.'baofu/inc/BaofuClient.php');
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
$params = [
|
||||
'trans_content' => ['trans_reqDatas'=>[['trans_reqData'=>[[
|
||||
'trans_no' => $bizParam['out_biz_no'],
|
||||
'trans_money' => $bizParam['money'],
|
||||
'to_acc_name' => $bizParam['payee_real_name'],
|
||||
'to_acc_no' => $bizParam['payee_account'],
|
||||
'to_bank_name' => $bank_info['bank_name'],
|
||||
]]]]],
|
||||
];
|
||||
|
||||
try{
|
||||
$result = $client->transfer('BF0040001', $params);
|
||||
$info = $result[0]['trans_reqData'][0];
|
||||
return ['code'=>0, 'status'=>0, 'orderid'=>$info['trans_batchid'], 'paydate'=>date('Y-m-d H:i:s')];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//转账查询
|
||||
static public function transfer_query($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require_once(PLUGIN_ROOT.'baofu/inc/BaofuClient.php');
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
$params = [
|
||||
'trans_content' => ['trans_reqDatas'=>[['trans_reqData'=>[[
|
||||
'trans_no' => $bizParam['out_biz_no']
|
||||
]]]]],
|
||||
];
|
||||
try{
|
||||
$result = $client->transfer('BF0040002', $params);
|
||||
$info = $result[0]['trans_reqData'][0];
|
||||
if($info['state'] == '1'){
|
||||
$status = 1;
|
||||
}elseif($info['trade_status'] == '-1' || $info['trade_status'] == '2'){
|
||||
$status = 2;
|
||||
$errmsg = $info['trans_remark'];
|
||||
}else{
|
||||
$status = 0;
|
||||
}
|
||||
return ['code'=>0, 'status'=>$status, 'errmsg'=>$errmsg];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//电子回单
|
||||
static public function transfer_proof($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require_once(PLUGIN_ROOT.'baofu/inc/BaofuClient.php');
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
$params = [
|
||||
'memberTransId' => $bizParam['out_biz_no'],
|
||||
'fileType' => '2',
|
||||
'transferDate' => substr($bizParam['out_biz_no'], 0, 4).'-'.substr($bizParam['out_biz_no'], 4, 2).'-'.substr($bizParam['out_biz_no'], 6, 2),
|
||||
'orderType' => '0',
|
||||
'version' => 'V1.1',
|
||||
];
|
||||
try{
|
||||
$result = $client->submit('T-1001-003-03', $params);
|
||||
if($result['state'] == '0000'){
|
||||
return ['code'=>0, 'msg'=>'电子回单生成成功!', 'download_url'=>$result['urlDownload']];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>'电子回单生成失败!['.$result['state'].']'.$result['message']];
|
||||
}
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//余额查询
|
||||
static public function balance_query($channel, $bizParam){
|
||||
if(empty($channel))exit();
|
||||
|
||||
require_once(PLUGIN_ROOT.'baofu/inc/BaofuClient.php');
|
||||
$client = new BaofuClient($channel['appid'], $channel['appurl'], $channel['appkey']);
|
||||
|
||||
$params = [
|
||||
'version' => '4.0.0',
|
||||
'accountType' => 'BASE_ACCOUNT',
|
||||
];
|
||||
try{
|
||||
$result = $client->submit('T-1001-006-03', $params);
|
||||
return ['code'=>0, 'amount'=>$result['balance']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDgDCCAmigAwIBAgIFEFmDdYIwDQYJKoZIhvcNAQEFBQAwITELMAkGA1UEBhMC
|
||||
Q04xEjAQBgNVBAoTCUNGQ0EgT0NBMTAeFw0xNjEwMjQwNzIzMjRaFw0yMTEwMjQw
|
||||
NzIzMjRaMHExCzAJBgNVBAYTAkNOMRIwEAYDVQQKEwlDRkNBIE9DQTExDzANBgNV
|
||||
BAsTBkJhb2ZvbzEZMBcGA1UECxMQT3JnYW5pemF0aW9uYWwtMTEiMCAGA1UEAwwZ
|
||||
QmFvZm9vQOWuneS7mEBaNjg4MTk5OTlAMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
|
||||
gYkCgYEA30bgCAY6agzuJccSKfLe/2NeOeUm2GZFuajai6CB9E0SOg6QymWuGw/f
|
||||
XyL6rcZd/eavew1Ec2EDTeq4DgVudah6HZbI3EXt2TSxLpn6AwDMwKgSGhWpxR2V
|
||||
1HnEiIyTOCjdWe5gUJl62UnE5acErjO0G9w+o+qGy13r0/ZZ6h0CAwEAAaOB8jCB
|
||||
7zAfBgNVHSMEGDAWgBTR2+mIguXdGo9MqgCMvnzyqxv22TBIBgNVHSAEQTA/MD0G
|
||||
CGCBHIbvKgEBMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly93d3cuY2ZjYS5jb20uY24v
|
||||
dXMvdXMtMTQuaHRtMDcGA1UdHwQwMC4wLKAqoCiGJmh0dHA6Ly9jcmwuY2ZjYS5j
|
||||
b20uY24vUlNBL2NybDQ0MDEuY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQURqt0
|
||||
qRdCkRebpuVAmkiDlMQj95IwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwME
|
||||
MA0GCSqGSIb3DQEBBQUAA4IBAQAHTgkQg47p4Fy5PCFcdGzX5LnHqyHK/cysjcpo
|
||||
lHSj89/s/kX1pXU7Jqgp/FD1RJu/Ng6rmgHSNDR9ZHwapdc++PRSxDBN/+2BnR6J
|
||||
4CoxHb0e7sjDddb7R1ceTuRXNjZuruV80j5HFycgrHSsSLI/LeZq1up0NLM+YOxt
|
||||
/+zsnkAiGfLvRCVTlppwgfhpsT1LhdVvrDkYMedbgrA1zqL/kbXe0DIdb8kn2G8Q
|
||||
7zR8SEYPXnWsDR2Ktno53mxKhx9kg3DQayWMudNY8qy+So0uBT1CqCsWR7SWoMpX
|
||||
VSnKLXWBCRDqevVt4B2fpTHoo4uM4oZDggYaf14ky90d0lWH
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://docs.baofu.com/
|
||||
*/
|
||||
class BaofuClient
|
||||
{
|
||||
public $gateway_url = 'https://juhe.baofoo.com/api';
|
||||
protected $merId;
|
||||
protected $terId;
|
||||
protected $publicCertPath;
|
||||
protected $privateCertPath;
|
||||
protected $privateKeyPwd;
|
||||
protected $version = '1.0';
|
||||
protected $format = 'json';
|
||||
protected $signType = 'RSA';
|
||||
protected $charset = 'UTF-8';
|
||||
|
||||
public function __construct($merId, $terId, $privateKeyPwd)
|
||||
{
|
||||
$this->merId = $merId;
|
||||
$this->terId = $terId;
|
||||
$this->privateKeyPwd = $privateKeyPwd;
|
||||
$this->publicCertPath = PLUGIN_ROOT.'baofu/cert/baofu.cer';
|
||||
if(file_exists(PLUGIN_ROOT.'baofu/cert/'.$merId.'.pfx')){
|
||||
$this->privateCertPath = PLUGIN_ROOT.'baofu/cert/'.$merId.'.pfx';
|
||||
}else{
|
||||
$this->privateCertPath = PLUGIN_ROOT.'baofu/cert/client.pfx';
|
||||
}
|
||||
if(!file_exists($this->publicCertPath)){
|
||||
throw new \Exception('宝付公钥证书文件baofu.cer不存在');
|
||||
}
|
||||
if(!file_exists($this->privateCertPath)){
|
||||
throw new \Exception('商户私钥证书文件client.pfx不存在');
|
||||
}
|
||||
}
|
||||
|
||||
//聚合交易接口
|
||||
public function execute($method, $bizContent){
|
||||
$biz_content = json_encode($bizContent);
|
||||
$params = [
|
||||
'merId' => $this->merId,
|
||||
'terId' => $this->terId,
|
||||
'method' => $method,
|
||||
'charset' => $this->charset,
|
||||
'version' => $this->version,
|
||||
'format' => $this->format,
|
||||
'timestamp' => date('YmdHis'),
|
||||
'signType' => $this->signType,
|
||||
'signSn' => '1',
|
||||
'ncrptnSn' => '1',
|
||||
'bizContent' => $biz_content,
|
||||
'signStr' => $this->rsaPrivateSign($biz_content),
|
||||
];
|
||||
$response = get_curl($this->gateway_url, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['returnCode']) && $result['returnCode'] == 'SUCCESS'){
|
||||
if(empty($result['dataContent'])) throw new Exception('返回值dataContent为空');
|
||||
if(empty($result['signStr'])) throw new Exception('返回值signStr为空');
|
||||
if(!$this->rsaPubilcVerify($result['dataContent'], $result['signStr'])) throw new Exception('返回数据验签失败');
|
||||
return json_decode($result['dataContent'], true);
|
||||
}else{
|
||||
throw new \Exception($result['returnMsg']?$result['returnMsg']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//代付接口
|
||||
public function transfer($method, $bizContent){
|
||||
$biz_content = json_encode($bizContent, JSON_UNESCAPED_UNICODE);
|
||||
$requrl = 'https://public.baofoo.com/baofoo-fopay/pay/'.$method.'.do';
|
||||
$params = [
|
||||
'member_id' => $this->merId,
|
||||
'terminal_id' => $this->terId,
|
||||
'data_type' => 'json',
|
||||
'data_content' => $this->rsaPrivateEncrypt($biz_content),
|
||||
'version' => '4.0.2',
|
||||
];
|
||||
$response = get_curl($requrl, http_build_query($params));
|
||||
if(strpos($response, 'trans_content') === false){
|
||||
$response = $this->rsaPublicDecrypt($response);
|
||||
if(!$response) throw new Exception('返回数据解密失败');
|
||||
}
|
||||
$arr = json_decode($response, true);
|
||||
if(isset($arr['trans_content']['trans_head']['return_code'])){
|
||||
if($arr['trans_content']['trans_head']['return_code'] == '0000'){
|
||||
return $arr['trans_reqDatas'];
|
||||
}else{
|
||||
throw new Exception($arr['trans_content']['trans_head']['return_msg']);
|
||||
}
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//统一入口
|
||||
public function submit($service_tp, $params){
|
||||
$requrl = 'https://public.baofu.com/union-gw/api/'.$service_tp.'/transReq.do';
|
||||
$content = [
|
||||
'header' => [
|
||||
'memberId' => $this->merId,
|
||||
'terminalId' => $this->terId,
|
||||
'serviceTp' => $service_tp,
|
||||
'verifyType' => '1',
|
||||
],
|
||||
'body' => $params,
|
||||
];
|
||||
$contentStr = json_encode($content);
|
||||
$enContent = $this->rsaPrivateEncrypt($contentStr);
|
||||
|
||||
$post = [
|
||||
'memberId' => $this->merId,
|
||||
'terminalId' => $this->terId,
|
||||
'verifyType' => '1',
|
||||
'content' => $enContent,
|
||||
];
|
||||
$response = get_curl($requrl, http_build_query($post));
|
||||
if(empty($response)) throw new Exception('请求返回为空');
|
||||
if(strpos($response, "header") != false){
|
||||
$result = json_decode($response, true);
|
||||
}else{
|
||||
$decrypted = $this->rsaPublicDecrypt($response);
|
||||
if($decrypted === false) throw new Exception('返回数据解密失败');
|
||||
$result = json_decode($decrypted, true);
|
||||
}
|
||||
if($result['header']['sysRespCode'] == 'S_0000'){
|
||||
return $result['body'];
|
||||
}elseif(isset($result['header']['sysRespCode'])){
|
||||
throw new Exception('['.$result['header']['sysRespCode'].']'.$result['header']['sysRespDesc']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//文件上传接口
|
||||
public function upload($params, $file_name, $file_path){
|
||||
$requrl = 'https://upload.baofoo.com/baofu-upload-trade/trade/syncUploadFile';
|
||||
$contentStr = json_encode($params);
|
||||
$enContent = $this->rsaPrivateEncrypt($contentStr);
|
||||
$post = [
|
||||
'memberId' => $this->merId,
|
||||
'terminalId' => $this->terId,
|
||||
'orderType' => '0',
|
||||
'content' => $enContent,
|
||||
'file' => new \CURLFile($file_path, mime_content_type($file_path), $file_name),
|
||||
];
|
||||
$response = get_curl($requrl, $post);
|
||||
if(empty($response)) throw new Exception('请求返回为空');
|
||||
$decrypted = $this->rsaPublicDecrypt($response);
|
||||
if($decrypted === false) throw new Exception('返回数据解密失败');
|
||||
$result = json_decode($decrypted, true);
|
||||
if($result['success'] == 1 || $result['success'] == 2){
|
||||
return $result['result'];
|
||||
}elseif(isset($result['errorCode'])){
|
||||
throw new Exception('['.$result['errorCode'].']'.$result['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//回调验签
|
||||
public function verifyNotify($data, $sign){
|
||||
if(empty($sign)) return false;
|
||||
return $this->rsaPubilcVerify($data, $sign);
|
||||
}
|
||||
|
||||
//商户私钥签名
|
||||
private function rsaPrivateSign($data){
|
||||
$pkcs12 = file_get_contents($this->privateCertPath);
|
||||
if (!openssl_pkcs12_read($pkcs12, $keyarr, $this->privateKeyPwd)) {
|
||||
throw new Exception('商户私钥证书解析失败');
|
||||
}
|
||||
$private_key = openssl_pkey_get_private($keyarr['pkey']);
|
||||
openssl_sign($data, $signature, $private_key, OPENSSL_ALGO_SHA256);
|
||||
return bin2hex($signature);
|
||||
}
|
||||
|
||||
//平台公钥验签
|
||||
private function rsaPubilcVerify($data, $signature){
|
||||
$keyFile = file_get_contents($this->publicCertPath);
|
||||
$public_key = openssl_pkey_get_public($keyFile);
|
||||
if(!$public_key){
|
||||
throw new Exception('验签失败,平台公钥证书不正确');
|
||||
}
|
||||
$result = openssl_verify($data, hex2bin($signature), $public_key, OPENSSL_ALGO_SHA256);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
//商户私钥加密
|
||||
private function rsaPrivateEncrypt($data){
|
||||
$pkcs12 = file_get_contents($this->privateCertPath);
|
||||
if (!openssl_pkcs12_read($pkcs12, $keyarr, $this->privateKeyPwd)) {
|
||||
throw new Exception('商户私钥证书解析失败');
|
||||
}
|
||||
$privateKey = openssl_pkey_get_private($keyarr['pkey']);
|
||||
|
||||
$data = base64_encode($data);
|
||||
$encrypted = '';
|
||||
$partLen = openssl_pkey_get_details($privateKey)['bits']/8 - 11;
|
||||
$plainData = str_split($data, $partLen);
|
||||
foreach ($plainData as $chunk) {
|
||||
$partialEncrypted = '';
|
||||
$encryptionOk = openssl_private_encrypt($chunk, $partialEncrypted, $privateKey);
|
||||
if ($encryptionOk === false) {
|
||||
return false;
|
||||
}
|
||||
$encrypted .= $partialEncrypted;
|
||||
}
|
||||
return bin2hex($encrypted);
|
||||
}
|
||||
|
||||
//平台公钥解密
|
||||
public function rsaPublicDecrypt($data){
|
||||
$keyFile = file_get_contents($this->publicCertPath);
|
||||
$publicKey = openssl_pkey_get_public($keyFile);
|
||||
|
||||
$decrypted = '';
|
||||
$partLen = openssl_pkey_get_details($publicKey)['bits']/8;
|
||||
$data = hex2bin($data);
|
||||
$plainData = str_split($data, $partLen);
|
||||
foreach ($plainData as $chunk) {
|
||||
$partialDecrypted = '';
|
||||
$decryptionOk = openssl_public_decrypt($chunk, $partialDecrypted, $publicKey);
|
||||
if ($decryptionOk === false) {
|
||||
return false;
|
||||
}
|
||||
$decrypted .= $partialDecrypted;
|
||||
}
|
||||
return base64_decode($decrypted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
class bepusdt_plugin
|
||||
{
|
||||
public static $info = [
|
||||
'name' => 'bepusdt',
|
||||
'showname' => 'BEpusdt 个人加密货币收款',
|
||||
'author' => 'V03413',
|
||||
'link' => 'https://github.com/v03413/BEpusdt',
|
||||
'types' => [
|
||||
// 此列表可能存在变动,以此为准 https://github.com/v03413/BEpusdt/blob/main/docs/trade-type.md
|
||||
'tron.trx',
|
||||
'bsc.bnb',
|
||||
'ethereum.eth',
|
||||
'usdt.trc20',
|
||||
'usdc.trc20',
|
||||
'usdt.polygon',
|
||||
'usdc.polygon',
|
||||
'usdt.arbitrum',
|
||||
'usdc.arbitrum',
|
||||
'usdt.erc20',
|
||||
'usdc.erc20',
|
||||
'usdt.bep20',
|
||||
'usdc.bep20',
|
||||
'usdt.xlayer',
|
||||
'usdc.xlayer',
|
||||
'usdc.base',
|
||||
'usdt.solana',
|
||||
'usdc.solana',
|
||||
'usdt.aptos',
|
||||
'usdc.aptos',
|
||||
'usdt.plasma',
|
||||
],
|
||||
'inputs' => [
|
||||
'appurl' => [
|
||||
'name' => '接口地址',
|
||||
'type' => 'input',
|
||||
'note' => '必须以http://或https://开头,以/结尾',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '认证Token',
|
||||
'type' => 'input',
|
||||
'note' => '搭建BEpusdt时填写的 auth_token 参数',
|
||||
],
|
||||
'address' => [
|
||||
'name' => '收款地址',
|
||||
'type' => 'input',
|
||||
'note' => '可以留空 留空则由BEpusdt自动分配,切勿乱填 注意空格',
|
||||
],
|
||||
'timeout' => [
|
||||
'name' => '订单超时',
|
||||
'type' => 'input',
|
||||
'note' => '可以留空 填写整数(单位秒)、推荐 1200',
|
||||
],
|
||||
'rate' => [
|
||||
'name' => '订单汇率',
|
||||
'type' => 'input',
|
||||
'note' => '可以留空 例如:7.4 ~1.02 ~0.98(不明白切勿乱填)',
|
||||
],
|
||||
'fiat' => [
|
||||
'name' => '交易法币',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'CNY' => '人民币 (CNY)',
|
||||
'USD' => '美元 (USD)',
|
||||
'EUR' => '欧元 (EUR)',
|
||||
'GBP' => '英镑 (GBP)',
|
||||
'JPY' => '日元 (JPY)',
|
||||
],
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '', //支付密钥填写说明
|
||||
];
|
||||
|
||||
public static function submit(): array
|
||||
{
|
||||
global $siteurl, $channel, $order, $conf;
|
||||
|
||||
$parameter = [
|
||||
'fiat' => trim($channel['fiat']),
|
||||
'address' => trim($channel['address']),
|
||||
'trade_type' => $order['typename'],
|
||||
'order_id' => TRADE_NO,
|
||||
'name' => $order['name'],
|
||||
'timeout' => intval($channel['timeout']),
|
||||
'rate' => strval($channel['rate']),
|
||||
'amount' => floatval($order['realmoney']),
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'redirect_url' => $siteurl . 'pay/return/' . TRADE_NO . '/',
|
||||
];
|
||||
$parameter['signature'] = self::_toSign($parameter, $channel['appkey']);
|
||||
|
||||
$url = trim($channel['appurl']) . 'api/v1/order/create-transaction';
|
||||
$data = self::_post($url, $parameter);
|
||||
if (!is_array($data)) {
|
||||
|
||||
return ['type' => 'error', 'msg' => '请求失败,请检查服务器是否能正常请求 BEpusdt 网关!'];
|
||||
}
|
||||
|
||||
if ($data['status_code'] != 200) {
|
||||
|
||||
return ['type' => 'error', 'msg' => '请求失败,错误信息:' . $data['message']];
|
||||
}
|
||||
|
||||
return ['type' => 'jump', 'url' => $data['data']['payment_url']];
|
||||
}
|
||||
|
||||
public static function notify()
|
||||
{
|
||||
global $channel, $order;
|
||||
|
||||
ob_clean();
|
||||
header('Content-Type: plain/text; charset=utf-8');
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$sign = $data['signature'] ?? '';
|
||||
if ($sign != self::_toSign($data, $channel['appkey'])) {
|
||||
// 签名验证失败
|
||||
|
||||
exit('fail - sign error');
|
||||
}
|
||||
|
||||
$out_trade_no = $data['order_id']; // 商户订单号
|
||||
$trade_no = $data['trade_id']; // BEpusdt 交易ID
|
||||
$buyer = mb_substr($data['buyer'], -28);
|
||||
if ($data['status'] === 2 && $out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $trade_no, $buyer);
|
||||
|
||||
exit('ok');
|
||||
}
|
||||
|
||||
exit('fail - status error');
|
||||
}
|
||||
|
||||
public static function return(): array
|
||||
{
|
||||
return ['type' => 'page', 'page' => 'return'];
|
||||
}
|
||||
|
||||
private static function _toSign(array $parameter, string $token): string
|
||||
{
|
||||
ksort($parameter);
|
||||
|
||||
$sign = '';
|
||||
|
||||
foreach ($parameter as $key => $val) {
|
||||
if ($val == '') continue;
|
||||
if ($key != 'signature') {
|
||||
if ($sign != '') {
|
||||
$sign .= "&";
|
||||
|
||||
}
|
||||
|
||||
$sign .= "$key=$val";
|
||||
}
|
||||
}
|
||||
|
||||
return md5($sign . $token);
|
||||
}
|
||||
|
||||
private static function _post(string $url, array $json)
|
||||
{
|
||||
|
||||
$header[] = 'Accept: */*';
|
||||
$header[] = 'Accept-Language: zh-CN,zh;q=0.8';
|
||||
$header[] = 'Connection: close';
|
||||
$header[] = 'Content-Type: application/json';
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json));
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
$resp = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
class chinaums_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'chinaums', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '银联商务', //支付插件显示名称
|
||||
'author' => '银联商务', //支付插件作者
|
||||
'link' => 'https://open.chinaums.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => 'AppId',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => 'AppKey',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户号mid',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appurl' => [
|
||||
'name' => '终端号tid',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '通讯密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'msgsrcid' => [
|
||||
'name' => '来源编号',
|
||||
'type' => 'input',
|
||||
'note' => '4位来源编号',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '环境选择',
|
||||
'type' => 'select',
|
||||
'options' => [0=>'生产环境',1=>'测试环境'],
|
||||
],
|
||||
],
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'H5支付',
|
||||
//'3' => 'APP支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'H5支付',
|
||||
'3' => 'H5转小程序支付',
|
||||
//'4' => 'APP支付',
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
if(in_array('2',$channel['apptype']) && checkmobile()){
|
||||
$code_url = self::h5pay('alipay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if(in_array('2',$channel['apptype']) && checkmobile()){
|
||||
$code_url = self::h5pay('wxpay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}elseif(in_array('3',$channel['apptype']) && checkmobile()){
|
||||
$code_url = self::h5pay('wxminipay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}elseif(in_array('4',$channel['apptype']) && checkmobile() && strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone OS')!==false){
|
||||
return ['type'=>'jump','url'=>'/pay/wxapppay/'.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($order['typename']=='alipay'){
|
||||
if(in_array('2',$channel['apptype']) && $device=='mobile'){
|
||||
$code_url = self::h5pay('alipay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return self::alipay();
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if(in_array('2',$channel['apptype']) && $device=='mobile'){
|
||||
$code_url = self::h5pay('wxpay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}elseif(in_array('3',$channel['apptype']) && $device=='mobile'){
|
||||
$code_url = self::h5pay('wxminipay');
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//扫码下单
|
||||
static private function qrcode(){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require(PAY_ROOT."inc/Build.class.php");
|
||||
|
||||
$client = new ChinaumsBuild($channel['appid'], $channel['appkey'], $channel['appswitch'] == 1);
|
||||
|
||||
$path = '/v1/netpay/bills/get-qrcode';
|
||||
$time = time();
|
||||
$param = [
|
||||
'msgId' => md5(uniqid(mt_rand(), true)),
|
||||
'requestTimestamp' => date('Y-m-d H:i:s', $time),
|
||||
'mid' => $channel['appmchid'],
|
||||
'tid' => $channel['appurl'],
|
||||
'instMid' => 'QRPAYDEFAULT',
|
||||
'billNo' => $channel['msgsrcid'].TRADE_NO,
|
||||
'billDate' => date('Y-m-d', $time),
|
||||
'billDesc' => $ordername,
|
||||
'totalAmount' => intval(round($order['realmoney']*100)),
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'returnUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $path, $param, $time) {
|
||||
$result = $client->request($path, $param, $time);
|
||||
if(isset($result['errCode']) && $result['errCode']=='SUCCESS'){
|
||||
return $result['billQRCode'];
|
||||
}elseif(isset($result['errMsg'])){
|
||||
throw new Exception($result['errMsg']);
|
||||
}elseif(isset($result['errInfo'])){
|
||||
throw new Exception($result['errInfo']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static private function h5pay($pay_type){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require(PAY_ROOT."inc/Build.class.php");
|
||||
|
||||
$client = new ChinaumsBuild($channel['appid'], $channel['appkey'], $channel['appswitch'] == 1);
|
||||
|
||||
if($pay_type == 'alipay'){
|
||||
$path = '/v1/netpay/trade/h5-pay';
|
||||
}elseif($pay_type == 'wxpay'){
|
||||
$path = '/v1/netpay/wxpay/h5-pay';
|
||||
}elseif($pay_type == 'wxminipay'){
|
||||
$path = '/v1/netpay/wxpay/h5-to-minipay';
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$param = [
|
||||
'msgId' => md5(uniqid(mt_rand(), true)),
|
||||
'requestTimestamp' => date('Y-m-d H:i:s', $time),
|
||||
'mid' => $channel['appmchid'],
|
||||
'tid' => $channel['appurl'],
|
||||
'instMid' => 'H5DEFAULT',
|
||||
'merOrderId' => $channel['msgsrcid'].TRADE_NO,
|
||||
'orderDesc' => $ordername,
|
||||
'totalAmount' => intval(round($order['realmoney']*100)),
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'returnUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
if($pay_type == 'wxpay'){
|
||||
$param['sceneType'] = 'AND_WAP';
|
||||
$param['merAppName'] = $conf['sitename'];
|
||||
$param['merAppId'] = $siteurl;
|
||||
}
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
$url = $client->requestGet($path, $param, $time);
|
||||
|
||||
\lib\Payment::updateOrderCombine(TRADE_NO);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
//APP支付(跳转小程序)
|
||||
static private function apppay($pay_type, $sub_app_id = null){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require(PAY_ROOT."inc/Build.class.php");
|
||||
|
||||
$client = new ChinaumsBuild($channel['appid'], $channel['appkey'], $channel['appswitch'] == 1);
|
||||
|
||||
if($pay_type == 'alipay'){
|
||||
$path = '/v1/netpay/trade/app-pre-order';
|
||||
}elseif($pay_type == 'wxpay'){
|
||||
$path = '/v1/netpay/wx/app-pre-order';
|
||||
}elseif($pay_type == 'bank'){
|
||||
$path = '/v1/netpay/uac/app-order';
|
||||
}
|
||||
$time = time();
|
||||
$param = [
|
||||
'msgId' => md5(uniqid(mt_rand(), true)),
|
||||
'requestTimestamp' => date('Y-m-d H:i:s', $time),
|
||||
'mid' => $channel['appmchid'],
|
||||
'tid' => $channel['appurl'],
|
||||
'instMid' => 'APPDEFAULT',
|
||||
'merOrderId' => $channel['msgsrcid'].TRADE_NO,
|
||||
'orderDesc' => $ordername,
|
||||
'totalAmount' => intval(round($order['realmoney']*100)),
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
if($sub_app_id){
|
||||
$param['subAppId'] = $sub_app_id;
|
||||
}
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $path, $param, $time) {
|
||||
$result = $client->request($path, $param, $time);
|
||||
if(isset($result['errCode']) && $result['errCode']=='SUCCESS'){
|
||||
return $result['appPayRequest'];
|
||||
}elseif(isset($result['errMsg'])){
|
||||
throw new Exception($result['errMsg']);
|
||||
}elseif(isset($result['errInfo'])){
|
||||
throw new Exception($result['errInfo']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static private function handleProfits(&$param){
|
||||
global $order, $channel;
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$param['divisionFlag'] = true;
|
||||
$suborders = [];
|
||||
$i = 1;
|
||||
$allmoney = 0;
|
||||
foreach($psreceiver['info'] as $receiver){
|
||||
$psmoney = intval(round(floor($order['realmoney'] * $receiver['rate'])));
|
||||
$suborders[] = [
|
||||
'mid' => $receiver['account'],
|
||||
'merOrderId' => $channel['msgsrcid'].TRADE_NO.$i++,
|
||||
'totalAmount' => $psmoney
|
||||
];
|
||||
$allmoney += $psmoney;
|
||||
}
|
||||
$param['platformAmount'] = $param['totalAmount'] - $allmoney;
|
||||
$param['subOrders'] = $suborders;
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $mdevice;
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}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];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝APP支付
|
||||
static public function alipayapp(){
|
||||
global $channel, $method;
|
||||
try{
|
||||
$result = self::apppay('alipay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'app'){
|
||||
return ['type'=>'app','data'=>$result];
|
||||
}
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $device, $mdevice;
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}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];
|
||||
}
|
||||
}
|
||||
|
||||
//微信APP支付
|
||||
static public function wxapppay(){
|
||||
global $channel, $method;
|
||||
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
|
||||
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
|
||||
try{
|
||||
$result = self::apppay('wxpay', $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'app'){
|
||||
return ['type'=>'app','data'=>$result];
|
||||
}
|
||||
|
||||
$param = [
|
||||
'nonceStr' => $result['noncestr'],
|
||||
'package' => $result['package'],
|
||||
'partnerId' => $result['partnerid'],
|
||||
'prepayId' => $result['prepayid'],
|
||||
'timeStamp' => $result['timestamp'],
|
||||
'sign' => $result['sign'],
|
||||
];
|
||||
$code_url = 'weixin://app/'.$result['appid'].'/pay/?'.http_build_query($param);
|
||||
return ['type'=>'qrcode','page'=>'wxpay_h5','url'=>$code_url];
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}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;
|
||||
|
||||
require(PAY_ROOT."inc/Build.class.php");
|
||||
|
||||
$client = new ChinaumsBuild($channel['appid'], $channel['appkey'], $channel['appswitch'] == 1);
|
||||
|
||||
$verifyResult = $client->verify($_POST, $channel['appsecret']);
|
||||
|
||||
if($verifyResult){
|
||||
if($_POST['instMid'] == 'H5DEFAULT'){
|
||||
if($_POST['status'] == 'TRADE_SUCCESS'){
|
||||
$out_trade_no = substr($_POST['merOrderId'],4);
|
||||
$trade_no = $_POST['merOrderId'];
|
||||
$money = $_POST['totalAmount'];
|
||||
$buyer = $_POST['buyerId'];
|
||||
$bill_trade_no = $_POST['targetOrderId'];
|
||||
if($out_trade_no == TRADE_NO && $money==strval($order['realmoney']*100)){
|
||||
processNotify($order, $trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'SUCCESS'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'FAILED'];
|
||||
}
|
||||
}else{
|
||||
if($_POST['billStatus'] == 'PAID'){
|
||||
$out_trade_no = substr($_POST['billNo'],4);
|
||||
$billPayment = json_decode($_POST['billPayment'], true);
|
||||
$trade_no = $_POST['billNo'];
|
||||
$money = $_POST['totalAmount'];
|
||||
$buyer = $billPayment['buyerId'];
|
||||
$bill_trade_no = $billPayment['targetOrderId'];
|
||||
if($out_trade_no == TRADE_NO && $money==strval($order['realmoney']*100)){
|
||||
processNotify($order, $trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'SUCCESS'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'FAILED'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'FAILED'];
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $conf;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/Build.class.php");
|
||||
|
||||
$client = new ChinaumsBuild($channel['appid'], $channel['appkey'], $channel['appswitch'] == 1);
|
||||
|
||||
if($order['combine'] == 1){ //H5支付退款
|
||||
$path = '/v1/netpay/refund';
|
||||
$time = time();
|
||||
$param = [
|
||||
'msgId' => md5(uniqid(mt_rand(), true)),
|
||||
'requestTimestamp' => date('Y-m-d H:i:s', $time),
|
||||
'mid' => $channel['appmchid'],
|
||||
'tid' => $channel['appurl'],
|
||||
'instMid' => 'H5DEFAULT',
|
||||
'merOrderId' => $order['api_trade_no'],
|
||||
'billDate' => date('Y-m-d', strtotime($order['addtime'])),
|
||||
'refundOrderId' => $channel['msgsrcid'].$order['refund_no'],
|
||||
'refundAmount' => $order['refundmoney']*100,
|
||||
];
|
||||
}else{
|
||||
$path = '/v1/netpay/bills/refund';
|
||||
$time = time();
|
||||
$param = [
|
||||
'msgId' => md5(uniqid(mt_rand(), true)),
|
||||
'requestTimestamp' => date('Y-m-d H:i:s', $time),
|
||||
'mid' => $channel['appmchid'],
|
||||
'tid' => $channel['appurl'],
|
||||
'instMid' => 'QRPAYDEFAULT',
|
||||
'billNo' => $order['api_trade_no'],
|
||||
'billDate' => date('Y-m-d', strtotime($order['addtime'])),
|
||||
'refundOrderId' => $channel['msgsrcid'].$order['refund_no'],
|
||||
'refundAmount' => $order['refundmoney']*100,
|
||||
];
|
||||
}
|
||||
|
||||
$result = $client->request($path, $param, $time);
|
||||
if(isset($result['errCode']) && $result['errCode']=='SUCCESS'){
|
||||
return ['code'=>0, 'trade_no'=>$result['billNo'], 'refund_fee'=>round($result['refundAmount']/100, 2)];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>$result['errMsg']?$result['errMsg']:'返回数据解析失败'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class ChinaumsBuild
|
||||
{
|
||||
private $appid;
|
||||
private $appkey;
|
||||
|
||||
// 网关地址(生产环境)
|
||||
private $gateway = 'https://api-mop.chinaums.com';
|
||||
|
||||
// 网关地址(测试环境)
|
||||
private $gateway_test = 'https://test-api-open.chinaums.com';
|
||||
|
||||
public function __construct($appid, $appkey, $istest = false){
|
||||
$this->appid = $appid;
|
||||
$this->appkey = $appkey;
|
||||
if($istest){
|
||||
$this->gateway = $this->gateway_test;
|
||||
}
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
public function request($path, $params, $time){
|
||||
$url = $this->gateway.$path;
|
||||
$json = json_encode($params);
|
||||
$authorization = $this->getOpenBodySig($json, $time);
|
||||
$response = $this->httpPost($url, $json, $authorization);
|
||||
$arr = json_decode($response, true);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
// 发起支付GET
|
||||
public function requestGet($path, $params, $time){
|
||||
$url = $this->gateway.$path;
|
||||
$json = json_encode($params);
|
||||
$query = [
|
||||
'authorization' => 'OPEN-FORM-PARAM',
|
||||
'appId' => $this->appid,
|
||||
'timestamp' => date('YmdHis', $time),
|
||||
'nonce' => md5(uniqid(mt_rand(), true)),
|
||||
'content' => $json
|
||||
];
|
||||
$query['signature'] = $this->getSignature($query['timestamp'], $query['nonce'], $query['content']);
|
||||
return $url . '?' . http_build_query($query);
|
||||
}
|
||||
|
||||
// 获取Authorization
|
||||
private function getOpenBodySig($body, $time){
|
||||
|
||||
$timestamp = date('YmdHis', $time);
|
||||
$nonce = md5(uniqid(mt_rand(), true));
|
||||
$signature = $this->getSignature($timestamp, $nonce, $body);
|
||||
$authorization = 'OPEN-BODY-SIG AppId="'.$this->appid.'", Timestamp="'.$timestamp.'", Nonce="'.$nonce.'", Signature="'.$signature.'"';
|
||||
return $authorization;
|
||||
}
|
||||
|
||||
// 获取Signature
|
||||
private function getSignature($timestamp, $nonce, $body){
|
||||
$hash = hash('sha256', $body);
|
||||
$str = $this->appid.$timestamp.$nonce.$hash;
|
||||
$hash = hash_hmac('sha256', $str, $this->appkey, true);
|
||||
$signature = base64_encode($hash);
|
||||
return $signature;
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
private function httpPost($url, $json, $authorization)
|
||||
{
|
||||
$ch = curl_init();
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
|
||||
$httpheader[] = "Content-Type: application/json; charset=utf-8";
|
||||
$httpheader[] = "Connection: close";
|
||||
$httpheader[] = "Authorization: ".$authorization;
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$data = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
if ($errno) {
|
||||
$msg = 'curl errInfo: ' . curl_error($ch) . ' curl errNo: ' . $errno;
|
||||
throw new \Exception($msg);
|
||||
}
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 回调签名验证
|
||||
public function verify($params, $key){
|
||||
$sign = $this->getSign($params, $key, $params['signType']);
|
||||
if($sign === $params['sign']){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算签名
|
||||
private function getSign($params, $key, $signType){
|
||||
ksort($params);
|
||||
$signstr = '';
|
||||
|
||||
foreach($params as $k => $v){
|
||||
if($k != "sign" && $v!=''){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr, 0, -1);
|
||||
$signstr = $signstr.$key;
|
||||
if($signType == 'SHA256'){
|
||||
$sign = strtoupper(hash('sha256', $signstr));
|
||||
}else{
|
||||
$sign = strtoupper(md5($signstr));
|
||||
}
|
||||
return $sign;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,633 @@
|
||||
<?php
|
||||
|
||||
class dinpay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'dinpay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '智付', //支付插件显示名称
|
||||
'author' => '智付', //支付插件作者
|
||||
'link' => 'https://www.dinpay.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' => 'SM2-Hex格式',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '平台公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => 'SM2-Hex格式',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '子商户号',
|
||||
'type' => 'input',
|
||||
'note' => '可留空',
|
||||
],
|
||||
'reportid' => [
|
||||
'name' => '渠道商户报备ID',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,多个报备ID可用,隔开',
|
||||
],
|
||||
],
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'H5支付',
|
||||
'3' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'H5支付',
|
||||
'3' => 'JS支付',
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '<a href="http://qqapi.cccyun.cc/dinpay.php" target="_blank" rel="noreferrer">智付SM2公私钥提取</a>', //支付密钥填写说明
|
||||
'bindwxmp' => true, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
if(checkalipay() && in_array('3',$channel['apptype']) && !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() && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile() && ($channel['appwxa']>0 || in_array('2',$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, $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('3',$channel['apptype']) && !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' && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile' && ($channel['appwxa']>0 || in_array('2',$channel['apptype']))){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
static private function getReportId($reportid){
|
||||
global $order;
|
||||
if(!empty($order['param']) && is_numeric($order['param'])){
|
||||
return $order['param'];
|
||||
}
|
||||
if(strpos($reportid, ',')){
|
||||
$reportids = explode(',', $reportid);
|
||||
$reportid = $reportids[array_rand($reportids)];
|
||||
}
|
||||
global $DB;
|
||||
$DB->update('order', ['param'=>$reportid], ['trade_no'=>TRADE_NO]);
|
||||
return $reportid;
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static private function qrcode($paytype){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$params = [
|
||||
'interfaceName' => 'AppPay',
|
||||
'paymentType' => $paytype,
|
||||
'paymentMethods' => 'SCAN',
|
||||
'paymentCode' => '1',
|
||||
'payAmount' => $order['realmoney'],
|
||||
'currency' => 'CNY',
|
||||
'orderNo' => TRADE_NO,
|
||||
'orderIp' => $clientip,
|
||||
'goodsName' => $ordername,
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
if(!empty($channel['reportid'])) $params['reportId'] = self::getReportId($channel['reportid']);
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->execute('/api/appPay/pay', $params);
|
||||
return $result['qrcode'];
|
||||
}
|
||||
|
||||
//公众号支付
|
||||
static private function publicpay($paytype, $openid, $appid){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$params = [
|
||||
'interfaceName' => 'AppPayPublic',
|
||||
'paymentType' => $paytype,
|
||||
'paymentMethods' => 'PUBLIC',
|
||||
'appid' => $appid,
|
||||
'openid' => $openid,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'currency' => 'CNY',
|
||||
'orderNo' => TRADE_NO,
|
||||
'orderIp' => $clientip,
|
||||
'goodsName' => $ordername,
|
||||
'isNative' => '1',
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'successToUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
if(!empty($channel['reportid'])) $params['reportId'] = self::getReportId($channel['reportid']);
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->execute('/api/appPay/payPublic', $params);
|
||||
return $result['payInfo'];
|
||||
}
|
||||
|
||||
//小程序支付
|
||||
static private function appletpay($paytype, $openid, $appid){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$params = [
|
||||
'interfaceName' => 'AppPayApplet',
|
||||
'paymentType' => $paytype,
|
||||
'paymentMethods' => 'APPLET',
|
||||
'appid' => $appid,
|
||||
'openid' => $openid,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'currency' => 'CNY',
|
||||
'orderNo' => TRADE_NO,
|
||||
'orderIp' => $clientip,
|
||||
'goodsName' => $ordername,
|
||||
'isNative' => '1',
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
//'successToUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
if(!empty($channel['reportid'])) $params['reportId'] = self::getReportId($channel['reportid']);
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->execute('/api/appPay/payApplet', $params);
|
||||
return $result['payInfo'];
|
||||
}
|
||||
|
||||
//H5支付
|
||||
static private function h5pay($paytype){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$params = [
|
||||
'interfaceName' => 'AppPayH5WFT',
|
||||
'paymentType' => $paytype,
|
||||
'paymentMethods' => 'WAP',
|
||||
'payAmount' => $order['realmoney'],
|
||||
'currency' => 'CNY',
|
||||
'orderNo' => TRADE_NO,
|
||||
'orderIp' => $clientip,
|
||||
'applyName' => $conf['sitename'],
|
||||
'applyType' => 'AND_WAP',
|
||||
'applyId' => $siteurl,
|
||||
'isNative' => '0',
|
||||
'goodsName' => $ordername,
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'successToUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
if(!empty($channel['reportid'])) $params['reportId'] = self::getReportId($channel['reportid']);
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->execute('/api/appPay/payH5', $params);
|
||||
return $result['payInfo'];
|
||||
}
|
||||
|
||||
static private function handleProfits(&$params){
|
||||
global $order;
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$splitRules = [];
|
||||
$i = 1;
|
||||
foreach($psreceiver['info'] as $receiver){
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']) / 100, 2);
|
||||
$splitRules[] = [
|
||||
'splitBillMerchantNo' => $receiver['account'],
|
||||
'splitBillAmount' => $psmoney,
|
||||
'splitBillRequestNo' => TRADE_NO.$i++,
|
||||
];
|
||||
}
|
||||
$params['splitType'] = 'FIXED_AMOUNT';
|
||||
$params['splitRules'] = json_encode($splitRules);
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype']) || empty($channel['apptype'][0])){
|
||||
try{
|
||||
$code_url = self::qrcode('ALIPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
if(checkalipay() || $mdevice=='alipay'){
|
||||
try{
|
||||
$code_url = self::h5pay('ALIPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/alipay/'.TRADE_NO.'/';
|
||||
}
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
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::publicpay('ALIPAY', $user_id, '1');
|
||||
$result = json_decode($payinfo, true);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['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'=>$result['tradeNO'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
try{
|
||||
$code_url = self::qrcode('WXPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
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 wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
if(in_array('2',$channel['apptype'])){
|
||||
try{
|
||||
$code_url = self::h5pay('WXPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
return ['type'=>'jump','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 wxjspay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
//①、获取用户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::publicpay('WXPAY', $openid, $wxinfo['appid']);
|
||||
}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'=>$payinfo, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信小程序支付
|
||||
static public function wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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{
|
||||
$payinfo = self::appletpay('WXPAY', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($payinfo, true)]));
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode('UNIONPAY');
|
||||
}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;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->sm2DoVerifySign($_POST['data'], $_POST['sign']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$data = json_decode($_POST['data'], true);
|
||||
if ($data['orderStatus'] == 'SUCCESS') {
|
||||
$out_trade_no = $data['orderNo'];
|
||||
$api_trade_no = $data['channelNumber'];
|
||||
$money = $data['payAmount'];
|
||||
$buyer = $data['subOpenId'];
|
||||
$bill_trade_no = $data['outTransactionOrderId'];
|
||||
if($order['type'] == 1 && substr($bill_trade_no, 0, 4) != date('Y') && substr($bill_trade_no, 2, 4) == date('Y')) $bill_trade_no = substr($bill_trade_no, 2);
|
||||
if($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)){
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $DB;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$params = [
|
||||
'interfaceName' => 'AppPayRefund',
|
||||
'payOrderNo' => $order['trade_no'],
|
||||
'refundOrderNo' => $order['refund_no'],
|
||||
'refundAmount' => $order['refundmoney'],
|
||||
'notifyUrl' => $conf['localurl'] . 'pay/refundnotify/' . $order['trade_no'] . '/',
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$psorder = \lib\ProfitSharing\CommUtil::getOrder($order['trade_no']);
|
||||
if($psorder && $psorder['rdata']){
|
||||
$leftmoney = (float)$order['refundmoney'];
|
||||
$rules = [];
|
||||
$i = 1;
|
||||
foreach($psorder['rdata'] as $receiver){
|
||||
$money = $receiver['money'] > $leftmoney ? $leftmoney : $receiver['money'];
|
||||
$rules[] = [
|
||||
'merchantNo' => $receiver['account'],
|
||||
'refundAmount' => $money,
|
||||
'splitBillRequestNo' => $order['trade_no'].$i++,
|
||||
];
|
||||
$leftmoney -= $money;
|
||||
if($leftmoney <= 0) break;
|
||||
}
|
||||
$params['refundSplitRules'] = json_encode($rules);
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$result = $client->execute('/api/appPay/payRefund', $params);
|
||||
|
||||
return ['code'=>0, 'trade_no'=>$result['refundChannelNumber'], 'refund_fee'=>$result['refundAmount']];
|
||||
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//退款异步回调
|
||||
static public function refundnotify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
if(!empty($channel['appmchid']) && substr($channel['appmchid'], 0, 1)!='[') $channel['appid'] = $channel['appmchid'];
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->sm2DoVerifySign($_POST['data'], $_POST['sign']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$data = json_decode($_POST['data'], true);
|
||||
if ($data['refundStatus'] == 'ALL_REFUND') {
|
||||
$out_trade_no = $data['orderNo'];
|
||||
$api_trade_no = $data['channelNumber'];
|
||||
}
|
||||
return ['type'=>'html','data'=>'sccuess'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//转账异步回调
|
||||
static public function transfernotify(){
|
||||
global $channel, $order, $DB;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->sm2DoVerifySign($arr['data'], $arr['sign']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$data = json_decode($arr['data'], true);
|
||||
$orderid = $data['orderNo'];
|
||||
$trade_row = $DB->find('dinpay_trade', '*', ['orderid'=>$orderid]);
|
||||
if($trade_row){
|
||||
if($trade_row['status'] != $data['orderStatus']){
|
||||
$DB->update('dinpay_trade', ['status'=>$data['orderStatus'], 'reason'=>$data['statusIllustrate'], 'endtime'=>date('Y-m-d H:i:s')], ['id'=>$trade_row['id']]);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'sccuess'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//投诉通知
|
||||
static public function complainnotify(){
|
||||
global $channel;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
require(PAY_ROOT."inc/DinpayClient.php");
|
||||
|
||||
$client = new DinpayClient($channel['appid'],$channel['appkey'],$channel['appsecret']);
|
||||
$verify_result = $client->sm2DoVerifySign($arr['data'], $arr['sign']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
|
||||
$data = json_decode($arr['data'], true);
|
||||
$thirdid = $data['complaintId'];
|
||||
if(substr($channel['appmchid'],0,1)=='['){
|
||||
$channel['appmchid'] = $data['merchantId'];
|
||||
}
|
||||
if($data['appPayType'] == 'ALIPAY'){
|
||||
$channel['type'] = 1;
|
||||
}else{
|
||||
$channel['type'] = 2;
|
||||
}
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($thirdid);
|
||||
return ['type'=>'html','data'=>'sccuess'];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
class DinpayClient
|
||||
{
|
||||
private $gateway_url = 'https://payment.dinpay.com/trx';
|
||||
private $sign_method = 'SM3WITHSM2';
|
||||
|
||||
private $mchid;
|
||||
|
||||
//平台公钥证书路径
|
||||
private $platform_cert_path;
|
||||
//商户私钥证书路径
|
||||
private $merchant_cert_path;
|
||||
//商户私钥证书密码
|
||||
private $merchant_private_pwd;
|
||||
|
||||
private $platform_public_key;
|
||||
private $merchant_private_key;
|
||||
|
||||
//SM4算法IV(base64编码)
|
||||
public $sm4Iv = "T172oxqWwkr8wqB9D7aR7g==";
|
||||
//SM2算法userId
|
||||
public $sm2userId = "1234567812345678";
|
||||
|
||||
public function __construct($mchid, $platform_public_key, $merchant_private_key, $isTest = false)
|
||||
{
|
||||
if(!function_exists('gmp_init')) throw new Exception('请先安装GMP扩展');
|
||||
$this->mchid = $mchid;
|
||||
if($isTest) $this->gateway_url = 'https://paymenttest.dinpay.com/trx';
|
||||
$this->platform_public_key = $platform_public_key;
|
||||
$this->merchant_private_key = $merchant_private_key;
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function execute($path, $data, $file = null, $download = false){
|
||||
//生成16位SM4随机秘钥
|
||||
$sm4Key = random(16);
|
||||
|
||||
//加密后的SM4密钥
|
||||
$encrytionKey = base64_encode(hex2bin('04'.$this->sm2DoEncrypt($sm4Key)));
|
||||
|
||||
$json = json_encode($data);
|
||||
$enc_data = $this->sm4DoEncrypt($json, $sm4Key);
|
||||
$sign = trim($this->sm2DoSign($enc_data));
|
||||
|
||||
$params = [
|
||||
'merchantId' => $this->mchid,
|
||||
'timestamp' => date('YmdHis'),
|
||||
'data' => $enc_data,
|
||||
'encryptionKey' => $encrytionKey,
|
||||
'signatureMethod' => $this->sign_method,
|
||||
'sign' => $sign,
|
||||
];
|
||||
if($file){
|
||||
if($file instanceof \CURLFile){
|
||||
$params['file'] = $file;
|
||||
}
|
||||
$response = get_curl($this->gateway_url.$path, $params);
|
||||
}else{
|
||||
$response = get_curl($this->gateway_url.$path, json_encode($params), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
}
|
||||
if($download) return $response;
|
||||
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['code']) && ($result['code'] == '0000' || $result['code'] == '0001')){
|
||||
if(!empty($result['sign'])){
|
||||
if(!$this->sm2DoVerifySign($result['data'], $result['sign'])){
|
||||
throw new Exception('返回数据验签失败');
|
||||
}
|
||||
}
|
||||
return json_decode($result['data'], true);
|
||||
}elseif(isset($result['msg'])){
|
||||
throw new Exception($result['msg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//使用商户私钥对数据进行sm2签名
|
||||
private function sm2DoSign($signStr){
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64', true);
|
||||
return $sm2->doSign($signStr, $this->merchant_private_key, $this->sm2userId);
|
||||
}
|
||||
|
||||
//使用平台公钥对数据进行sm2验签
|
||||
public function sm2DoVerifySign($signStr,$sign){
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64', true);
|
||||
$isSign = $sm2->verifySign($signStr, $sign, $this->platform_public_key, $this->sm2userId);
|
||||
return $isSign;
|
||||
}
|
||||
|
||||
//使用平台公钥对数据进行sm2加密
|
||||
private function sm2DoEncrypt($plaintext){
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64');
|
||||
return $sm2->doEncrypt($plaintext, $this->platform_public_key);
|
||||
}
|
||||
|
||||
//使用商户私钥对数据进行sm2解密
|
||||
private function sm2DoDecrypt($ciphertext){
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64');
|
||||
return $sm2->doDecrypt($ciphertext, $this->merchant_private_key);
|
||||
}
|
||||
|
||||
//sm4加密
|
||||
private function sm4DoEncrypt($plaintext, $key){
|
||||
$sm4 = new Rtgm\sm\RtSm4($key);
|
||||
return $sm4->encrypt($plaintext,'sm4',base64_decode($this->sm4Iv),'base64');
|
||||
}
|
||||
|
||||
public function sm3ToHex($str){
|
||||
$sm3 = new Rtgm\sm\RtSm3();
|
||||
return $sm3->digest($str);
|
||||
}
|
||||
|
||||
//获取平台公钥
|
||||
private function getDinpayPublicKey(){
|
||||
$cer_public_content = file_get_contents($this->platform_cert_path);
|
||||
$cer_public_content = str_replace(PHP_EOL,'',$cer_public_content);
|
||||
$certificateContent = '-----BEGIN CERTIFICATE-----' . PHP_EOL
|
||||
. chunk_split($cer_public_content, 64, PHP_EOL)
|
||||
. '-----END CERTIFICATE-----'.PHP_EOL;
|
||||
$cer_public_key = openssl_pkey_get_public($certificateContent);
|
||||
if(!$cer_public_key){
|
||||
throw new Exception('读取平台公钥失败:'.openssl_error_string());
|
||||
}
|
||||
$key_detail = openssl_pkey_get_details($cer_public_key);
|
||||
$cerPublicKey = bin2hex($key_detail['ec']['x']).bin2hex($key_detail['ec']['y']); //公钥的ec格式
|
||||
return $cerPublicKey;
|
||||
}
|
||||
|
||||
//获取商户私钥
|
||||
private function getMerchantPrivateKey(){
|
||||
$cert_store = file_get_contents($this->merchant_cert_path);
|
||||
|
||||
$status = openssl_pkcs12_read($cert_store, $cert_info, $this->merchant_private_pwd);
|
||||
if (!$status) {
|
||||
throw new Exception('读取商户私钥失败:'.openssl_error_string());
|
||||
}
|
||||
|
||||
$fpx_private_key = $cert_info['pkey'];
|
||||
$private_key = openssl_pkey_get_private($fpx_private_key);
|
||||
$key_detail = openssl_pkey_get_details($private_key);
|
||||
|
||||
$privateKey = bin2hex($key_detail['ec']['d']);
|
||||
|
||||
return $privateKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
class douyinpay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'douyinpay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '抖音支付', //支付插件显示名称
|
||||
'author' => '抖音支付', //支付插件作者
|
||||
'link' => 'https://pay.douyinpay.com/', //支付插件作者链接
|
||||
'types' => ['douyinpay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '应用ID',
|
||||
'type' => 'input',
|
||||
'note' => '抖音开放平台网站应用Client Key',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '应用Secret',
|
||||
'type' => 'input',
|
||||
'note' => '对应应用的Client Secret,仅JSAPI支付需要填写',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'apikey' => [
|
||||
'name' => '接口加密密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'certserial' => [
|
||||
'name' => '商户API证书序列号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => [ //选择已开启的支付方式
|
||||
'1' => 'Native支付',
|
||||
'2' => 'JSAPI支付',
|
||||
'3' => 'H5支付',
|
||||
'4' => 'APP支付',
|
||||
],
|
||||
'note' => '<p>请将商户API私钥“apiclient_key.pem”放到 /plugins/douyinpay/cert/ 文件夹内(或 /plugins/douyinpay/cert/商户号/ 文件夹内)。</p><p>上方应用ID必须为网站应用,需要在抖音支付后台关联对应的应用才能使用。</p><p>若开启JSAPI支付,需在开放平台配置应用授权回调URL:[siteurl]user/douyinoauth.php</p>', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $submit2, $conf;
|
||||
|
||||
$urlpre = '/';
|
||||
if(checkdouyin() && in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$urlpre.'pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile() && in_array('3',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$urlpre.'pay/h5/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/qrcode/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice, $method;
|
||||
|
||||
$urlpre = $siteurl;
|
||||
if($method=='app'){
|
||||
return self::apppay();
|
||||
}elseif($method=='jsapi'){
|
||||
return self::jspay();
|
||||
}
|
||||
elseif($mdevice=='douyin' && in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$urlpre.'pay/jspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile' && in_array('3',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$urlpre.'pay/h5/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return self::qrcode();
|
||||
}
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
static public function qrcode(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $device, $mdevice;
|
||||
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
|
||||
$param = [
|
||||
'description' => $ordername,
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'amount' => [
|
||||
'total' => intval(round($order['realmoney']*100)),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'scene_info' => [
|
||||
'payer_client_ip' => $clientip
|
||||
]
|
||||
];
|
||||
if($order['profits']>0){
|
||||
$param['settle_info'] = ['profit_sharing' => true];
|
||||
}
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$result = $client->nativePay($param);
|
||||
$code_url = $result['code_url'];
|
||||
} catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'抖音支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/jspay/'.TRADE_NO.'/';
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/h5/'.TRADE_NO.'/';
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'当前支付通道没有开启的支付方式'];
|
||||
}
|
||||
|
||||
if(checkmobile() || $device == 'mobile'){
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_h5','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_wap','url'=>$code_url];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//JS支付
|
||||
static public function jspay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $method;
|
||||
|
||||
require(PAY_ROOT.'inc/DouyinOauth.php');
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
|
||||
if(!empty($order['sub_openid'])){
|
||||
if(!empty($order['sub_appid'])){
|
||||
$channel['appid'] = $order['sub_appid'];
|
||||
}
|
||||
$openid = $order['sub_openid'];
|
||||
}else{
|
||||
$oauth = new \DouYinPay\DouyinOauth($channel['appid'], $channel['appsecret']);
|
||||
$redirect_uri = $siteurl.'user/douyinoauth.php';
|
||||
$state = $_SERVER['REQUEST_URI'];
|
||||
$openid = $oauth->get_openid($redirect_uri, $state);
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($openid, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
//②、统一下单
|
||||
$param = [
|
||||
'description' => $ordername,
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'amount' => [
|
||||
'total' => intval(round($order['realmoney']*100)),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'payer' => [
|
||||
'openid' => $openid
|
||||
],
|
||||
'scene_info' => [
|
||||
'payer_client_ip' => $clientip
|
||||
]
|
||||
];
|
||||
if($order['profits']>0){
|
||||
$param['settle_info'] = ['profit_sharing' => true];
|
||||
}
|
||||
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$result = $client->jsapiPay($param);
|
||||
$jsApiParameters = json_encode($result);
|
||||
} catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'抖音支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$jsApiParameters];
|
||||
}
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'douyinpay_jspay','data'=>['jsApiParameters'=>$jsApiParameters, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//H5支付
|
||||
static public function h5(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$param = [
|
||||
'description' => $ordername,
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'amount' => [
|
||||
'total' => intval(round($order['realmoney']*100)),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'scene_info' => [
|
||||
'payer_client_ip' => $clientip,
|
||||
'h5_info' => [
|
||||
'type' => 'Wap',
|
||||
'app_name' => $conf['sitename'],
|
||||
'app_url' => $siteurl,
|
||||
],
|
||||
]
|
||||
];
|
||||
if($order['profits']>0){
|
||||
$param['settle_info'] = ['profit_sharing' => true];
|
||||
}
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$result = $client->h5Pay($param);
|
||||
$redirect_url=$siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
$url=$result['h5_url'].'&return_url='.urlencode($redirect_url);
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
} catch (Exception $e) {
|
||||
return ['type'=>'error','msg'=>'抖音支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//APP支付
|
||||
static public function apppay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $method;
|
||||
|
||||
$param = [
|
||||
'description' => $ordername,
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'amount' => [
|
||||
'total' => intval(round($order['realmoney']*100)),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'scene_info' => [
|
||||
'payer_client_ip' => $clientip
|
||||
]
|
||||
];
|
||||
if($order['profits']>0){
|
||||
$param['settle_info'] = ['profit_sharing' => true];
|
||||
}
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$result = $client->appPay($param);
|
||||
return ['type'=>'app','data'=>json_encode($result)];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'抖音支付下单失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$data = $client->notify();
|
||||
} catch (Exception $e) {
|
||||
$client->replyNotify(false, $e->getMessage());
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($data['trade_state'] == 'SUCCESS') {
|
||||
if($data['out_trade_no'] == TRADE_NO){
|
||||
processNotify($order, $data['transaction_id'], $data['payer']['openid']);
|
||||
}
|
||||
}
|
||||
$client->replyNotify(true);
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $conf;
|
||||
if(empty($order))exit();
|
||||
|
||||
$param = [
|
||||
'transaction_id' => $order['api_trade_no'],
|
||||
'out_refund_no' => $order['refund_no'],
|
||||
'notify_url' => $conf['localurl'].'pay/refundnotify/'.TRADE_NO.'/',
|
||||
'amount' => [
|
||||
'refund' => intval(round($order['refundmoney']*100)),
|
||||
'total' => intval(round($order['realmoney']*100)),
|
||||
'currency' => 'CNY'
|
||||
]
|
||||
];
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$result = $client->refund($param);
|
||||
$result = ['code'=>0, 'trade_no'=>$result['refund_id'], 'refund_fee'=>$result['amount']['refund']/100];
|
||||
} catch (Exception $e) {
|
||||
$result = ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function refundnotify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$data = $client->notify();
|
||||
} catch (Exception $e) {
|
||||
$client->replyNotify(false, $e->getMessage());
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($data['refund_status'] == 'SUCCESS') {
|
||||
|
||||
}
|
||||
$client->replyNotify(true);
|
||||
}
|
||||
|
||||
//关闭订单
|
||||
static public function close($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT.'inc/PaymentService.php');
|
||||
$douyinpay_config = require(PAY_ROOT.'inc/config.php');
|
||||
try{
|
||||
$client = new \DouYinPay\PaymentService($douyinpay_config);
|
||||
$client->closeOrder($order['trade_no']);
|
||||
$result = ['code'=>0];
|
||||
} catch (Exception $e) {
|
||||
$result = ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
<?php
|
||||
|
||||
namespace DouYinPay;
|
||||
|
||||
require 'DouyinPayException.php';
|
||||
|
||||
use Exception;
|
||||
|
||||
class BaseService
|
||||
{
|
||||
//SDK版本号
|
||||
static $VERSION = "1.0.0";
|
||||
|
||||
static $GATEWAY = "https://api.douyinpay.com";
|
||||
|
||||
//应用ID
|
||||
protected $appId;
|
||||
|
||||
//商户号
|
||||
protected $mchId;
|
||||
|
||||
//接口加密密钥
|
||||
protected $apiKey;
|
||||
|
||||
|
||||
//「商户API私钥」文件路径
|
||||
protected $merchantPrivateKeyFilePath;
|
||||
|
||||
//「商户API证书」的「证书序列号」
|
||||
protected $merchantCertificateSerial;
|
||||
|
||||
//「抖音支付平台公钥证书」文件路径
|
||||
protected $platformCertificateFilePath;
|
||||
|
||||
//抖音支付平台证书序列号
|
||||
protected $platformCertificateSerial;
|
||||
|
||||
//商户API私钥
|
||||
protected $merchantPrivateKeyInstance;
|
||||
|
||||
//抖音支付平台证书
|
||||
protected $platformPublicKeyInstance;
|
||||
|
||||
private $download_cert = false;
|
||||
|
||||
/**
|
||||
* @param array $config 抖音支付配置信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
if (empty($config['appid'])) {
|
||||
throw new \InvalidArgumentException('应用APPID不能为空');
|
||||
}
|
||||
if (empty($config['mchid'])) {
|
||||
throw new \InvalidArgumentException("商户号不能为空");
|
||||
}
|
||||
if (empty($config['apikey'])) {
|
||||
throw new \InvalidArgumentException("商户APIv3密钥不能为空");
|
||||
}
|
||||
if (strlen($config['apikey']) != 32) {
|
||||
throw new \InvalidArgumentException("无效的商户APIv3密钥");
|
||||
}
|
||||
if (empty($config['merchantPrivateKeyFilePath'])) {
|
||||
throw new \InvalidArgumentException("商户API私钥路径不能为空");
|
||||
}
|
||||
if (empty($config['merchantCertificateSerial'])) {
|
||||
throw new \InvalidArgumentException("商户API证书序列号不能为空");
|
||||
}
|
||||
if (!file_exists($config['merchantPrivateKeyFilePath'])) {
|
||||
throw new \InvalidArgumentException("商户API私钥文件不存在");
|
||||
}
|
||||
$this->appId = $config['appid'];
|
||||
$this->mchId = $config['mchid'];
|
||||
$this->apiKey = $config['apikey'];
|
||||
$this->merchantPrivateKeyFilePath = $config['merchantPrivateKeyFilePath'];
|
||||
$this->merchantCertificateSerial = $config['merchantCertificateSerial'];
|
||||
$this->platformCertificateFilePath = $config['platformCertificateFilePath'];
|
||||
$this->initCertificate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化证书与私钥
|
||||
* @throws Exception
|
||||
*/
|
||||
private function initCertificate()
|
||||
{
|
||||
//读取商户API私钥
|
||||
$this->merchantPrivateKeyInstance = openssl_pkey_get_private(file_get_contents($this->merchantPrivateKeyFilePath));
|
||||
if (!$this->merchantPrivateKeyInstance) {
|
||||
throw new Exception("商户API私钥错误");
|
||||
}
|
||||
//读取抖音支付平台证书
|
||||
$this->loadPlatformCertificate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载抖音支付平台证书
|
||||
* @throws Exception
|
||||
*/
|
||||
private function loadPlatformCertificate()
|
||||
{
|
||||
if (file_exists($this->platformCertificateFilePath)) {
|
||||
$certificate = file_get_contents($this->platformCertificateFilePath);
|
||||
$this->platformPublicKeyInstance = openssl_pkey_get_public($certificate);
|
||||
if ($this->platformPublicKeyInstance) {
|
||||
$cert_info = openssl_x509_parse($certificate);
|
||||
if ($cert_info && isset($cert_info['serialNumberHex'])) {
|
||||
$this->platformCertificateSerial = $cert_info['serialNumberHex'];
|
||||
}
|
||||
} else {
|
||||
throw new Exception("抖音支付平台证书错误");
|
||||
}
|
||||
} else {
|
||||
$this->downloadCertificate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载抖音支付平台证书
|
||||
* @throws Exception
|
||||
*/
|
||||
private function downloadCertificate()
|
||||
{
|
||||
$result = $this->execute('GET', '/v1/merchant/certificates/getPlatformCertificates');
|
||||
$effective_time = 0;
|
||||
foreach ($result['certificates'] as $item) {
|
||||
if (strtotime($item['effective_time']) > $effective_time) {
|
||||
$effective_time = strtotime($item['effective_time']);
|
||||
$encert = $item['encrypt_certificate'];
|
||||
}
|
||||
}
|
||||
|
||||
$certificate = $this->decryptToString($encert['cipher_text'], $encert['nonce'], $encert['associated_data'] ?? '');
|
||||
if (!$certificate) {
|
||||
throw new Exception('抖音支付平台证书解密失败');
|
||||
}
|
||||
if (!file_put_contents($this->platformCertificateFilePath, $certificate)) {
|
||||
throw new Exception('抖音支付平台证书保存失败,可能无文件写入权限');
|
||||
}
|
||||
//从证书解析公钥与序列号
|
||||
$this->platformPublicKeyInstance = openssl_x509_read($certificate);
|
||||
if (!$this->platformPublicKeyInstance) {
|
||||
throw new Exception("抖音支付平台证书错误");
|
||||
}
|
||||
$cert_info = openssl_x509_parse($certificate);
|
||||
if ($cert_info && isset($cert_info['serialNumberHex'])) {
|
||||
$this->platformCertificateSerial = $cert_info['serialNumberHex'];
|
||||
}
|
||||
$this->download_cert = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求接口并解析返回数据
|
||||
* @param string $method 请求方式 GET POST PUT
|
||||
* @param string $path 请求路径
|
||||
* @param array $params 请求参数
|
||||
* @param bool $cert 是否包含平台公钥序列号
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(string $method, string $path, array $params = [], bool $cert = false)
|
||||
{
|
||||
$url = self::$GATEWAY . $path;
|
||||
$body = '';
|
||||
if ($method == 'GET' || $method == 'DELETE') {
|
||||
if (count($params) > 0) {
|
||||
$url .= '?' . http_build_query($params);
|
||||
}
|
||||
} elseif(!empty($params)) {
|
||||
$body = json_encode($params);
|
||||
}
|
||||
|
||||
$authorization = $this->getAuthorization($method, $url, $body);
|
||||
$header[] = 'Accept: application/json';
|
||||
$header[] = 'Authorization: DouyinPay-RSA ' . $authorization;
|
||||
if ($cert) {
|
||||
$header[] = 'Douyinpay-Serial: ' . $this->platformCertificateSerial;
|
||||
}
|
||||
if ($method == 'POST' || $method == 'PUT') {
|
||||
$header[] = 'Content-Type: application/json';
|
||||
}
|
||||
|
||||
[$httpCode, $header, $response] = $this->curl($method, $url, $header, $body);
|
||||
$result = json_decode($response, true);
|
||||
if ($httpCode >= 200 && $httpCode <= 299) {
|
||||
if ($path != '/v1/merchant/certificates/getPlatformCertificates' && !$this->checkResponseSign($response, $header)) {
|
||||
throw new Exception("抖音支付返回数据验签失败");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
throw new DouyinPayException($result, $httpCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载账单/图片
|
||||
* @param string $download_url 下载地址
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function download(string $download_url)
|
||||
{
|
||||
$method = 'GET';
|
||||
$authorization = $this->getAuthorization($method, $download_url);
|
||||
$header[] = 'Authorization: DouyinPay-RSA ' . $authorization;
|
||||
[$httpCode, $header, $response] = $this->curl($method, $download_url, $header);
|
||||
if ($httpCode >= 200 && $httpCode <= 299) {
|
||||
return $response;
|
||||
} else {
|
||||
$result = json_decode($response, true);
|
||||
throw new DouyinPayException($result, $httpCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param string $path 请求路径
|
||||
* @param string $file_path 本地文件路径
|
||||
* @param string $file_name 文件名
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upload(string $path, string $file_path, string $file_name)
|
||||
{
|
||||
$url = self::$GATEWAY . $path;
|
||||
if (!file_exists($file_path)) {
|
||||
throw new Exception("文件不存在");
|
||||
}
|
||||
$meta = [
|
||||
'filename' => $file_name,
|
||||
'sha256' => hash_file("sha256", $file_path)
|
||||
];
|
||||
$meta_json = json_encode($meta);
|
||||
$params = [
|
||||
'file' => new \CURLFile($file_path, '', $file_name),
|
||||
'meta' => $meta_json
|
||||
];
|
||||
|
||||
$authorization = $this->getAuthorization('POST', $url, $meta_json);
|
||||
$header[] = 'Accept: application/json';
|
||||
$header[] = 'Authorization: DouyinPay-RSA ' . $authorization;
|
||||
[$httpCode, $header, $response] = $this->curl('POST', $url, $header, $params);
|
||||
$result = json_decode($response, true);
|
||||
if ($httpCode >= 200 && $httpCode <= 299) {
|
||||
if (!$this->checkResponseSign($response, $header)) {
|
||||
throw new Exception("抖音支付返回数据验签失败");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
throw new DouyinPayException($result, $httpCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回数据验签
|
||||
* @param string $body 返回内容
|
||||
* @param string $header 返回头部
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function checkResponseSign(string $body, string $header): bool
|
||||
{
|
||||
if (!$this->platformCertificateSerial) return true;
|
||||
|
||||
if (preg_match('/Douyinpay-Signature: (.*?)\r\n/i', $header, $signature)) {
|
||||
$signature = $signature[1];
|
||||
}
|
||||
if (preg_match('/Douyinpay-Nonce: (.*?)\r\n/i', $header, $nonce)) {
|
||||
$nonce = $nonce[1];
|
||||
}
|
||||
if (preg_match('/Douyinpay-Timestamp: (.*?)\r\n/i', $header, $timestamp)) {
|
||||
$timestamp = $timestamp[1];
|
||||
}
|
||||
if (preg_match('/Douyinpay-Serial: (.*?)\r\n/i', $header, $serial)) {
|
||||
$serial = $serial[1];
|
||||
}
|
||||
|
||||
if (empty($signature)) return false;
|
||||
if ($serial != $this->platformCertificateSerial) {
|
||||
if (!$this->download_cert) {
|
||||
$this->downloadCertificate();
|
||||
}
|
||||
if ($serial != $this->platformCertificateSerial) {
|
||||
throw new Exception('平台证书序列号不匹配');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->checkSign($timestamp, $nonce, $body, $signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名
|
||||
* @param string $timestamp 应答时间戳
|
||||
* @param string $nonce 应答随机串
|
||||
* @param string $body 应答报文主体
|
||||
* @param string $signature 应答签名
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkSign(string $timestamp, string $nonce, string $body, string $signature): bool
|
||||
{
|
||||
$message = $timestamp . "\n" . $nonce . "\n" . $body . "\n";
|
||||
$result = openssl_verify($message, base64_decode($signature), $this->platformPublicKeyInstance, OPENSSL_ALGO_SHA256);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名
|
||||
* @param array $arr - 待签名数组
|
||||
* @return string
|
||||
*/
|
||||
protected function makeSign(array $arr): string
|
||||
{
|
||||
$message = implode("\n", array_merge($arr, ['']));
|
||||
openssl_sign($message, $sign, $this->merchantPrivateKeyInstance, OPENSSL_ALGO_SHA256);
|
||||
return base64_encode($sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成authorization
|
||||
* @param string $method 请求方式 GET POST PUT
|
||||
* @param string $url 请求URL
|
||||
* @param string $body 请求内容 GET时留空
|
||||
*/
|
||||
protected function getAuthorization(string $method, string $url, string $body = ''): string
|
||||
{
|
||||
$url_values = parse_url($url);
|
||||
$url = $url_values['path'] . (isset($url_values['query']) ? ('?' . $url_values['query']) : '');
|
||||
$timestamp = (string)time();
|
||||
$nonce = $this->getNonceStr();
|
||||
$sign = $this->makeSign([$method, $url, $timestamp, $nonce, $body]);
|
||||
return sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $this->mchId, $nonce, $timestamp, $this->merchantCertificateSerial, $sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步回调处理
|
||||
* @return array 回调解密后的数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public function notify(): array
|
||||
{
|
||||
$inDouyinpaySignature = $_SERVER['HTTP_DOUYINPAY_SIGNATURE'];
|
||||
$inDouyinpayTimestamp = $_SERVER['HTTP_DOUYINPAY_TIMESTAMP'];
|
||||
$inDouyinpaySerial = $_SERVER['HTTP_DOUYINPAY_SERIAL'];
|
||||
$inDouyinpayNonce = $_SERVER['HTTP_DOUYINPAY_NONCE'];
|
||||
$inBody = file_get_contents('php://input');
|
||||
|
||||
if (empty($inBody)) {
|
||||
throw new Exception('no data');
|
||||
}
|
||||
if ($this->platformCertificateSerial != $inDouyinpaySerial) {
|
||||
if (!$this->download_cert) {
|
||||
$this->downloadCertificate();
|
||||
}
|
||||
if ($inDouyinpaySerial != $this->platformCertificateSerial) {
|
||||
throw new Exception('平台证书序列号不匹配');
|
||||
}
|
||||
}
|
||||
|
||||
// 使用平台API证书验签
|
||||
if (!$this->checkSign($inDouyinpayTimestamp, $inDouyinpayNonce, $inBody, $inDouyinpaySignature)) {
|
||||
throw new Exception('签名校验失败');
|
||||
}
|
||||
|
||||
// 转换通知的JSON文本消息为PHP Array数组
|
||||
$inBodyArray = (array)json_decode($inBody, true);
|
||||
// 使用PHP7的数据解构语法,从Array中解构并赋值变量
|
||||
['resource' => [
|
||||
'ciphertext' => $ciphertext,
|
||||
'nonce' => $nonce,
|
||||
'associated_data' => $associated_data
|
||||
]] = $inBodyArray;
|
||||
// 加密文本消息解密
|
||||
$inBodyResource = $this->decryptToString($ciphertext, $nonce, $associated_data);
|
||||
if (!$inBodyResource) {
|
||||
throw new Exception('数据解密失败');
|
||||
}
|
||||
// 把解密后的文本转换为PHP Array数组
|
||||
// print_r($inBodyResourceArray);
|
||||
return json_decode($inBodyResource, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复通知
|
||||
* @param bool $isSuccess 是否成功
|
||||
* @param string|null $msg 失败原因
|
||||
*/
|
||||
public function replyNotify(bool $isSuccess = true, ?string $msg = '')
|
||||
{
|
||||
$data = [];
|
||||
if ($isSuccess) {
|
||||
$data['code'] = 'SUCCESS';
|
||||
} else {
|
||||
@header("HTTP/1.1 499 Error");
|
||||
$data['code'] = 'FAIL';
|
||||
$data['message'] = $msg;
|
||||
}
|
||||
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
echo $json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 产生随机字符串,不长于32位
|
||||
* @param int $length
|
||||
* @return string 产生的随机字符串
|
||||
*/
|
||||
protected function getNonceStr(int $length = 32): string
|
||||
{
|
||||
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 敏感信息RSA加密
|
||||
* @param $str
|
||||
* @return string|bool
|
||||
*/
|
||||
public function rsaEncrypt($str)
|
||||
{
|
||||
if (openssl_public_encrypt($str, $encrypted, $this->platformPublicKeyInstance, OPENSSL_PKCS1_OAEP_PADDING)) {
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 敏感信息RSA解密
|
||||
* @param $str
|
||||
* @return string|bool
|
||||
*/
|
||||
public function rsaDecrypt($str)
|
||||
{
|
||||
if (openssl_private_decrypt(base64_decode($str), $decrypted, $this->merchantPrivateKeyInstance, OPENSSL_PKCS1_OAEP_PADDING)) {
|
||||
return $decrypted;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密AEAD AES 256gcm密文
|
||||
* @param string $ciphertext AES GCM cipher text
|
||||
* @param string $nonceStr AES GCM nonce
|
||||
* @param string $associatedData AES GCM additional authentication data
|
||||
*
|
||||
* @return string|bool Decrypted string on success or FALSE on failure
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function decryptToString(string $ciphertext, string $nonceStr, string $associatedData = '')
|
||||
{
|
||||
$ciphertext = base64_decode($ciphertext);
|
||||
if (strlen($ciphertext) <= 16) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists('sodium_crypto_aead_aes256gcm_is_available') && sodium_crypto_aead_aes256gcm_is_available()) {
|
||||
return sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->apiKey);
|
||||
}
|
||||
if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', openssl_get_cipher_methods())) {
|
||||
$ctext = substr($ciphertext, 0, -16);
|
||||
$authTag = substr($ciphertext, -16);
|
||||
|
||||
return openssl_decrypt($ctext, 'aes-256-gcm', $this->apiKey, OPENSSL_RAW_DATA, $nonceStr, $authTag, $associatedData);
|
||||
}
|
||||
|
||||
throw new Exception('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起curl请求
|
||||
* @param string $method 请求方式 GET POST PUT
|
||||
* @param string $url 请求URL
|
||||
* @param array $header 请求头部
|
||||
* @param null $body POST内容
|
||||
* @param int $timeout 超时时间
|
||||
* @return array [http状态码,响应头部,响应数据]
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function curl(string $method, string $url, array $header, $body = null, int $timeout = 10): array
|
||||
{
|
||||
$ch = curl_init();
|
||||
$curlVersion = curl_version();
|
||||
$ua = "douyinpay-php/" . self::$VERSION . " curl/" . $curlVersion['version'] . " (" . PHP_OS . "/" . php_uname('r') . ") PHP/" . PHP_VERSION;
|
||||
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
if ($method == 'POST') {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
} elseif ($method == 'PUT') {
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
} elseif ($method == 'DELETE') {
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
}
|
||||
$data = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new Exception($errmsg, 0);
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($data, 0, $headerSize);
|
||||
$body = substr($data, $headerSize);
|
||||
curl_close($ch);
|
||||
return [$httpCode, $header, $body];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace DouYinPay;
|
||||
|
||||
use Exception;
|
||||
|
||||
class DouyinOauth
|
||||
{
|
||||
private $client_key;
|
||||
private $client_secret;
|
||||
|
||||
public function __construct($client_key, $client_secret)
|
||||
{
|
||||
$this->client_key = $client_key;
|
||||
$this->client_secret = $client_secret;
|
||||
}
|
||||
|
||||
public function get_openid($redirect_uri, $state = null)
|
||||
{
|
||||
if (isset($_GET['code'])) {
|
||||
$code = $_GET['code'];
|
||||
$data = $this->callback($code);
|
||||
return $data['open_id'];
|
||||
}else{
|
||||
$this->login($redirect_uri, $state);
|
||||
}
|
||||
}
|
||||
|
||||
public function login($redirect_uri, $state = null)
|
||||
{
|
||||
$param = [
|
||||
"client_key" => $this->client_key,
|
||||
"scope" => "login_id",
|
||||
"response_type" => "code",
|
||||
"redirect_uri" => $redirect_uri,
|
||||
];
|
||||
if($state) $param['state'] = $state;
|
||||
$url = 'https://aweme.snssdk.com/passport/open/silent_auth/?' . http_build_query($param);
|
||||
Header("Location: $url");
|
||||
exit;
|
||||
}
|
||||
|
||||
public function callback(string $code): array
|
||||
{
|
||||
$param = [
|
||||
"client_key" => $this->client_key,
|
||||
"client_secret" => $this->client_secret,
|
||||
"code" => $code,
|
||||
"grant_type" => "authorization_code"
|
||||
];
|
||||
$url = 'https://open.douyin.com/oauth/access_token/';
|
||||
$res = get_curl($url, http_build_query($param));
|
||||
$data = json_decode($res, true);
|
||||
if (isset($data['data']['error_code']) && $data['data']['error_code'] == 0) {
|
||||
return $data['data'];
|
||||
} elseif (isset($data['data']['error_code'])) {
|
||||
throw new Exception('Openid获取失败 [' . $data['data']['error_code'] . ']' . $data['data']['description']);
|
||||
} else {
|
||||
throw new Exception('Openid获取失败,原因未知');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace DouYinPay;
|
||||
|
||||
/**
|
||||
* 抖音支付响应内容异常
|
||||
*/
|
||||
class DouyinPayException extends \Exception
|
||||
{
|
||||
private $res = [];
|
||||
private $errCode;
|
||||
private $httpCode;
|
||||
|
||||
/**
|
||||
* @param array $res
|
||||
* @param string $httpCode
|
||||
*/
|
||||
public function __construct($res, $httpCode)
|
||||
{
|
||||
$this->res = $res;
|
||||
$this->httpCode = $httpCode;
|
||||
if(is_array($res)){
|
||||
$this->errCode = $res['code'];
|
||||
$message = '['.$res['code'].']'.$res['message'].(isset($res['detail']['issue'])?'('.$res['detail']['issue'].')':'');
|
||||
}else{
|
||||
$message = '返回数据解析失败(http_code='.$httpCode.')';
|
||||
}
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
public function getResponse(): array
|
||||
{
|
||||
return $this->res;
|
||||
}
|
||||
|
||||
public function getErrCode()
|
||||
{
|
||||
return $this->errCode;
|
||||
}
|
||||
|
||||
public function getHttpCode(): string
|
||||
{
|
||||
return $this->httpCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace DouYinPay;
|
||||
|
||||
require 'BaseService.php';
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 基础支付服务类
|
||||
* @see https://pay.douyinpay.com/wiki
|
||||
*/
|
||||
class PaymentService extends BaseService
|
||||
{
|
||||
public function __construct(array $config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* NATIVE支付
|
||||
* @param array $params 下单参数
|
||||
* @return mixed {"code_url":"二维码链接"}
|
||||
* @throws Exception
|
||||
*/
|
||||
public function nativePay(array $params){
|
||||
$path = '/v1/trade/transactions/native';
|
||||
$publicParams = [
|
||||
'appid' => $this->appId,
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('POST', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSAPI支付
|
||||
* @param array $params 下单参数
|
||||
* @return array Jsapi支付json数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public function jsapiPay(array $params): array
|
||||
{
|
||||
$path = '/v1/trade/transactions/jsapi';
|
||||
$publicParams = [
|
||||
'appid' => $this->appId,
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
$result = $this->execute('POST', $path, $params);
|
||||
return $this->getJsApiParameters($result['prepay_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JSAPI支付的参数
|
||||
* @param string $prepay_id 预支付交易会话标识
|
||||
* @return array json数据
|
||||
*/
|
||||
private function getJsApiParameters(string $prepay_id): array
|
||||
{
|
||||
$params = [
|
||||
'appId' => $this->appId,
|
||||
'timeStamp' => time().'',
|
||||
'nonceStr' => $this->getNonceStr(),
|
||||
'package' => 'prepay_id=' . $prepay_id,
|
||||
];
|
||||
$params['paySign'] = $this->makeSign([$params['appId'], $params['timeStamp'], $params['nonceStr'], $params['package']]);
|
||||
$params['signType'] = 'DouyinPay-RSA';
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* H5支付
|
||||
* @param array $params 下单参数
|
||||
* @return mixed {"h5_url":"支付跳转链接"}
|
||||
* @throws Exception
|
||||
*/
|
||||
public function h5Pay(array $params){
|
||||
$path = '/v1/trade/transactions/h5';
|
||||
$publicParams = [
|
||||
'appid' => $this->appId,
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('POST', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* APP支付
|
||||
* @param array $params 下单参数
|
||||
* @return array APP支付json数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public function appPay(array $params): array
|
||||
{
|
||||
$path = '/v1/trade/transactions/app';
|
||||
$publicParams = [
|
||||
'appid' => $this->appId,
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
$result = $this->execute('POST', $path, $params);
|
||||
return $this->getAppParameters($result['prepay_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取APP支付的参数
|
||||
* @param string $prepay_id 预支付交易会话标识
|
||||
* @return array
|
||||
*/
|
||||
private function getAppParameters(string $prepay_id): array
|
||||
{
|
||||
$params = [
|
||||
'appid' => $this->appId,
|
||||
'partnerid' => $this->mchId,
|
||||
'prepayid' => $prepay_id,
|
||||
'package' => 'Sign=DYPay',
|
||||
'noncestr' => $this->getNonceStr(),
|
||||
'timestamp' => time().'',
|
||||
];
|
||||
$params['sign'] = $this->makeSign([$params['appid'], $params['timestamp'], $params['noncestr'], $params['prepayid']]);
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单,抖音订单号、商户订单号至少填一个
|
||||
* @param string|null $transaction_id 抖音订单号
|
||||
* @param string|null $out_trade_no 商户订单号
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function orderQuery(string $transaction_id = null, string $out_trade_no = null){
|
||||
if(!empty($transaction_id)){
|
||||
$path = '/v1/trade/transactions/id/'.$transaction_id;
|
||||
}elseif(!empty($out_trade_no)){
|
||||
$path = '/v1/trade/transactions/out-trade-no/'.$out_trade_no;
|
||||
}else{
|
||||
throw new Exception('抖音支付订单号和商户订单号不能同时为空');
|
||||
}
|
||||
|
||||
$params = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断订单是否已完成
|
||||
* @param string $transaction_id 抖音订单号
|
||||
* @return bool
|
||||
*/
|
||||
public function orderQueryResult(string $transaction_id): bool
|
||||
{
|
||||
try {
|
||||
$data = $this->orderQuery($transaction_id);
|
||||
return $data['trade_state'] == 'SUCCESS' || $data['trade_state'] == 'REFUND';
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
* @param string $out_trade_no 商户订单号
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function closeOrder(string $out_trade_no){
|
||||
$path = '/v1/trade/transactions/out-trade-no/'.$out_trade_no.'/close';
|
||||
$params = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
return $this->execute('POST', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refund(array $params){
|
||||
$path = '/v1/trade/refund/domestic/refunds';
|
||||
$publicParams = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('POST', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
* @param string $out_refund_no
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refundQuery(string $out_refund_no){
|
||||
$path = '/v1/trade/refund/domestic/refunds/'.$out_refund_no;
|
||||
$params = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请交易账单
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function tradeBill(array $params){
|
||||
$path = '/v1/bill/billapply';
|
||||
$publicParams = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请资金账单
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fundflowBill(array $params){
|
||||
$path = '/v1/bill/fundflowbill';
|
||||
$publicParams = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请结算账单
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function billApply(array $params){
|
||||
$path = '/v1/bill/billapply';
|
||||
$publicParams = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请分账账单
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function splitBill(array $params){
|
||||
$path = '/v1/bill/splitbill';
|
||||
$publicParams = [
|
||||
'mchid' => $this->mchId,
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
return $this->execute('GET', $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付通知处理
|
||||
* @return array 支付成功通知参数
|
||||
* @throws Exception
|
||||
*/
|
||||
public function notify(): array
|
||||
{
|
||||
$data = parent::notify();
|
||||
if (!$data || !isset($data['transaction_id'])) {
|
||||
throw new Exception('缺少订单号参数');
|
||||
}
|
||||
if (!$this->orderQueryResult($data['transaction_id'])) {
|
||||
throw new Exception('订单未完成');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
//抖音支付配置文件
|
||||
|
||||
$douyinpay_config = [
|
||||
//应用ID
|
||||
'appid' => $channel['appid'],
|
||||
|
||||
//商户号
|
||||
'mchid' => $channel['appmchid'],
|
||||
|
||||
//接口加密密钥
|
||||
'apikey' => $channel['apikey'],
|
||||
|
||||
//「商户API私钥」文件路径
|
||||
'merchantPrivateKeyFilePath' => PLUGIN_ROOT.$channel['plugin'].'/cert/apiclient_key.pem',
|
||||
|
||||
//「商户API证书」的「证书序列号」
|
||||
'merchantCertificateSerial' => $channel['certserial'],
|
||||
|
||||
//「微信支付平台证书」文件路径
|
||||
'platformCertificateFilePath' => PLUGIN_ROOT.$channel['plugin'].'/cert/cert.pem',
|
||||
];
|
||||
|
||||
if(file_exists(PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appmchid'].'/apiclient_key.pem')){
|
||||
$douyinpay_config['merchantPrivateKeyFilePath'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appmchid'].'/apiclient_key.pem';
|
||||
$douyinpay_config['platformCertificateFilePath'] = PLUGIN_ROOT.$channel['plugin'].'/cert/'.$channel['appmchid'].'/cert.pem';
|
||||
}
|
||||
|
||||
return $douyinpay_config;
|
||||
@@ -0,0 +1,530 @@
|
||||
<?php
|
||||
|
||||
class duolabao_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'duolabao', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '哆啦宝支付', //支付插件显示名称
|
||||
'author' => '哆啦宝', //支付插件作者
|
||||
'link' => 'https://www.duolabao.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','qqpay','bank','jdpay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'agentNum' => [
|
||||
'name' => '代理商编号',
|
||||
'type' => 'input',
|
||||
'note' => '非代理商不需要填写',
|
||||
],
|
||||
'customerNum' => [
|
||||
'name' => '商户编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'shopNum' => [
|
||||
'name' => '店铺编号',
|
||||
'type' => 'input',
|
||||
'note' => '此项可留空',
|
||||
],
|
||||
'accessKey' => [
|
||||
'name' => '公钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'secretKey' => [
|
||||
'name' => '私钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
],
|
||||
'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){
|
||||
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/'.$order['typename'].'/'.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){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}else{
|
||||
$typename = $order['typename'];
|
||||
return self::$typename();
|
||||
}
|
||||
}
|
||||
|
||||
//通用创建订单
|
||||
static public function qrcode(){
|
||||
global $channel, $order, $ordername, $conf, $clientip, $siteurl;
|
||||
|
||||
require PAY_ROOT.'inc/PayApp.class.php';
|
||||
$client = new PayApp($channel['accessKey'], $channel['secretKey']);
|
||||
|
||||
$param = [
|
||||
'version' => 'V4.0',
|
||||
'agentNum' => $channel['agentNum'],
|
||||
'customerNum' => $channel['customerNum'],
|
||||
'shopNum' => $channel['shopNum'],
|
||||
'requestNum' => TRADE_NO,
|
||||
'orderAmount' => $order['realmoney'],
|
||||
'subOrderType' => 'NORMAL',
|
||||
'orderType' => 'SALES',
|
||||
'timeExpire' => date('Y-m-d H:i:s', time() + 7200),
|
||||
'businessType' => 'QRCODE_TRAD',
|
||||
'payModel' => 'ONCE',
|
||||
'source' => 'API',
|
||||
'callbackUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'completeUrl' => $siteurl . 'pay/return/' . TRADE_NO . '/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
$result = $client->submitNew('/api/generateQRCodeUrl', $param);
|
||||
return $result['url'];
|
||||
}
|
||||
|
||||
//通用创建订单
|
||||
static public function jspay($bankType, $authCode, $appId = null){
|
||||
global $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require PAY_ROOT.'inc/PayApp.class.php';
|
||||
$client = new PayApp($channel['accessKey'], $channel['secretKey']);
|
||||
|
||||
$param = [
|
||||
'version' => 'V4.0',
|
||||
'agentNum' => $channel['agentNum'],
|
||||
'customerNum' => $channel['customerNum'],
|
||||
'shopNum' => $channel['shopNum'],
|
||||
'bankType' => $bankType,
|
||||
'paySource' => $bankType,
|
||||
'authCode' => $authCode,
|
||||
'requestNum' => TRADE_NO,
|
||||
'orderAmount' => $order['realmoney'],
|
||||
'subOrderType' => 'NORMAL',
|
||||
'orderType' => 'SALES',
|
||||
'payType' => 'ACTIVE',
|
||||
'businessType' => 'QRCODE_TRAD',
|
||||
'payModel' => 'ONCE',
|
||||
'source' => 'API',
|
||||
'timeExpire' => date('Y-m-d H:i:s', time() + 7200),
|
||||
'callbackUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
if($appId) {
|
||||
$param['appId'] = $appId;
|
||||
$param['subAppId'] = $appId;
|
||||
}
|
||||
if($order['profits']>0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
$result = $client->submitNew('/api/createPayWithCheck', $param);
|
||||
return $result['bankRequest'];
|
||||
}
|
||||
|
||||
static private function handleProfits(&$params){
|
||||
global $order;
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$list = [];
|
||||
$allmoney = 0;
|
||||
foreach($psreceiver['info'] as $receiver){
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']) / 100, 2);
|
||||
$list[] = [
|
||||
'customerNum' => $receiver['account'],
|
||||
'amount' => sprintf('%.2f' , $psmoney),
|
||||
];
|
||||
$allmoney += $psmoney;
|
||||
}
|
||||
$psmoney2 = round($order['realmoney']-$allmoney, 2);
|
||||
if($psmoney2 > 0){
|
||||
$list[] = [
|
||||
'customerNum' => $params['customerNum'],
|
||||
'amount' => sprintf('%.2f' , $psmoney2),
|
||||
];
|
||||
}
|
||||
$params['LedgerRequest'] = [
|
||||
'ledgerType' => 'FIXED',
|
||||
'ledgerFeeAssume' => 'FIXED',
|
||||
'list' => $list,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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::qrcode();
|
||||
}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{
|
||||
$result = self::jspay('ALIPAY', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['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'=>$result['TRADENO'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $siteurl, $device, $mdevice, $channel;
|
||||
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
if($channel['appwxmp']>0){
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}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, $ordername, $conf, $method;
|
||||
|
||||
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::jspay($order['is_applet'] == 1 ? 'WX_XCX' : 'WX', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
$payinfo = ['appId'=>$result['APPID'], 'timeStamp'=>$result['TIMESTAMP'], 'nonceStr'=>$result['NONCESTR'], 'package'=>$result['PACKAGE'], 'signType'=>$result['SIBGTYPE'], 'paySign'=>$result['PAYSIGN']];
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>json_encode($payinfo)];
|
||||
}
|
||||
|
||||
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($payinfo), 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信小程序支付
|
||||
static public function wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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::jspay('WX_XCX', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
$payinfo = ['appId'=>$result['APPID'], 'timeStamp'=>$result['TIMESTAMP'], 'nonceStr'=>$result['NONCESTR'], 'package'=>$result['PACKAGE'], 'signType'=>$result['SIGNTYPE'], 'paySign'=>$result['PAYSIGN']];
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>$payinfo]));
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
$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];
|
||||
}
|
||||
|
||||
//QQ扫码支付
|
||||
static public function qqpay(){
|
||||
global $siteurl, $device, $mdevice;
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'QQ钱包支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if(checkmobbileqq() || $mdevice == 'qq'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
} elseif((checkmobile() || $device == 'mobile') && !isset($_GET['qrcode'])){
|
||||
return ['type'=>'qrcode','page'=>'qqpay_wap','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'qqpay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if (checkmobile()) {
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//京东支付
|
||||
static public function jdpay(){
|
||||
try{
|
||||
$code_url = self::qrcode();
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'京东支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if (checkmobile()) {
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'jdpay_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 PAY_ROOT.'inc/PayApp.class.php';
|
||||
$client = new PayApp($channel['accessKey'], $channel['secretKey']);
|
||||
|
||||
if ($client->verifyNotify($json)) {
|
||||
$trade_no = $arr['requestNum'];
|
||||
$api_trade_no = $arr['orderNum'];
|
||||
$orderAmount = $arr['orderAmount'];
|
||||
$bill_trade_no = $arr['bankOutTradeNum'];
|
||||
$bill_mch_trade_no = $arr['bankRequestNum'];
|
||||
$buyer = $arr['subOpenId'];
|
||||
if ($arr['status'] == 'SUCCESS') {
|
||||
if ($trade_no == TRADE_NO && round($order['money'],2) == round($orderAmount,2)) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
} else {
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require PAY_ROOT.'inc/PayApp.class.php';
|
||||
$client = new PayApp($channel['accessKey'], $channel['secretKey']);
|
||||
|
||||
$param = [
|
||||
'requestVersion' => 'V4.0',
|
||||
'agentNum' => $channel['agentNum'],
|
||||
'customerNum' => $channel['customerNum'],
|
||||
'shopNum' => $channel['shopNum'],
|
||||
'requestNum' => $order['trade_no'],
|
||||
'refundPartAmount' => $order['refundmoney'],
|
||||
'refundRequestNum' => $order['refund_no'],
|
||||
'extMap' => ['refund_status_type'=>'1'],
|
||||
];
|
||||
if($order['profits'] > 0){
|
||||
$psorder = \lib\ProfitSharing\CommUtil::getOrder($order['trade_no']);
|
||||
if($psorder && ($psorder['status'] == 1 || $psorder['status'] == 2)){
|
||||
if($psorder['rdata']){
|
||||
$leftmoney = (float)$order['refundmoney'];
|
||||
$div_members = [];
|
||||
foreach($psorder['rdata'] as $receiver){
|
||||
$money = $receiver['money'] > $leftmoney ? $leftmoney : $receiver['money'];
|
||||
$div_members[] = [
|
||||
'customerNum' => $receiver['account'],
|
||||
'amount' => sprintf('%.2f' , $money),
|
||||
];
|
||||
$leftmoney -= $money;
|
||||
if($leftmoney <= 0) break;
|
||||
}
|
||||
$param['list'] = $div_members;
|
||||
}else{
|
||||
$amount = $psorder['money'] > $order['refundmoney'] ? $order['refundmoney'] : $psorder['money'];
|
||||
$div_members[] = [
|
||||
'customerNum' => $psorder['account'],
|
||||
'amount' => sprintf('%.2f' , $amount),
|
||||
];
|
||||
if($order['refundmoney'] > $psorder['money']){
|
||||
$amount = round($order['refundmoney'] - $psorder['money'], 2);
|
||||
$div_members[] = [
|
||||
'customerNum' => $param['customerNum'],
|
||||
'amount' => sprintf('%.2f' , $amount),
|
||||
];
|
||||
}
|
||||
$param['list'] = $div_members;
|
||||
}
|
||||
}
|
||||
}
|
||||
try{
|
||||
$result = $client->submitNew('/api/refundByRequestNum', $param);
|
||||
return ['code'=>0, 'trade_no'=>$result['orderNum'], 'refund_fee'=>$result['refundAmount']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1,'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//进件回调
|
||||
static public function applynotify(){
|
||||
global $channel, $order, $DB;
|
||||
|
||||
require PAY_ROOT.'inc/PayApp.class.php';
|
||||
$client = new PayApp($channel['accessKey'], $channel['secretKey']);
|
||||
|
||||
if ($client->verifyNotify()) {
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($_GET);
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
} else {
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://mer.jd.com/open/?agg_recpt
|
||||
*/
|
||||
class PayApp
|
||||
{
|
||||
const GATEWAY = 'https://openapi.duolabao.com';
|
||||
private $accessKey;
|
||||
private $secretKey;
|
||||
|
||||
function __construct($accessKey, $secretKey)
|
||||
{
|
||||
$this->accessKey = $accessKey;
|
||||
$this->secretKey = $secretKey;
|
||||
}
|
||||
|
||||
public function submit($path, $param = null){
|
||||
$body = $param ? json_encode($param, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '';
|
||||
$time = time();
|
||||
$token = $this->get_token($time, $path, $body);
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'accessKey: ' . $this->accessKey,
|
||||
'timestamp: ' . $time,
|
||||
'token: ' . $token
|
||||
];
|
||||
$path = implode('/', array_map('urlencode', explode('/', $path)));
|
||||
$response = $this->curl($path, $headers, $body);
|
||||
$result = json_decode($response, true);
|
||||
if($result['result'] == 'success'){
|
||||
return $result['data'];
|
||||
}elseif(isset($result['error'])){
|
||||
throw new Exception('['.$result['error']['errorCode'].']'.$result['error']['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('接口请求失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function submitNew($path, $param = null){
|
||||
$body = $param ? json_encode($param, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '';
|
||||
$time = time();
|
||||
$token = $this->get_token($time, $path, $body);
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'accessKey: ' . $this->accessKey,
|
||||
'timestamp: ' . $time,
|
||||
'token: ' . $token
|
||||
];
|
||||
$path = implode('/', array_map('urlencode', explode('/', $path)));
|
||||
$response = $this->curl($path, $headers, $body);
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['success']) && $result['success']===true || isset($result['result']) && $result['result']===true){
|
||||
return $result;
|
||||
}elseif(isset($result['errorCode'])){
|
||||
throw new Exception('['.$result['errorCode'].']'.$result['errorMsg']);
|
||||
}elseif(isset($result['msg'])){
|
||||
throw new Exception('['.$result['code'].']'.$result['msg']);
|
||||
}elseif(isset($result['message'])){
|
||||
throw new Exception('['.$result['code'].']'.$result['message']);
|
||||
}else{
|
||||
throw new Exception('接口请求失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyNotify($body = null)
|
||||
{
|
||||
$timestamp = $_SERVER['HTTP_TIMESTAMP'];
|
||||
$token = $this->get_token($timestamp, null, $body);
|
||||
if ($token === $_SERVER['HTTP_TOKEN']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function get_token($time, $path, $body){
|
||||
$sign_data = [
|
||||
'secretKey' => $this->secretKey,
|
||||
'timestamp' => $time,
|
||||
];
|
||||
if($path) $sign_data['path'] = $path;
|
||||
if($body) $sign_data['body'] = $body;
|
||||
$o = '';
|
||||
foreach ($sign_data as $k => $v) {
|
||||
$o .= "{$k}={$v}&";
|
||||
}
|
||||
$o = substr($o , 0 , -1);
|
||||
$token = strtoupper(sha1($o));
|
||||
return $token;
|
||||
}
|
||||
|
||||
private function curl($path, $headers, $post = null)
|
||||
{
|
||||
$url = self::GATEWAY . $path;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Encoding: gzip,deflate";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.9";
|
||||
$httpheader[] = "Connection: keep-alive";
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
if ($post) {
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($httpheader, $headers));
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,582 @@
|
||||
<?php
|
||||
|
||||
class easypay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'easypay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '易生易企通', //支付插件显示名称
|
||||
'author' => '易生', //支付插件作者
|
||||
'link' => 'https://www.easypay.com.cn/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'reqtype' => [
|
||||
'name' => '接入模式',
|
||||
'type' => 'select',
|
||||
'options' => [2=>'机构模式',1=>'商户模式'],
|
||||
],
|
||||
'appid' => [
|
||||
'name' => '机构号/商户号',
|
||||
'type' => 'input',
|
||||
'note' => 'reqId',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '子商户号',
|
||||
'type' => 'input',
|
||||
'note' => '机构模式下填写子商户号,非机构模式请勿填写',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '易生公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '不能有换行和标签',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '不能有换行和标签',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '环境选择',
|
||||
'type' => 'select',
|
||||
'options' => [0=>'生产环境',1=>'测试环境'],
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '主扫支付',
|
||||
'2' => 'JSAPI支付',
|
||||
],
|
||||
'select_bank' => [
|
||||
'1' => '主扫支付',
|
||||
'2' => 'JSAPI支付',
|
||||
],
|
||||
'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() && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile() && $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']=='bank'){
|
||||
return self::bankjs();
|
||||
}
|
||||
}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' && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile' && $channel['appwxa']>0){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//扫码支付接口
|
||||
static private function qrcode($pay_type){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => TRADE_NO,
|
||||
'transAmount' => intval(round($order['realmoney']*100)),
|
||||
'orderSub' => $ordername,
|
||||
'backUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
],
|
||||
'payInfo' => [
|
||||
'payType' => $pay_type,
|
||||
'transDate' => date('Ymd'),
|
||||
],
|
||||
'settleParamInfo' => [
|
||||
'delaySettleFlag' => '0',
|
||||
'patnerSettleFlag' => '0',
|
||||
'splitSettleFlag' => '0',
|
||||
],
|
||||
'riskData' => [
|
||||
'customerIp' => $clientip,
|
||||
],
|
||||
];
|
||||
if(strpos($pay_type, 'UnionPay') === 0){
|
||||
$params['qrBizParam'] = [
|
||||
'transType' => '10',
|
||||
'areaInfo' => '1561000',
|
||||
];
|
||||
}
|
||||
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
$result = \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
return $client->execute('/trade/native', $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>';
|
||||
}
|
||||
if($result['respStateInfo']['respCode'] == '000000'){
|
||||
if($result['respStateInfo']['transState'] == 'X'){
|
||||
if(isset($result['respStateInfo']['appendRetCode'])){
|
||||
throw new Exception('['.$result['respStateInfo']['appendRetCode'].']'.$result['respStateInfo']['appendRetMsg']);
|
||||
}else{
|
||||
throw new Exception($result['respStateInfo']['transStatusDesc']);
|
||||
}
|
||||
}
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['respOrderInfo']['outTrace']);
|
||||
return $result['respOrderInfo']['qrCode'];
|
||||
}else{
|
||||
throw new Exception($result['respStateInfo']['respDesc']);
|
||||
}
|
||||
}
|
||||
|
||||
//JSAPI支付接口
|
||||
static private function jsapi($pay_type, $openid, $appid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => TRADE_NO,
|
||||
'transAmount' => intval(round($order['realmoney']*100)),
|
||||
'orderSub' => $ordername,
|
||||
'backUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
],
|
||||
'payInfo' => [
|
||||
'payType' => $pay_type,
|
||||
'transDate' => date('Ymd'),
|
||||
],
|
||||
'settleParamInfo' => [
|
||||
'delaySettleFlag' => '0',
|
||||
'patnerSettleFlag' => '0',
|
||||
'splitSettleFlag' => '0',
|
||||
],
|
||||
'riskData' => [
|
||||
'customerIp' => $clientip,
|
||||
],
|
||||
];
|
||||
if(strpos($pay_type, 'AliPay') === 0){
|
||||
$params['aliBizParam'] = [
|
||||
'buyerId' => $openid,
|
||||
];
|
||||
}elseif(strpos($pay_type, 'WeChat') === 0){
|
||||
$params['wxBizParam'] = [
|
||||
'subAppid' => $appid,
|
||||
'subOpenId' => $openid,
|
||||
];
|
||||
}elseif(strpos($pay_type, 'UnionPay') === 0){
|
||||
$params['qrBizParam'] = [
|
||||
'userAuthCode' => $_SESSION['unionpay_auth_code'],
|
||||
'userId' => $openid,
|
||||
'qrCode' => $siteurl,
|
||||
'paymentValidTime' => 1800,
|
||||
'transType' => '10',
|
||||
'areaInfo' => '1561000',
|
||||
];
|
||||
}
|
||||
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
$result = \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
return $client->execute('/trade/jsapi', $params);
|
||||
});
|
||||
|
||||
if($result['respStateInfo']['respCode'] == '000000'){
|
||||
if($result['respStateInfo']['transState'] == 'X'){
|
||||
if(isset($result['respStateInfo']['appendRetCode'])){
|
||||
throw new Exception('['.$result['respStateInfo']['appendRetCode'].']'.$result['respStateInfo']['appendRetMsg']);
|
||||
}else{
|
||||
throw new Exception($result['respStateInfo']['transStatusDesc']);
|
||||
}
|
||||
}
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['respOrderInfo']['outTrace']);
|
||||
if(strpos($pay_type, 'AliPay') === 0){
|
||||
return $result['aliRespParamInfo']['tradeNo'];
|
||||
}elseif(strpos($pay_type, 'WeChat') === 0){
|
||||
return $result['wxRespParamInfo']['wcPayData'];
|
||||
}elseif(strpos($pay_type, 'UnionPay') === 0){
|
||||
return $result['qrRespParamInfo']['qrRedirectUrl'];
|
||||
}
|
||||
}else{
|
||||
throw new Exception($result['respStateInfo']['respDesc']);
|
||||
}
|
||||
}
|
||||
|
||||
static public function query(){
|
||||
global $siteurl, $channel, $order;
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => date('YmdHis').rand(100000,999999),
|
||||
'oriOrgTrace' => TRADE_NO,
|
||||
'oriTransDate' => substr(TRADE_NO, 0, 8),
|
||||
],
|
||||
'payInfo' => [
|
||||
'transDate' => date('Ymd'),
|
||||
],
|
||||
];
|
||||
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
$result = $client->execute('/trade/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>';
|
||||
}
|
||||
print_r($result);
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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::qrcode('AliPayNative');
|
||||
}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{
|
||||
$alipay_trade_no = self::jsapi('AliPayJsapi', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$alipay_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'=>$alipay_trade_no, 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $siteurl, $device, $mdevice;
|
||||
|
||||
if($channel['appwxa']>0 && $channel['appwxmp']==0){
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
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 wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
$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 wxjspay(){
|
||||
global $siteurl, $channel, $order, $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::jsapi('WeChatJsapi', $openid, $wxinfo['appid']);
|
||||
}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 wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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{
|
||||
$payinfo = self::jsapi('WeChatMiniApp', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($payinfo, true)]));
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode('UnionPayNative');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//云闪付JS支付
|
||||
static public function bankjs(){
|
||||
global $method, $order;
|
||||
try{
|
||||
$code_url = self::jsapi('UnionPayJsapi', $order['sub_openid']);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}
|
||||
|
||||
static public function get_unionpay_userid($channel, $userAuthCode){
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => date('YmdHis').rand(100000,999999),
|
||||
'authCode' => $userAuthCode,
|
||||
'appUpIdentifier' => get_unionpay_ua(),
|
||||
],
|
||||
];
|
||||
|
||||
try{
|
||||
$result = $client->execute('/trade/user/getQrUserId', $params);
|
||||
if($result['respStateInfo']['respCode'] == '000000'){
|
||||
$_SESSION['unionpay_auth_code'] = $userAuthCode;
|
||||
return ['code'=>0,'data'=>$result['respOrderInfo']['userId']];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>$result['respStateInfo']['respDesc']];
|
||||
}
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1,'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'json','data'=>['code'=>'400001','msg'=>'no data']];
|
||||
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
$verify_result = $client->verifySign($arr['reqHeader'], $arr['reqBody'], $arr['reqSign']);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
$data = $arr['reqBody'];
|
||||
if ($data['respStateInfo']['transState'] == '0' || $data['respStateInfo']['transState'] == '1') {
|
||||
$out_trade_no = $data['respOrderInfo']['orgTrace'];
|
||||
$api_trade_no = $data['respOrderInfo']['outTrace'];
|
||||
$money = $data['respOrderInfo']['transAmount'];
|
||||
$buyer = $data['respOrderInfo']['userId'];
|
||||
$bill_trade_no = $data['respOrderInfo']['pcTrace'];
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'json','data'=>['code'=>'000000','msg'=>'Success']];
|
||||
}
|
||||
else {
|
||||
return ['type'=>'json','data'=>['code'=>'100001','msg'=>'sign error']];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
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/EasypayClient.php");
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => $order['refund_no'],
|
||||
'oriOutTrace' => $order['api_trade_no'],
|
||||
'oriTransDate' => substr($order['trade_no'], 0, 8),
|
||||
'refundAmount' => intval(round($order['refundmoney']*100)),
|
||||
],
|
||||
'payInfo' => [
|
||||
'transDate' => date('Ymd'),
|
||||
],
|
||||
];
|
||||
|
||||
try{
|
||||
$result = $client->execute('/trade/refund/apply', $params);
|
||||
if($result['respStateInfo']['respCode'] == '000000'){
|
||||
if($result['respStateInfo']['transState'] == 'X'){
|
||||
if(isset($result['respStateInfo']['appendRetCode'])){
|
||||
return ['code'=>-1, 'msg'=>'['.$result['respStateInfo']['appendRetCode'].']'.$result['respStateInfo']['appendRetMsg']];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>$result['respStateInfo']['transStatusDesc']];
|
||||
}
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['outTrace'], 'refund_fee'=>$result['transAmt']/100];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>$result['respStateInfo']['respDesc']];
|
||||
}
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//退款查询
|
||||
static public function refundquery(){
|
||||
global $channel, $order;
|
||||
|
||||
require_once(PAY_ROOT."inc/EasypayClient.php");
|
||||
$client = new EasypayClient($channel['appid'],$channel['reqtype'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
$refund_no = '2025052715162033617';
|
||||
$params = [
|
||||
'reqInfo' => [
|
||||
'mchtCode' => $channel['reqtype'] == 2 ? $channel['appmchid'] : $channel['appid'],
|
||||
],
|
||||
'reqOrderInfo' => [
|
||||
'orgTrace' => date('YmdHis').rand(100000,999999),
|
||||
'oriOrgTrace' => $refund_no,
|
||||
'oriTransDate' => substr($refund_no, 0, 8),
|
||||
],
|
||||
'payInfo' => [
|
||||
'transDate' => date('Ymd'),
|
||||
],
|
||||
];
|
||||
|
||||
$result = $client->execute('/trade/refund/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>';
|
||||
}
|
||||
print_r($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @see https://apifox.com/apidoc/shared/9758ecc8-2c38-4ec6-914f-b09be6f563bc
|
||||
*/
|
||||
class EasypayClient
|
||||
{
|
||||
private $gateway_url = 'https://phoenix.eycard.cn/yqt';
|
||||
private $reqId;
|
||||
private $reqType;
|
||||
private $easypay_public_key;
|
||||
private $mch_rsa_private_key;
|
||||
|
||||
public $request_body;
|
||||
public $response_body;
|
||||
|
||||
public function __construct($reqId, $reqType, $easypay_public_key, $mch_rsa_private_key, $isTest = false)
|
||||
{
|
||||
$this->reqId = $reqId;
|
||||
$this->reqType = $reqType;
|
||||
$this->easypay_public_key = $easypay_public_key;
|
||||
$this->mch_rsa_private_key = $mch_rsa_private_key;
|
||||
if($isTest){
|
||||
$this->gateway_url = 'https://d-phoenix-gap.easypay.com.cn:24443/yqt';
|
||||
}
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function execute($path, $data){
|
||||
$requrl = $this->gateway_url . $path;
|
||||
$params = [
|
||||
'reqBody' => $data,
|
||||
'reqHeader' => [
|
||||
'transTime' => date('YmdHis'),
|
||||
'reqId' => $this->reqId,
|
||||
'reqType' => $this->reqType,
|
||||
],
|
||||
];
|
||||
$params['reqSign'] = $this->generateSign($params['reqHeader'], $params['reqBody']);
|
||||
|
||||
$body = json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
$this->request_body = $body;
|
||||
$response = get_curl($requrl, $body, 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
$this->response_body = $response;
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['rspHeader']['rspCode']) && $result['rspHeader']['rspCode']=='000000'){
|
||||
if(!$this->verifySign($result['rspHeader'], $result['rspBody'], $result['rspSign'])){
|
||||
throw new Exception('返回数据验签失败');
|
||||
}
|
||||
return $result['rspBody'];
|
||||
}elseif(isset($result['rspHeader']['rspInfo'])){
|
||||
throw new Exception('['.$result['rspHeader']['rspCode'].']'.$result['rspHeader']['rspInfo']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//获取待签名字符串
|
||||
private function getSignContent($header, $body){
|
||||
$sortHeader = $this->sortJSON($header);
|
||||
$sortBody = $this->sortJSON($body);
|
||||
$sortHeader = json_encode($sortHeader, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||
$sortBody = json_encode($sortBody, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||
$signstr = $sortHeader . strtoupper(md5($sortBody));
|
||||
return $signstr;
|
||||
}
|
||||
|
||||
//请求参数签名
|
||||
private function generateSign($header, $body){
|
||||
return $this->rsaPrivateSign($this->getSignContent($header, $body));
|
||||
}
|
||||
|
||||
//验签方法
|
||||
public function verifySign($header, $body, $sign){
|
||||
if(empty($sign)) return false;
|
||||
return $this->rsaPubilcVerify($this->getSignContent($header, $body), $sign);
|
||||
}
|
||||
|
||||
private function isJSONObject($value) {
|
||||
return is_array($value) && array_keys($value) !== range(0, count($value) - 1);
|
||||
}
|
||||
|
||||
private function isJSONArray($value) {
|
||||
return is_array($value) && array_keys($value) === range(0, count($value) - 1);
|
||||
}
|
||||
|
||||
private function sortArray($array) {
|
||||
$sortedArray = [];
|
||||
foreach ($array as $item) {
|
||||
$sortedArray[] = $this->sortJSON($item);
|
||||
}
|
||||
return $sortedArray;
|
||||
}
|
||||
|
||||
private function sortJSON($param) {
|
||||
if ($this->isJSONArray($param)) {
|
||||
return $this->sortArray($param);
|
||||
}
|
||||
|
||||
$keys = array_keys($param);
|
||||
sort($keys, SORT_STRING);
|
||||
|
||||
$paramPair = [];
|
||||
foreach ($keys as $key) {
|
||||
if ($this->isJSONArray($param[$key])) {
|
||||
$paramPair[$key] = $this->sortArray($param[$key]);
|
||||
} elseif ($this->isJSONObject($param[$key])) {
|
||||
$paramPair[$key] = $this->sortJSON($param[$key]);
|
||||
} else {
|
||||
$paramPair[$key] = $param[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $paramPair;
|
||||
}
|
||||
|
||||
//商户私钥签名
|
||||
private function rsaPrivateSign($data){
|
||||
$priKey = str_replace(["\n", "\r"], '', $this->mch_rsa_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 rsaPubilcVerify($data, $signature){
|
||||
$pubKey = str_replace(["\n", "\r"], '', $this->easypay_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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
class epay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'epay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '彩虹易支付', //支付插件显示名称
|
||||
'author' => '彩虹', //支付插件作者
|
||||
'link' => '', //支付插件作者链接
|
||||
'types' => ['alipay','qqpay','wxpay','bank','jdpay','douyinpay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appurl' => [
|
||||
'name' => '接口地址',
|
||||
'type' => 'input',
|
||||
'note' => '必须以http://或https://开头,以/结尾',
|
||||
],
|
||||
'appid' => [
|
||||
'name' => '商户ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '商户密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '是否使用mapi接口',
|
||||
'type' => 'select',
|
||||
'options' => [0=>'否',1=>'是'],
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $conf;
|
||||
|
||||
if($channel['appswitch']==1){
|
||||
return ['type'=>'jump','url'=>'/pay/'.$order['typename'].'/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
$parameter = array(
|
||||
"pid" => trim($epay_config['pid']),
|
||||
"type" => $order['typename'],
|
||||
"notify_url" => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
"return_url" => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
"out_trade_no" => TRADE_NO,
|
||||
"name" => $order['name'],
|
||||
"money" => $order['realmoney']
|
||||
);
|
||||
//建立请求
|
||||
$epay = new EpayCore($epay_config);
|
||||
if(is_https() && substr($epay_config['apiurl'],0,7)=='http://'){
|
||||
$jump_url = $epay->getPayLink($parameter);
|
||||
return ['type'=>'jump','url'=>$jump_url];
|
||||
}else{
|
||||
$html_text = $epay->pagePay($parameter, '正在跳转');
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice;
|
||||
|
||||
if($channel['appswitch']==1){
|
||||
$typename = $order['typename'];
|
||||
return self::$typename();
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/submit/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
|
||||
static private function getDevice(){
|
||||
global $device, $mdevice;
|
||||
if (checkwechat() || $mdevice=='wechat') {
|
||||
$device = 'wechat';
|
||||
}elseif (checkmobbileqq() || $mdevice=='qq') {
|
||||
$device = 'qq';
|
||||
}elseif (checkalipay() || $mdevice=='alipay') {
|
||||
$device = 'alipay';
|
||||
}elseif (checkdouyin() || $mdevice=='douyin') {
|
||||
$device = 'douyin';
|
||||
}elseif (checkmobile() || $device=='mobile') {
|
||||
$device = 'mobile';
|
||||
}else{
|
||||
$device = 'pc';
|
||||
}
|
||||
return $device;
|
||||
}
|
||||
|
||||
//mapi接口下单
|
||||
static private function pay_mapi($type){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
$parameter = array(
|
||||
"pid" => trim($epay_config['pid']),
|
||||
"type" => $type,
|
||||
"device" => self::getDevice(),
|
||||
"clientip" => $clientip,
|
||||
"notify_url" => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
"return_url" => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
"out_trade_no" => TRADE_NO,
|
||||
"name" => $order['name'],
|
||||
"money" => $order['realmoney']
|
||||
);
|
||||
//建立请求
|
||||
$epay = new EpayCore($epay_config);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($epay, $parameter) {
|
||||
$result = $epay->apiPay($parameter);
|
||||
|
||||
if(isset($result['code']) && $result['code']==1){
|
||||
if($result['payurl']){
|
||||
$method = 'jump';
|
||||
$url = $result['payurl'];
|
||||
}elseif($result['qrcode']){
|
||||
$method = 'qrcode';
|
||||
$url = $result['qrcode'];
|
||||
}elseif($result['urlscheme']){
|
||||
$method = 'scheme';
|
||||
$url = $result['urlscheme'];
|
||||
}else{
|
||||
throw new Exception('未返回支付链接');
|
||||
}
|
||||
}elseif(isset($result['msg'])){
|
||||
throw new Exception($result['msg']);
|
||||
}else{
|
||||
throw new Exception('获取支付接口数据失败');
|
||||
}
|
||||
return [$method, $url];
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('alipay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('wxpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'scheme'){
|
||||
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$url];
|
||||
}else{
|
||||
if(checkwechat()){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
} elseif (checkmobile()) {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//QQ扫码支付
|
||||
static public function qqpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('qqpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
if(checkmobbileqq()){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
} elseif(checkmobile() && !isset($_GET['qrcode'])){
|
||||
return ['type'=>'qrcode','page'=>'qqpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'qqpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('bank');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//京东支付
|
||||
static public function jdpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('jdpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'jdpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//抖音支付
|
||||
static public function douyinpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('douyinpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
if (checkmobile()) {
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$epayNotify = new EpayCore($epay_config);
|
||||
$verify_result = $epayNotify->verifyNotify();
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//易支付交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//交易金额
|
||||
$money = $_GET['money'];
|
||||
|
||||
if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)){
|
||||
processNotify($order, $trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$epayNotify = new EpayCore($epay_config);
|
||||
$verify_result = $epayNotify->verifyReturn();
|
||||
if($verify_result) {
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//易支付交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//交易金额
|
||||
$money = $_GET['money'];
|
||||
|
||||
if($_GET['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if ($out_trade_no == TRADE_NO && round($money, 2)==round($order['money'], 2)) {
|
||||
processReturn($order, $trade_no);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'trade_status='.$_GET['trade_status']];
|
||||
}
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'error','msg'=>'验证失败!'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
$epay = new EpayCore($epay_config);
|
||||
$result = $epay->refund($order['refund_no'], $order['api_trade_no'], $order['refundmoney']);
|
||||
|
||||
if($result['code'] == 0){
|
||||
return ['code'=>0];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>$result['msg']?$result['msg']:'返回数据解密失败'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/* *
|
||||
* 彩虹易支付SDK服务类
|
||||
* 说明:
|
||||
* 包含发起支付、查询订单、回调验证等功能
|
||||
*/
|
||||
|
||||
class EpayCore
|
||||
{
|
||||
private $pid;
|
||||
private $key;
|
||||
private $submit_url;
|
||||
private $mapi_url;
|
||||
private $api_url;
|
||||
private $sign_type = 'MD5';
|
||||
|
||||
function __construct($config){
|
||||
$this->pid = $config['pid'];
|
||||
$this->key = $config['key'];
|
||||
$this->submit_url = $config['apiurl'].'submit.php';
|
||||
$this->mapi_url = $config['apiurl'].'mapi.php';
|
||||
$this->api_url = $config['apiurl'].'api.php';
|
||||
}
|
||||
|
||||
// 发起支付(页面跳转)
|
||||
public function pagePay($param_tmp, $button='正在跳转'){
|
||||
$param = $this->buildRequestParam($param_tmp);
|
||||
|
||||
$html = '<form id="dopay" action="'.$this->submit_url.'" method="post">';
|
||||
foreach ($param as $k=>$v) {
|
||||
$html.= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
|
||||
}
|
||||
$html .= '<input type="submit" value="'.$button.'"></form><script>document.getElementById("dopay").submit();</script>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// 发起支付(获取链接)
|
||||
public function getPayLink($param_tmp){
|
||||
$param = $this->buildRequestParam($param_tmp);
|
||||
$url = $this->submit_url.'?'.http_build_query($param);
|
||||
return $url;
|
||||
}
|
||||
|
||||
// 发起支付(API接口)
|
||||
public function apiPay($param_tmp){
|
||||
$param = $this->buildRequestParam($param_tmp);
|
||||
$response = $this->getHttpResponse($this->mapi_url, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
// 异步回调验证
|
||||
public function verifyNotify(){
|
||||
if(empty($_GET)) return false;
|
||||
|
||||
$sign = $this->getSign($_GET);
|
||||
|
||||
if($sign === $_GET['sign']){
|
||||
$signResult = true;
|
||||
}else{
|
||||
$signResult = false;
|
||||
}
|
||||
|
||||
return $signResult;
|
||||
}
|
||||
|
||||
// 同步回调验证
|
||||
public function verifyReturn(){
|
||||
if(empty($_GET)) return false;
|
||||
|
||||
$sign = $this->getSign($_GET);
|
||||
|
||||
if($sign === $_GET['sign']){
|
||||
$signResult = true;
|
||||
}else{
|
||||
$signResult = false;
|
||||
}
|
||||
|
||||
return $signResult;
|
||||
}
|
||||
|
||||
// 查询订单支付状态
|
||||
public function orderStatus($trade_no){
|
||||
$result = $this->queryOrder($trade_no);
|
||||
if($result['status']==1){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询订单
|
||||
public function queryOrder($trade_no){
|
||||
$url = $this->api_url.'?act=order&pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no;
|
||||
$response = $this->getHttpResponse($url);
|
||||
$arr = json_decode($response, true);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
// 订单退款
|
||||
public function refund($refund_no, $trade_no, $money){
|
||||
$url = $this->api_url.'?act=refund';
|
||||
$post = 'pid=' . $this->pid . '&key=' . $this->key . '&refund_no=' . $refund_no . '&trade_no=' . $trade_no . '&money=' . $money;
|
||||
$response = $this->getHttpResponse($url, $post);
|
||||
$arr = json_decode($response, true);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
private function buildRequestParam($param){
|
||||
$mysign = $this->getSign($param);
|
||||
$param['sign'] = $mysign;
|
||||
$param['sign_type'] = $this->sign_type;
|
||||
return $param;
|
||||
}
|
||||
|
||||
// 计算签名
|
||||
private function getSign($param){
|
||||
ksort($param);
|
||||
reset($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $k != "sign_type" && $v!=''){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr,0,-1);
|
||||
$signstr .= $this->key;
|
||||
$sign = md5($signstr);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
// 请求外部资源
|
||||
private function getHttpResponse($url, $post = false, $timeout = 10){
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
|
||||
$httpheader[] = "Connection: close";
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
if($post){
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/* *
|
||||
* 配置文件
|
||||
*/
|
||||
|
||||
//支付API地址
|
||||
$epay_config['apiurl'] = $channel['appurl'];
|
||||
|
||||
//商户ID
|
||||
$epay_config['pid'] = $channel['appid'];
|
||||
|
||||
//商户KEY
|
||||
$epay_config['key'] = $channel['appkey'];
|
||||
@@ -0,0 +1,413 @@
|
||||
<?php
|
||||
|
||||
class epayn_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'epayn', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '彩虹易支付V2', //支付插件显示名称
|
||||
'author' => '彩虹', //支付插件作者
|
||||
'link' => '', //支付插件作者链接
|
||||
'types' => ['alipay','qqpay','wxpay','bank','jdpay','douyinpay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'transtypes' => ['alipay','wxpay','qqpay','bank'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appurl' => [
|
||||
'name' => '接口地址',
|
||||
'type' => 'input',
|
||||
'note' => '必须以http://或https://开头,以/结尾',
|
||||
],
|
||||
'appid' => [
|
||||
'name' => '商户ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '平台公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '是否使用mapi接口',
|
||||
'type' => 'select',
|
||||
'options' => [0=>'否',1=>'是'],
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $conf;
|
||||
|
||||
if($channel['appswitch']==1){
|
||||
return ['type'=>'jump','url'=>'/pay/'.$order['typename'].'/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
$params = [
|
||||
"type" => $order['typename'],
|
||||
"notify_url" => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
"return_url" => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
"out_trade_no" => TRADE_NO,
|
||||
"name" => $order['name'],
|
||||
"money" => $order['realmoney']
|
||||
];
|
||||
|
||||
$epay = new EpayCore($epay_config);
|
||||
if(is_https() && substr($epay_config['apiurl'],0,7)=='http://'){
|
||||
$jump_url = $epay->getPayLink($params);
|
||||
return ['type'=>'jump','url'=>$jump_url];
|
||||
}else{
|
||||
$html_text = $epay->pagePay($params, '正在跳转');
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice;
|
||||
|
||||
if($channel['appswitch']==1){
|
||||
$typename = $order['typename'];
|
||||
return self::$typename();
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/submit/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
|
||||
static private function getDevice(){
|
||||
global $device, $mdevice;
|
||||
if (checkwechat() || $mdevice=='wechat') {
|
||||
$device = 'wechat';
|
||||
}elseif (checkmobbileqq() || $mdevice=='qq') {
|
||||
$device = 'qq';
|
||||
}elseif (checkalipay() || $mdevice=='alipay') {
|
||||
$device = 'alipay';
|
||||
}elseif (checkdouyin() || $mdevice=='douyin') {
|
||||
$device = 'douyin';
|
||||
}elseif (checkmobile() || $device=='mobile') {
|
||||
$device = 'mobile';
|
||||
}else{
|
||||
$device = 'pc';
|
||||
}
|
||||
return $device;
|
||||
}
|
||||
|
||||
//统一下单接口
|
||||
static private function pay_mapi($method, $type, $auth_code = null, $sub_openid = null, $sub_appid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
$params = [
|
||||
"method" => $method,
|
||||
"type" => $type,
|
||||
"device" => self::getDevice(),
|
||||
"clientip" => $clientip,
|
||||
"notify_url" => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
"return_url" => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
"out_trade_no" => TRADE_NO,
|
||||
"name" => $order['name'],
|
||||
"money" => $order['realmoney']
|
||||
];
|
||||
if($auth_code) $params['auth_code'] = $auth_code;
|
||||
if($sub_openid) $params['sub_openid'] = $sub_openid;
|
||||
if($sub_appid) $params['sub_appid'] = $sub_openid;
|
||||
|
||||
$epay = new EpayCore($epay_config);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($epay, $params) {
|
||||
$result = $epay->apiPay($params);
|
||||
return [$result['pay_type'], $result['pay_info']];
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','alipay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'html'){
|
||||
return ['type'=>'html','data'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','wxpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'html'){
|
||||
return ['type'=>'html','data'=>$url];
|
||||
}elseif($method == 'urlscheme'){
|
||||
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$url];
|
||||
}else{
|
||||
if(checkwechat()){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
} elseif (checkmobile()) {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//QQ扫码支付
|
||||
static public function qqpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','qqpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'html'){
|
||||
return ['type'=>'html','data'=>$url];
|
||||
}else{
|
||||
if(checkmobbileqq()){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
} elseif(checkmobile() && !isset($_GET['qrcode'])){
|
||||
return ['type'=>'qrcode','page'=>'qqpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'qqpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','bank');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'html'){
|
||||
return ['type'=>'html','data'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//京东支付
|
||||
static public function jdpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','jdpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}elseif($method == 'html'){
|
||||
return ['type'=>'html','data'=>$url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'jdpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
|
||||
//抖音支付
|
||||
static public function douyinpay(){
|
||||
try{
|
||||
list($method, $url) = self::pay_mapi('web','douyinpay');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($method == 'jump'){
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}else{
|
||||
if (checkmobile()) {
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_wap','url'=>$url];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'douyinpay_qrcode','url'=>$url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$epayNotify = new EpayCore($epay_config);
|
||||
$verify_result = $epayNotify->verify($_GET);
|
||||
|
||||
if($verify_result) {//验证成功
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//易支付交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//交易金额
|
||||
$money = $_GET['money'];
|
||||
|
||||
//支付人账号
|
||||
$buyer = $_GET['buyer'];
|
||||
|
||||
$api_trade_no = $_GET['api_trade_no'];
|
||||
|
||||
if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)){
|
||||
processNotify($order, $trade_no, $buyer, $api_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
//计算得出通知验证结果
|
||||
$epayNotify = new EpayCore($epay_config);
|
||||
$verify_result = $epayNotify->verify($_GET);
|
||||
if($verify_result) {
|
||||
//商户订单号
|
||||
$out_trade_no = $_GET['out_trade_no'];
|
||||
|
||||
//易支付交易号
|
||||
$trade_no = $_GET['trade_no'];
|
||||
|
||||
//交易金额
|
||||
$money = $_GET['money'];
|
||||
|
||||
//支付人账号
|
||||
$buyer = $_GET['buyer'];
|
||||
|
||||
$api_trade_no = $_GET['api_trade_no'];
|
||||
|
||||
if($_GET['trade_status'] == 'TRADE_SUCCESS') {
|
||||
if ($out_trade_no == TRADE_NO && round($money, 2)==round($order['money'], 2)) {
|
||||
processReturn($order, $trade_no, $buyer, $api_trade_no);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'trade_status='.$_GET['trade_status']];
|
||||
}
|
||||
}
|
||||
else {
|
||||
//验证失败
|
||||
return ['type'=>'error','msg'=>'验证失败!'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/epay.config.php");
|
||||
require(PAY_ROOT."inc/EpayCore.class.php");
|
||||
|
||||
$epay = new EpayCore($epay_config);
|
||||
try{
|
||||
$result = $epay->refund($order['refund_no'], $order['api_trade_no'], $order['refundmoney']);
|
||||
return ['code'=>0, 'trade_no'=>$result['refund_no'], 'refund_fee'=>$result['money']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//转账
|
||||
static public function transfer($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require(PLUGIN_ROOT."epayn/inc/epay.config.php");
|
||||
require(PLUGIN_ROOT."epayn/inc/EpayCore.class.php");
|
||||
|
||||
$params = [
|
||||
'type' => $bizParam['type'],
|
||||
'account' => $bizParam['payee_account'],
|
||||
'name' => $bizParam['payee_real_name'],
|
||||
'money' => $bizParam['money'],
|
||||
'remark' => $bizParam['transfer_desc'],
|
||||
'out_biz_no' => $bizParam['out_biz_no'],
|
||||
];
|
||||
$epay = new EpayCore($epay_config);
|
||||
try{
|
||||
$result = $epay->execute('api/transfer/submit', $params);
|
||||
if(isset($result['jumpurl'])){
|
||||
return ['code'=>0, 'status'=>$result['status'], 'orderid'=>$result['out_biz_no'], 'paydate'=>$result['paydate'], 'wxpackage'=>$result['jumpurl']];
|
||||
}else{
|
||||
return ['code'=>0, 'status'=>$result['status'], 'orderid'=>$result['out_biz_no'], 'paydate'=>$result['paydate']];
|
||||
}
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//转账查询
|
||||
static public function transfer_query($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require(PLUGIN_ROOT."epayn/inc/epay.config.php");
|
||||
require(PLUGIN_ROOT."epayn/inc/EpayCore.class.php");
|
||||
|
||||
$params = [
|
||||
'out_biz_no' => $bizParam['out_biz_no'],
|
||||
];
|
||||
$epay = new EpayCore($epay_config);
|
||||
try{
|
||||
$result = $epay->execute('api/transfer/query', $params);
|
||||
return ['code'=>0, 'status'=>$result['status'], 'amount'=>$result['amount'], 'paydate'=>$result['paydate'], 'errmsg'=>$result['errmsg']];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//余额查询
|
||||
static public function balance_query($channel, $bizParam){
|
||||
if(empty($channel))exit();
|
||||
|
||||
require(PLUGIN_ROOT."epayn/inc/epay.config.php");
|
||||
require(PLUGIN_ROOT."epayn/inc/EpayCore.class.php");
|
||||
|
||||
$params = [
|
||||
'out_biz_no' => $bizParam['out_biz_no'],
|
||||
];
|
||||
$epay = new EpayCore($epay_config);
|
||||
try{
|
||||
$result = $epay->execute('api/transfer/balance', $params);
|
||||
return ['code'=>0, 'amount'=>$result['available_money']];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/* *
|
||||
* 彩虹易支付SDK服务类
|
||||
* 说明:
|
||||
* 包含发起支付、查询订单、回调验证等功能
|
||||
*/
|
||||
|
||||
class EpayCore
|
||||
{
|
||||
private $apiurl;
|
||||
private $pid;
|
||||
private $platform_public_key;
|
||||
private $merchant_private_key;
|
||||
|
||||
private $sign_type = 'RSA';
|
||||
|
||||
function __construct($config){
|
||||
$this->apiurl = $config['apiurl'];
|
||||
$this->pid = $config['pid'];
|
||||
$this->platform_public_key = $config['platform_public_key'];
|
||||
$this->merchant_private_key = $config['merchant_private_key'];
|
||||
}
|
||||
|
||||
// 发起支付(页面跳转)
|
||||
public function pagePay($param_tmp, $button='正在跳转'){
|
||||
$requrl = $this->apiurl.'api/pay/submit';
|
||||
$param = $this->buildRequestParam($param_tmp);
|
||||
|
||||
$html = '<form id="dopay" action="'.$requrl.'" method="post">';
|
||||
foreach ($param as $k=>$v) {
|
||||
$html.= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
|
||||
}
|
||||
$html .= '<input type="submit" value="'.$button.'"></form><script>document.getElementById("dopay").submit();</script>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// 发起支付(获取链接)
|
||||
public function getPayLink($param_tmp){
|
||||
$requrl = $this->apiurl.'api/pay/submit';
|
||||
$param = $this->buildRequestParam($param_tmp);
|
||||
$url = $requrl.'?'.http_build_query($param);
|
||||
return $url;
|
||||
}
|
||||
|
||||
// 发起支付(API接口)
|
||||
public function apiPay($params){
|
||||
return $this->execute('api/pay/create', $params);
|
||||
}
|
||||
|
||||
// 发起API请求
|
||||
public function execute($path, $params){
|
||||
$path = ltrim($path, '/');
|
||||
$requrl = $this->apiurl.$path;
|
||||
$param = $this->buildRequestParam($params);
|
||||
$isMultipart = false;
|
||||
foreach ($param as $v) {
|
||||
if($v instanceof \CURLFile){
|
||||
$isMultipart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$response = $this->getHttpResponse($requrl, $isMultipart ? $param : http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
if($arr && $arr['code'] == 0){
|
||||
if(!$this->verify($arr)){
|
||||
throw new \Exception('返回数据验签失败');
|
||||
}
|
||||
return $arr;
|
||||
}else{
|
||||
throw new \Exception($arr ? $arr['msg'] : '请求失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 回调验证
|
||||
public function verify($arr){
|
||||
if(empty($arr) || empty($arr['sign'])) return false;
|
||||
|
||||
if(empty($arr['timestamp']) || abs(time() - $arr['timestamp']) > 300) return false;
|
||||
|
||||
$sign = $arr['sign'];
|
||||
|
||||
return $this->rsaPublicVerify($this->getSignContent($arr), $sign);
|
||||
}
|
||||
|
||||
// 查询订单支付状态
|
||||
public function orderStatus($trade_no){
|
||||
$result = $this->queryOrder($trade_no);
|
||||
if($result && $result['status']==1){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询订单
|
||||
public function queryOrder($trade_no){
|
||||
$params = [
|
||||
'trade_no' => $trade_no,
|
||||
];
|
||||
return $this->execute('api/pay/query', $params);
|
||||
}
|
||||
|
||||
// 订单退款
|
||||
public function refund($out_refund_no, $trade_no, $money){
|
||||
$params = [
|
||||
'trade_no' => $trade_no,
|
||||
'money' => $money,
|
||||
'out_refund_no' => $out_refund_no,
|
||||
];
|
||||
return $this->execute('api/pay/refund', $params);
|
||||
}
|
||||
|
||||
// 订单退款查询
|
||||
public function refundquery($out_refund_no){
|
||||
$params = [
|
||||
'out_refund_no' => $out_refund_no,
|
||||
];
|
||||
return $this->execute('api/pay/refundquery', $params);
|
||||
}
|
||||
|
||||
private function buildRequestParam($params){
|
||||
$params['pid'] = $this->pid;
|
||||
$params['timestamp'] = time().'';
|
||||
$mysign = $this->getSign($params);
|
||||
$params['sign'] = $mysign;
|
||||
$params['sign_type'] = $this->sign_type;
|
||||
return $params;
|
||||
}
|
||||
|
||||
// 生成签名
|
||||
private function getSign($params){
|
||||
return $this->rsaPrivateSign($this->getSignContent($params));
|
||||
}
|
||||
|
||||
// 获取待签名字符串
|
||||
private function getSignContent($params){
|
||||
ksort($params);
|
||||
$signstr = '';
|
||||
foreach ($params as $k => $v) {
|
||||
if($v instanceof \CURLFile || is_array($v) || $this->isEmpty($v) || $k == 'sign' || $k == 'sign_type') continue;
|
||||
$signstr .= '&' . $k . '=' . $v;
|
||||
}
|
||||
$signstr = substr($signstr, 1);
|
||||
return $signstr;
|
||||
}
|
||||
|
||||
private function isEmpty($value)
|
||||
{
|
||||
return $value === null || trim($value) === '';
|
||||
}
|
||||
|
||||
// 商户私钥签名
|
||||
private function rsaPrivateSign($data){
|
||||
$key = "-----BEGIN PRIVATE KEY-----\n" .
|
||||
wordwrap($this->merchant_private_key, 64, "\n", true) .
|
||||
"\n-----END PRIVATE KEY-----";
|
||||
$privatekey = openssl_get_privatekey($key);
|
||||
if(!$privatekey){
|
||||
throw new \Exception('签名失败,商户私钥错误');
|
||||
}
|
||||
openssl_sign($data, $sign, $privatekey, OPENSSL_ALGO_SHA256);
|
||||
return base64_encode($sign);
|
||||
}
|
||||
|
||||
// 平台公钥验签
|
||||
private function rsaPublicVerify($data, $sign){
|
||||
$key = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($this->platform_public_key, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$publickey = openssl_get_publickey($key);
|
||||
if (!$publickey) {
|
||||
throw new \Exception("验签失败,平台公钥错误");
|
||||
}
|
||||
$result = openssl_verify($data, base64_decode($sign), $publickey, OPENSSL_ALGO_SHA256);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
// 请求外部资源
|
||||
private function getHttpResponse($url, $post = false, $timeout = 10){
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
|
||||
$httpheader[] = "Connection: close";
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
if($post){
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/* *
|
||||
* 配置文件
|
||||
*/
|
||||
|
||||
$epay_config = [
|
||||
//支付接口地址
|
||||
'apiurl' => $channel['appurl'],
|
||||
|
||||
//商户ID
|
||||
'pid' => $channel['appid'],
|
||||
|
||||
//平台公钥
|
||||
'platform_public_key' => $channel['appkey'],
|
||||
|
||||
//商户私钥
|
||||
'merchant_private_key' => $channel['appsecret'],
|
||||
];
|
||||
@@ -0,0 +1,427 @@
|
||||
<?php
|
||||
|
||||
class fubei_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'fubei', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '付呗聚合支付', //支付插件显示名称
|
||||
'author' => '付呗', //支付插件作者
|
||||
'link' => 'https://www.51fubei.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '开放平台ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '接口密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '门店ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'mchid' => [
|
||||
'name' => '商户ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '生活号支付',
|
||||
'2' => 'H5支付',
|
||||
],
|
||||
'note' => '如果是微信支付,需要<a href="./plugin_page.php?channel=[channel]&func=wxconfig" target="_blank">配置绑定AppId和支付目录</a>', //支付密钥填写说明
|
||||
'bindwxmp' => true, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
if(checkmobile() && in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/alipaywap/'.TRADE_NO.'/'];
|
||||
}elseif(checkalipay() && in_array('1',$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()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}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($method == 'applet'){
|
||||
return self::wxplugin();
|
||||
}
|
||||
elseif($order['typename']=='alipay'){
|
||||
if($device=='mobile' && in_array('2',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/alipaywap/'.TRADE_NO.'/'];
|
||||
}elseif($mdevice=='alipay' && in_array('1',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/alipayjs/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return self::alipay();
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($mdevice=='wechat'){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//下单通用
|
||||
static private function addOrder($pay_type, $user_id, $sub_appid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT.'inc/FubeiClient.class.php');
|
||||
|
||||
$bizContent = [
|
||||
'merchant_id' => $channel['mchid'],
|
||||
'merchant_order_sn' => TRADE_NO,
|
||||
'pay_type' => $pay_type,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'store_id' => $channel['appmchid'],
|
||||
'user_id' => $user_id,
|
||||
'body' => $ordername,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
];
|
||||
if($sub_appid) $bizContent['sub_appid'] = $sub_appid;
|
||||
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $bizContent) {
|
||||
$retData = $client->execute('fbpay.order.create', $bizContent);
|
||||
return $retData;
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝H5下单
|
||||
//https://www.yuque.com/51fubei/hq1pfy/zzmg63
|
||||
static private function alipayH5(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT.'inc/FubeiClient.class.php');
|
||||
|
||||
$bizContent = [
|
||||
'merchant_id' => $channel['mchid'],
|
||||
'merchant_order_sn' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'store_id' => $channel['appmchid'],
|
||||
'body' => $ordername,
|
||||
'user_ip' => $clientip,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $bizContent) {
|
||||
$retData = $client->execute('fbpay.order.wap.create', $bizContent);
|
||||
return $retData;
|
||||
});
|
||||
}
|
||||
|
||||
//获取微信网页授权url
|
||||
static private function getWechatAuthUrl(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
require_once(PAY_ROOT.'inc/FubeiClient.class.php');
|
||||
|
||||
$url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
$bizContent = [
|
||||
'url' => $url,
|
||||
'store_id' => $channel['appmchid'],
|
||||
];
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
$retData = $client->execute('openapi.agent.merchant.wechat.payment.auth', $bizContent);
|
||||
return $retData['authUrl'];
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/alipaywap/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
if(checkalipay() || $mdevice=='alipay'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝JS支付
|
||||
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;
|
||||
|
||||
try{
|
||||
$retData = self::addOrder('alipay', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$retData['prepay_id']];
|
||||
}
|
||||
|
||||
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'=>$retData['prepay_id'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//支付宝H5支付
|
||||
static public function alipaywap(){
|
||||
try{
|
||||
$retData = self::alipayH5();
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
$html = $retData['html'];
|
||||
if(substr($html, 0, 4) == 'http'){
|
||||
return ['type'=>'jump','url'=>$html];
|
||||
}
|
||||
return ['type'=>'html','data'=>$html];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $siteurl, $device;
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
|
||||
if (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;
|
||||
|
||||
if($channel['appwxmp'] > 0){
|
||||
if(!empty($order['sub_openid'])){
|
||||
if(!empty($order['sub_appid'])){
|
||||
$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'=>'支付通道绑定的微信公众号不存在'];
|
||||
}
|
||||
$appid = $wxinfo['appid'];
|
||||
}
|
||||
$openid = $order['sub_openid'];
|
||||
}else{
|
||||
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
|
||||
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
|
||||
$appid = $wxinfo['appid'];
|
||||
|
||||
try{
|
||||
$openid = wechat_oauth($wxinfo);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!isset($_GET['open_id'])){
|
||||
try{
|
||||
$auth_url = self::getWechatAuthUrl();
|
||||
return ['type'=>'jump','url'=>$auth_url];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'获取微信网页授权url失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
$openid = $_GET['open_id'];
|
||||
$pay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$appid = $pay_config['wxappid'];
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($openid, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
try{
|
||||
$retData = self::addOrder('wxpay', $openid, $appid);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>json_encode($retData['sign_package'])];
|
||||
}
|
||||
|
||||
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($retData['sign_package']), 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信小程序插件支付
|
||||
static public function wxplugin(){
|
||||
$pay_config = require(PAY_ROOT.'inc/config.php');
|
||||
$appId = $pay_config['wxplugin_appid'];
|
||||
try{
|
||||
$result = self::addOrder('wxpay', null, $appId);
|
||||
$payinfo = ['appId'=>$appId, 'orderSn'=>$result['order_sn']];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'wxplugin','data'=>$payinfo];
|
||||
}
|
||||
|
||||
//微信参数配置
|
||||
static public function wxconfig(){
|
||||
global $siteurl,$channel,$islogin;
|
||||
if(!$islogin) exit('Access Denied');
|
||||
|
||||
require_once(PAY_ROOT.'inc/FubeiClient.class.php');
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
if(isset($_POST['sub_appid']) && isset($_POST['jsapi_path'])){
|
||||
$bizContent=[
|
||||
'store_id' => $channel['appmchid'],
|
||||
'sub_appid' => $_POST['sub_appid'],
|
||||
'jsapi_path' => $_POST['jsapi_path']
|
||||
];
|
||||
try{
|
||||
$retData = $client->execute('fbpay.order.wxconfig', $bizContent);
|
||||
$msg = '';
|
||||
if(!empty($retData['sub_appid_msg'])) $msg .= $retData['sub_appid_msg'].'<br/>';
|
||||
if(!empty($retData['jsapi_msg'])) $msg .= $retData['jsapi_msg'];
|
||||
if(defined('EPAY_PLUGIN_JSON')) echojson(['code'=>0,'msg'=>strip_tags($msg) ?: '微信参数配置成功!']);
|
||||
showmsg($msg,1);
|
||||
}catch(Exception $e){
|
||||
if(defined('EPAY_PLUGIN_JSON')) echojsonmsg('微信参数配置失败!'.$e->getMessage());
|
||||
showmsg('微信参数配置失败!'.$e->getMessage(),4);
|
||||
}
|
||||
}
|
||||
|
||||
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
|
||||
|
||||
$bizContent=[
|
||||
'store_id' => $channel['appmchid']
|
||||
];
|
||||
try{
|
||||
$retData = $client->execute('fbpay.order.wxconfig.query', $bizContent);
|
||||
$appid_list = json_decode($retData['appid_list'], true);
|
||||
$jsapi_path_list = json_decode($retData['jsapi_path_list'], true);
|
||||
$data = ['appid_config_list' => $appid_list['appid_config_list'], 'jsapi_path_list' => $jsapi_path_list['jsapi_path_list'], 'appid'=>$wxinfo ? $wxinfo['appid'] : ''];
|
||||
include PAY_ROOT.'wxconf.page.php';
|
||||
}catch(Exception $e){
|
||||
showmsg('微信参数配置查询失败!'.$e->getMessage(),4);
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
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;
|
||||
|
||||
require_once(PAY_ROOT.'inc/FubeiClient.class.php');
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
$verify_result = $client->verify($_POST);
|
||||
|
||||
if($verify_result){
|
||||
$data = json_decode($_POST["data"], true);
|
||||
if($data['order_status'] == 'SUCCESS'){
|
||||
$out_trade_no = $data['merchant_order_sn'];
|
||||
$api_trade_no = $data['order_sn'];
|
||||
$money = $data['total_amount'];
|
||||
$buyer = $data['user_id'];
|
||||
$bill_trade_no = $data['channel_order_sn'];
|
||||
$bill_mch_trade_no = $data['ins_order_sn'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'status='.$data['order_status']];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'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/FubeiClient.class.php');
|
||||
$client = new FubeiClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
$bizContent=[
|
||||
'order_sn' => $order['api_trade_no'],
|
||||
'merchant_refund_sn' => $order['refund_no'],
|
||||
'refund_amount' => $order['refundmoney'],
|
||||
];
|
||||
try{
|
||||
$retData = $client->execute('fbpay.order.refund', $bizContent);
|
||||
$result = ['code'=>0, 'trade_no'=>$retData['merchant_order_sn'], 'refund_fee'=>$retData['refund_amount']];
|
||||
}catch(Exception $e){
|
||||
$result = ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://www.yuque.com/51fubei/openapi
|
||||
*/
|
||||
class FubeiClient
|
||||
{
|
||||
//支付接口地址
|
||||
private $gateway_url = 'https://shq-api.51fubei.com/gateway/agent';
|
||||
|
||||
private $version = '1.0';
|
||||
|
||||
private $sign_method = 'md5';
|
||||
|
||||
private $format = 'json';
|
||||
|
||||
//开放平台ID
|
||||
private $app_id;
|
||||
|
||||
//接口密钥
|
||||
private $app_secret;
|
||||
|
||||
|
||||
public function __construct($app_id, $app_secret){
|
||||
$this->app_id = $app_id;
|
||||
$this->app_secret = $app_secret;
|
||||
}
|
||||
|
||||
//发起请求
|
||||
public function execute($method, $bizContent)
|
||||
{
|
||||
$commonData = [
|
||||
'app_id' => $this->app_id,
|
||||
'method' => $method,
|
||||
'format' => $this->format,
|
||||
'sign_method' => $this->sign_method,
|
||||
'nonce' => random(12),
|
||||
'version' => $this->version,
|
||||
'biz_content' => json_encode($bizContent, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
$commonData['sign'] = $this->make_sign($commonData);
|
||||
|
||||
$data = get_curl($this->gateway_url, json_encode($commonData), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['result_code']) && $result['result_code']==200){
|
||||
return $result['data'];
|
||||
}else{
|
||||
throw new Exception($result['result_message']?$result['result_message']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function verify($param){
|
||||
if(!isset($param['sign'])) return false;
|
||||
$sign = $this->make_sign($param);
|
||||
return $sign === $param['sign'];
|
||||
}
|
||||
|
||||
private function make_sign($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $v!=''){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr, 0, -1);
|
||||
$signstr .= $this->app_secret;
|
||||
$sign = strtoupper(md5($signstr));
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
// fubei支付插件配置
|
||||
// WeChat OAuth AppID(付呗平台公众号)
|
||||
// Mini-Program AppID(付呗微信小程序)
|
||||
return [
|
||||
'wxappid' => 'wxab36abed3127b34a',
|
||||
'wxplugin_appid' => 'wx21efb7c54d4729d6',
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
if(!defined('IN_CRONLITE'))exit();?>
|
||||
<style>tbody tr>td:nth-child(1){width:180px}</style>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading"><h3 class="panel-title">微信参数配置查询<span class="pull-right"><a class="btn btn-default btn-xs" href="javascript:window.location.reload()">刷新</a></span></h3></div>
|
||||
<div class="panel-body">
|
||||
<p><b>已关联的公众号AppID:</b></p>
|
||||
<p><?php foreach($data['appid_config_list'] as $row){ echo $row['sub_appid'].'<br/>';}?></p>
|
||||
<p><b>JSAPI支付授权目录:</b></p>
|
||||
<p><?php foreach($data['jsapi_path_list'] as $row){ echo $row.'<br/>';}?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-success">
|
||||
<div class="panel-heading"><h3 class="panel-title">微信参数配置</span></h3></div>
|
||||
<div class="panel-body">
|
||||
<form action="./plugin_page.php?channel=<?php echo $channel['id']?>&func=wxconfig" method="POST" class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">公众号AppID</label>
|
||||
<div class="col-sm-7"><input type="text" name="sub_appid" value="<?php echo $data['appid']?>" placeholder="只能填写已认证的服务号,且必须与当前主体或渠道商主体一致" class="form-control"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">JSAPI支付授权目录</label>
|
||||
<div class="col-sm-7"><input type="text" name="jsapi_path" value="<?php echo $siteurl?>" placeholder="必须以http://或https://开头,以/结尾" class="form-control"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-7"><input type="submit" name="submit" value="提交" class="btn btn-primary form-control"><br>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* http://fundwx.fuiou.com/doc/#/aggregatePay/
|
||||
*/
|
||||
class fuiou_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'fuiou', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'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' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '商户密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appurl' => [
|
||||
'name' => '订单号前缀',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
],
|
||||
'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() && !checkwechat() && 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, $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' && $mdevice!='wechat' && 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){
|
||||
global $siteurl, $channel, $order, $ordername, $clientip, $conf;
|
||||
|
||||
$apiurl = 'https://aipay-cloud.fuioupay.com/aggregatePay/preCreate';
|
||||
$param = [
|
||||
'version' => '1.0',
|
||||
'mchnt_cd' => $channel['appid'],
|
||||
'random_str' => random(32),
|
||||
'order_type' => $pay_type,
|
||||
'order_amt' => strval($order['realmoney']*100),
|
||||
'mchnt_order_no' => $channel['appurl'].TRADE_NO,
|
||||
'txn_begin_ts' => date('YmdHis'),
|
||||
'goods_des' => $ordername,
|
||||
'term_id' => rand(10000000,99999999).'',
|
||||
'term_ip' => $clientip,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
];
|
||||
|
||||
$param_ord = ['mchnt_cd', 'order_type', 'order_amt', 'mchnt_order_no', 'txn_begin_ts', 'goods_des', 'term_id', 'term_ip', 'notify_url', 'random_str', 'version'];
|
||||
$signStr = '';
|
||||
foreach($param_ord as $key){
|
||||
$signStr .= $param[$key] . '|';
|
||||
}
|
||||
$signStr .= $channel['appkey'];
|
||||
$param['sign'] = md5($signStr);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($apiurl, $param) {
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['result_code']) && $result['result_code']=='000000'){
|
||||
$code_url = $result['qr_code'];
|
||||
}else{
|
||||
throw new Exception($result['result_msg']?$result['result_msg']:'返回数据解析失败');
|
||||
}
|
||||
return $code_url;
|
||||
});
|
||||
}
|
||||
|
||||
//公众号小程序下单
|
||||
static private function jspay($trade_type, $sub_openid, $sub_appid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $clientip, $conf;
|
||||
|
||||
$apiurl = 'https://aipay-cloud.fuioupay.com/aggregatePay/wxPreCreate';
|
||||
$param = [
|
||||
'version' => '1.0',
|
||||
'mchnt_cd' => $channel['appid'],
|
||||
'random_str' => random(32),
|
||||
'order_amt' => strval($order['realmoney']*100),
|
||||
'mchnt_order_no' => $channel['appurl'].TRADE_NO,
|
||||
'txn_begin_ts' => date('YmdHis'),
|
||||
'goods_des' => $ordername,
|
||||
'term_id' => rand(10000000,99999999).'',
|
||||
'term_ip' => $clientip,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'trade_type' => $trade_type,
|
||||
'sub_openid' => $sub_openid,
|
||||
];
|
||||
if($sub_appid){
|
||||
$param['sub_appid'] = $sub_appid;
|
||||
}
|
||||
|
||||
$param_ord = ['mchnt_cd', 'trade_type', 'order_amt', 'mchnt_order_no', 'txn_begin_ts', 'goods_des', 'term_id', 'term_ip', 'notify_url', 'random_str', 'version'];
|
||||
$signStr = '';
|
||||
foreach($param_ord as $key){
|
||||
$signStr .= $param[$key] . '|';
|
||||
}
|
||||
$signStr .= $channel['appkey'];
|
||||
$param['sign'] = md5($signStr);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($apiurl, $param) {
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['result_code']) && $result['result_code']=='000000'){
|
||||
$code_url = $result;
|
||||
}else{
|
||||
throw new Exception($result['result_msg']?$result['result_msg']:'返回数据解析失败');
|
||||
}
|
||||
return $code_url;
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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{
|
||||
$result = self::jspay('FWC', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['reserved_transaction_id']];
|
||||
}
|
||||
|
||||
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'=>$result['reserved_transaction_id'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $siteurl, $device, $mdevice;
|
||||
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
if($channel['appwxmp']>0){
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::addOrder('WECHAT');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
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 wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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::jspay('LETPAY', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
$payinfo = ['appId'=>$result['sdk_appid'], 'timeStamp'=>$result['sdk_timestamp'], 'nonceStr'=>$result['sdk_noncestr'], 'package'=>$result['sdk_package'], 'signType'=>$result['sdk_signtype'], 'paySign'=>$result['sdk_paysign']];
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>$payinfo]));
|
||||
}
|
||||
|
||||
//微信公众号支付
|
||||
static public function wxjspay(){
|
||||
global $siteurl, $channel, $order, $method, $conf, $clientip;
|
||||
|
||||
//①、获取用户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::jspay($order['is_applet'] == 1 ? 'LETPAY' : 'JSAPI', $openid, $wxinfo['appid']);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
$payinfo = ['appId'=>$result['sdk_appid'], 'timeStamp'=>$result['sdk_timestamp'], 'nonceStr'=>$result['sdk_noncestr'], 'package'=>$result['sdk_package'], 'signType'=>$result['sdk_signtype'], 'paySign'=>$result['sdk_paysign']];
|
||||
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>json_encode($payinfo)];
|
||||
}
|
||||
|
||||
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($payinfo), 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
$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(){
|
||||
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');
|
||||
//file_put_contents('logs.txt', $json);
|
||||
$arr = json_decode($json,true);
|
||||
|
||||
$param_ord = ['mchnt_cd', 'mchnt_order_no', 'settle_order_amt', 'order_amt', 'txn_fin_ts', 'reserved_fy_settle_dt', 'random_str'];
|
||||
$signStr = '';
|
||||
foreach($param_ord as $key){
|
||||
$signStr .= $arr[$key] . '|';
|
||||
}
|
||||
$signStr .= $channel['appkey'];
|
||||
$sign = md5($signStr);
|
||||
|
||||
if ($sign === $arr['sign']) {
|
||||
$out_trade_no = substr($arr['mchnt_order_no'],strlen($channel['appurl']));
|
||||
$trade_no = $arr['transaction_id'];
|
||||
$money = $arr['order_amt'];
|
||||
$buyer = $arr['reserved_buyer_logon_id'];
|
||||
$bill_mch_trade_no = $arr['reserved_channel_order_id'];
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $trade_no, $buyer, null, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'1'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'0'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$apiurl = 'https://aipay-cloud.fuioupay.com/aggregatePay/commonRefund';
|
||||
|
||||
if($order['type'] == 1) $pay_type = 'ALIPAY';
|
||||
else if($order['type'] == 2) $pay_type = 'WECHAT';
|
||||
else if($order['type'] == 4) $pay_type = 'UNIONPAY';
|
||||
|
||||
$param = [
|
||||
'version' => '1.0',
|
||||
'mchnt_cd' => $channel['appid'],
|
||||
'term_id' => rand(10000000,99999999).'',
|
||||
'random_str' => random(32),
|
||||
'mchnt_order_no' => $channel['appurl'].$order['trade_no'],
|
||||
'refund_order_no' => $channel['appurl'].$order['refund_no'],
|
||||
'order_type' => $pay_type,
|
||||
'total_amt' => strval($order['realmoney']*100),
|
||||
'refund_amt' => strval($order['refundmoney']*100),
|
||||
];
|
||||
|
||||
$param_ord = ['mchnt_cd', 'order_type', 'mchnt_order_no', 'refund_order_no', 'total_amt', 'refund_amt', 'term_id', 'random_str', 'version'];
|
||||
$signStr = '';
|
||||
foreach($param_ord as $key){
|
||||
$signStr .= $param[$key] . '|';
|
||||
}
|
||||
$signStr .= $channel['appkey'];
|
||||
$param['sign'] = md5($signStr);
|
||||
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if($result["result_code"]=='000000'){
|
||||
$result = ['code'=>0, 'trade_no'=>$result['mchnt_order_no'], 'refund_fee'=>$result['reserved_refund_amt']];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["result_msg"]];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,582 @@
|
||||
<?php
|
||||
|
||||
class fuiou2_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'fuiou2', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'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' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '富友公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appurl' => [
|
||||
'name' => '订单号前缀',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'entrykey' => [
|
||||
'name' => '代理进件密钥',
|
||||
'type' => 'input',
|
||||
'note' => '不使用进件或投诉接口可不填写',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '环境选择',
|
||||
'type' => 'select',
|
||||
'options' => [0=>'生产环境',1=>'测试环境'],
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
],
|
||||
'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() && !checkwechat() && 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, $device, $mdevice, $method;
|
||||
|
||||
if($method=='jsapi'){
|
||||
if($order['typename']=='alipay'){
|
||||
return self::alipayjs();
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
return self::wxjspay();
|
||||
}
|
||||
}elseif($method=='scan'){
|
||||
return self::scanpay();
|
||||
}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' && $mdevice!='wechat' && 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){
|
||||
global $siteurl, $channel, $order, $ordername, $clientip, $conf;
|
||||
|
||||
require(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$param = [
|
||||
'order_type' => $pay_type,
|
||||
'order_amt' => strval($order['realmoney']*100),
|
||||
'mchnt_order_no' => $channel['appurl'].TRADE_NO,
|
||||
'txn_begin_ts' => date('YmdHis'),
|
||||
'goods_des' => $ordername,
|
||||
'term_ip' => $clientip,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'goods_detail' => '',
|
||||
'addn_inf' => '',
|
||||
'curr_type' => 'CNY',
|
||||
'goods_tag' => '',
|
||||
];
|
||||
|
||||
$client = new PayService($channel['appid'],$channel['appmchid'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $param) {
|
||||
$result = $client->submit('/preCreate', $param);
|
||||
return $result['qr_code'];
|
||||
});
|
||||
}
|
||||
|
||||
//JSAPI支付
|
||||
static private function jspay($trade_type, $sub_appid, $sub_openid){
|
||||
global $siteurl, $channel, $order, $ordername, $clientip, $conf;
|
||||
|
||||
require(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$param = [
|
||||
'trade_type' => $trade_type,
|
||||
'order_amt' => strval($order['realmoney']*100),
|
||||
'mchnt_order_no' => $channel['appurl'].TRADE_NO,
|
||||
'txn_begin_ts' => date('YmdHis'),
|
||||
'goods_des' => $ordername,
|
||||
'term_ip' => $clientip,
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'limit_pay' => '',
|
||||
'goods_detail' => '',
|
||||
'addn_inf' => '',
|
||||
'curr_type' => 'CNY',
|
||||
'goods_tag' => '',
|
||||
'product_id' => '',
|
||||
'openid' => '',
|
||||
'sub_openid' => $sub_openid,
|
||||
'sub_appid' => $sub_appid,
|
||||
];
|
||||
|
||||
$client = new PayService($channel['appid'],$channel['appmchid'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $param) {
|
||||
$result = $client->submit('/wxPreCreate', $param);
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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{
|
||||
$result = self::jspay('FWC', '', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['reserved_transaction_id']];
|
||||
}
|
||||
|
||||
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'=>$result['reserved_transaction_id'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $siteurl, $device, $mdevice;
|
||||
if(in_array('2',$channel['apptype']) && !in_array('1',$channel['apptype'])){
|
||||
if($channel['appwxmp']>0){
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::addOrder('WECHAT');
|
||||
}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 wxminipay(){
|
||||
global $siteurl, $channel;
|
||||
|
||||
$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::jspay('LETPAY', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
$payinfo = ['appId'=>$result['sdk_appid'], 'timeStamp'=>$result['sdk_timestamp'], 'nonceStr'=>$result['sdk_noncestr'], 'package'=>$result['sdk_package'], 'signType'=>$result['sdk_signtype'], 'paySign'=>$result['sdk_paysign']];
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>$payinfo]));
|
||||
}
|
||||
|
||||
//微信公众号支付
|
||||
static public function wxjspay(){
|
||||
global $siteurl, $channel, $order, $method, $conf, $clientip;
|
||||
|
||||
//①、获取用户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::jspay($order['is_applet'] == 1 ? 'LETPAY' : 'JSAPI', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
$payinfo = ['appId'=>$result['sdk_appid'], 'timeStamp'=>$result['sdk_timestamp'], 'nonceStr'=>$result['sdk_noncestr'], 'package'=>$result['sdk_package'], 'signType'=>$result['sdk_signtype'], 'paySign'=>$result['sdk_paysign']];
|
||||
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>json_encode($payinfo)];
|
||||
}
|
||||
|
||||
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($payinfo), 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
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];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::addOrder('UNIONPAY');
|
||||
}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 scanpay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
$order_type = 'ALIPAY';
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
$order_type = 'WECHAT';
|
||||
}elseif($order['typename']=='bank'){
|
||||
$order_type = 'UNIONPAY';
|
||||
}
|
||||
|
||||
require(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$params = [
|
||||
'order_type' => $order_type,
|
||||
'order_amt' => strval($order['realmoney']*100),
|
||||
'mchnt_order_no' => $channel['appurl'].TRADE_NO,
|
||||
'txn_begin_ts' => date('YmdHis'),
|
||||
'goods_des' => $ordername,
|
||||
'goods_detail' => '',
|
||||
'term_ip' => $clientip,
|
||||
'auth_code' => $order['auth_code'],
|
||||
'sence' => '1',
|
||||
'addn_inf' => '',
|
||||
'curr_type' => 'CNY',
|
||||
'goods_tag' => '',
|
||||
];
|
||||
|
||||
$client = new PayService($channel['appid'],$channel['appmchid'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
try{
|
||||
$result = $client->submit('/micropay', $params);
|
||||
if($result['result_code'] == '000000'){
|
||||
processNotify($order, $result['reserved_mchnt_order_no'], $result['buyer_id'], $result['transaction_id']);
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>TRADE_NO, 'api_trade_no'=>$result['reserved_mchnt_order_no'], 'buyer'=>$result['buyer_id'], 'money'=>strval(round($result['total_amount']/100, 2))]];
|
||||
}else{
|
||||
$retry = 0;
|
||||
$success = false;
|
||||
while($retry < 6){
|
||||
sleep(3);
|
||||
try{
|
||||
$result = self::orderQuery($client, $channel['appurl'].TRADE_NO, $order_type);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'订单查询失败:'.$e->getMessage()];
|
||||
}
|
||||
if($result['trans_stat'] == 'SUCCESS'){
|
||||
$success = true;
|
||||
break;
|
||||
}elseif($result['tranSts'] != 'USERPAYING' && $result['tranSts'] != 'NOTPAY'){
|
||||
return ['type'=>'error','msg'=>'订单超时或用户取消支付'];
|
||||
}
|
||||
$retry++;
|
||||
}
|
||||
if($success){
|
||||
processNotify($order, $result['mchnt_order_no'], $result['buyer_id'], $result['transaction_id']);
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>$result['orderNo'], 'api_trade_no'=>$result['mchnt_order_no'], 'buyer'=>$result['buyer_id'], 'money'=>strval(round($result['order_amt']/100, 2))]];
|
||||
}else{
|
||||
try{
|
||||
self::orderRevoked($client, $channel['appurl'].TRADE_NO, $order_type);
|
||||
}catch(Exception $e){
|
||||
}
|
||||
return ['type'=>'error','msg'=>'被扫下单失败!订单已超时'];
|
||||
}
|
||||
}
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'被扫下单失败!'.$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
static private function orderQuery($client, $out_trade_no, $order_type){
|
||||
global $channel;
|
||||
$params = [
|
||||
'order_type' => $order_type,
|
||||
'mchnt_order_no' => $out_trade_no,
|
||||
];
|
||||
$result = $client->request('/commonQuery', $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
static private function orderRevoked($client, $out_trade_no, $order_type){
|
||||
global $channel, $clientip;
|
||||
$params = [
|
||||
'order_type' => $order_type,
|
||||
'mchnt_order_no' => $out_trade_no,
|
||||
'cancel_order_no' => date('YmdHis').rand(1000,9999),
|
||||
'operator_id' => '',
|
||||
];
|
||||
$result = $client->request('/cancelorder', $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$xml = urldecode($_POST['req']);
|
||||
if(!$xml) return ['type'=>'html','data'=>'no data'];
|
||||
//file_put_contents('logs.txt', $xml);
|
||||
|
||||
$arr = json_decode(json_encode(simplexml_load_string($xml)), true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'xml err'];
|
||||
|
||||
require(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
$client = new PayService($channel['appid'],$channel['appmchid'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
$verify_result = $client->verifySign($arr);
|
||||
|
||||
if ($verify_result) {
|
||||
if($arr['result_code'] == '000000'){
|
||||
$out_trade_no = substr($arr['mchnt_order_no'], strlen($channel['appurl']));
|
||||
$api_trade_no = $arr['mchnt_order_no'];
|
||||
$bill_trade_no = $arr['transaction_id'];
|
||||
$money = $arr['order_amt'];
|
||||
$buyer = $arr['user_id'];
|
||||
if($out_trade_no == TRADE_NO){
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'1'];
|
||||
}
|
||||
return ['type'=>'html','data'=>'0'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'0'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/PayService.class.php");
|
||||
|
||||
if($order['type'] == 1) $pay_type = 'ALIPAY';
|
||||
else if($order['type'] == 2) $pay_type = 'WECHAT';
|
||||
else if($order['type'] == 4) $pay_type = 'UNIONPAY';
|
||||
|
||||
$param = [
|
||||
'mchnt_order_no' => $order['api_trade_no'],
|
||||
'refund_order_no' => $order['refund_no'],
|
||||
'order_type' => $pay_type,
|
||||
'total_amt' => strval($order['realmoney']*100),
|
||||
'refund_amt' => strval($order['refundmoney']*100),
|
||||
'operator_id' => '',
|
||||
];
|
||||
|
||||
$client = new PayService($channel['appid'],$channel['appmchid'],$channel['appkey'],$channel['appsecret'],$channel['appswitch']==1);
|
||||
|
||||
try{
|
||||
$result = $client->submit('/commonRefund', $param);
|
||||
|
||||
return ['code'=>0, 'trade_no'=>$result['mchnt_order_no'], 'refund_fee'=>$result['reserved_refund_amt']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//投诉回调
|
||||
static public function complainnotify(){
|
||||
global $channel, $order;
|
||||
|
||||
$json = $_POST['req'];
|
||||
if(!$json) return ['type'=>'html','data'=>'no req'];
|
||||
|
||||
$data = json_decode($json,true);
|
||||
if(!$data) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
require(PAY_ROOT."inc/EntryService.class.php");
|
||||
|
||||
$client = new EntryService($channel['appid'],$channel['entrykey']);
|
||||
$verify_result = $client->verifySign($data);
|
||||
|
||||
if ($verify_result) {
|
||||
$thirdid = $data['complaint_id'];
|
||||
$action_type = $data['action_type'];
|
||||
if(substr($channel['appmchid'],0,1)=='['){
|
||||
$channel['appmchid'] = $data['fy_mchnt_cd'];
|
||||
}
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($thirdid, $action_type);
|
||||
return ['type'=>'html','data'=>'1'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'0'];
|
||||
}
|
||||
}
|
||||
|
||||
//平台入网审核回调
|
||||
static public function applynotify(){
|
||||
global $channel, $order;
|
||||
|
||||
$json = $_POST['req'];
|
||||
if(!$json) return ['type'=>'html','data'=>'no req'];
|
||||
|
||||
$data = json_decode($json,true);
|
||||
if(!$data) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
require(PAY_ROOT."inc/EntryService.class.php");
|
||||
|
||||
$client = new EntryService($channel['appid'],$channel['entrykey']);
|
||||
$verify_result = $client->verifySign($data);
|
||||
|
||||
if ($verify_result) {
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($data);
|
||||
return ['type'=>'html','data'=>'1'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'0'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
class EntryService
|
||||
{
|
||||
private $ins_cd;
|
||||
private $key;
|
||||
private $xml;
|
||||
private $gateway_url = 'https://mchntapi.fuioupay.com';
|
||||
|
||||
public function __construct($ins_cd, $key, $is_test = false)
|
||||
{
|
||||
$this->ins_cd = $ins_cd;
|
||||
$this->key = $key;
|
||||
if($is_test){
|
||||
$this->gateway_url = 'http://www-1.fuiou.com:28090/wmp';
|
||||
}
|
||||
$this->xml = new XmlWriter();
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function submit($path, $params, $is_file = false, $is_download = false){
|
||||
$requrl = $this->gateway_url.$path;
|
||||
$public_params = [
|
||||
'trace_no' => getSid(),
|
||||
'ins_cd' => $this->ins_cd,
|
||||
];
|
||||
|
||||
foreach($params as $key=>$value){
|
||||
if(!$is_file && $value) $params[$key] = mb_convert_encoding($params[$key], 'GBK', 'UTF-8');
|
||||
}
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->makeSign($params);
|
||||
|
||||
if($is_file){
|
||||
$response = get_curl($requrl, $params);
|
||||
}else{
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\"?><xml>".$this->toXml($params)."</xml>";
|
||||
|
||||
$response = get_curl($requrl, 'req='.urlencode(urlencode($xml)));
|
||||
}
|
||||
if($is_download) return $response;
|
||||
if(strpos($response, '%3Cxml%3E') !== false){
|
||||
$response = urldecode($response);
|
||||
}
|
||||
$response = str_ireplace('encoding="gbk"', 'encoding="utf-8"', $response);
|
||||
LIBXML_VERSION < 20900 && libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($response)), true);
|
||||
if(empty($result)){
|
||||
$response = mb_convert_encoding($response, 'UTF-8', 'GBK');
|
||||
$result = json_decode(json_encode(simplexml_load_string($response)), true);
|
||||
}
|
||||
|
||||
//file_put_contents('log.txt', $path.' '.$params['trace_no'].PHP_EOL, FILE_APPEND);
|
||||
|
||||
if(isset($result['ret_code']) && ($result['ret_code']=='000000' || $result['ret_code']=='0000')){
|
||||
return $result;
|
||||
}elseif(isset($result['return_code']) && $result['return_code']=='SUCCESS'){
|
||||
return $result;
|
||||
}elseif(isset($result['ret_msg'])){
|
||||
throw new Exception($result['ret_msg']);
|
||||
}elseif(isset($result['return_msg'])){
|
||||
throw new Exception($result['return_msg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function submit_json($path, $params, $is_file = false){
|
||||
$requrl = $this->gateway_url.$path;
|
||||
$public_params = [
|
||||
'trace_no' => getSid(),
|
||||
'ins_cd' => $this->ins_cd,
|
||||
];
|
||||
|
||||
foreach($params as $key=>$value){
|
||||
if(!$is_file && $value) $params[$key] = mb_convert_encoding($params[$key], 'GBK', 'UTF-8');
|
||||
}
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->makeSign($params);
|
||||
|
||||
if($is_file){
|
||||
$response = get_curl($requrl, $params);
|
||||
}else{
|
||||
$json = json_encode($params);
|
||||
$response = get_curl($requrl, 'req='.urlencode($json));
|
||||
}
|
||||
$result = json_decode($response, true);
|
||||
|
||||
//file_put_contents('log.txt', $path.' '.$params['trace_no'].PHP_EOL, FILE_APPEND);
|
||||
|
||||
if(isset($result['ret_code']) && ($result['ret_code']=='000000' || $result['ret_code']=='0000')){
|
||||
return $result;
|
||||
}elseif(isset($result['ret_msg'])){
|
||||
throw new Exception($result['ret_msg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function submit_json_v2($path, $params){
|
||||
$requrl = $this->gateway_url.$path;
|
||||
$public_params = [
|
||||
'traceNo' => getSid(),
|
||||
'insCd' => $this->ins_cd,
|
||||
];
|
||||
|
||||
foreach($params as $key=>$value){
|
||||
if($value) $params[$key] = mb_convert_encoding($params[$key], 'GBK', 'UTF-8');
|
||||
}
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->makeSign($params);
|
||||
|
||||
$json = json_encode($params);
|
||||
$response = get_curl($requrl, 'req='.urlencode($json));
|
||||
$result = json_decode($response, true);
|
||||
|
||||
//file_put_contents('log.txt', $path.' '.$params['traceNo'].PHP_EOL, FILE_APPEND);
|
||||
|
||||
if(isset($result['retCode']) && $result['retCode']=='0000'){
|
||||
return $result;
|
||||
}elseif(isset($result['retMsg'])){
|
||||
throw new Exception($result['retMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function verifySign($param){
|
||||
$sign = $param['sign'];
|
||||
if(!$sign) return false;
|
||||
return $sign === $this->makeSign($param);
|
||||
}
|
||||
|
||||
//生成签名
|
||||
private function makeSign($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && !$v instanceof \CURLFile && !is_array($v) && !$this->isEmpty($v)){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr .= 'key='.$this->key;
|
||||
$sign = md5($signstr);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
private function isEmpty($value){
|
||||
return $value === null || $value === '';
|
||||
}
|
||||
|
||||
private function toXml($data, $eIsArray=FALSE) {
|
||||
if(!$eIsArray) {
|
||||
$this->xml->openMemory();
|
||||
}
|
||||
foreach($data as $key => $value){
|
||||
if(is_array($value)){
|
||||
$this->xml->startElement($key);
|
||||
$this->toXml($value, TRUE);
|
||||
$this->xml->endElement();
|
||||
continue;
|
||||
}
|
||||
$this->xml->writeElement($key, $value);
|
||||
}
|
||||
if(!$eIsArray) {
|
||||
$this->xml->endElement();
|
||||
return $this->xml->outputMemory(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://fundwx.fuiou.com/doc/#/
|
||||
*/
|
||||
class PayService
|
||||
{
|
||||
private $version = '1.0';
|
||||
private $ins_cd;
|
||||
private $mchnt_cd;
|
||||
private $platform_public_key;
|
||||
private $merchant_private_key;
|
||||
private $xml;
|
||||
private $gateway_url = 'https://spay-mc.fuioupay.com';
|
||||
|
||||
public function __construct($ins_cd, $mchnt_cd, $platform_public_key, $merchant_private_key, $is_test = false)
|
||||
{
|
||||
$this->ins_cd = $ins_cd;
|
||||
$this->mchnt_cd = $mchnt_cd;
|
||||
$this->platform_public_key = $platform_public_key;
|
||||
$this->merchant_private_key = $merchant_private_key;
|
||||
if($is_test){
|
||||
$this->gateway_url = 'https://fundwx.fuiou.com';
|
||||
}
|
||||
$this->xml = new XmlWriter();
|
||||
}
|
||||
|
||||
//发起API请求
|
||||
public function submit($path, $params){
|
||||
$requrl = $this->gateway_url.$path;
|
||||
$public_params = [
|
||||
'version' => $this->version,
|
||||
'ins_cd' => $this->ins_cd,
|
||||
'mchnt_cd' => $this->mchnt_cd,
|
||||
'term_id' => '88888888',
|
||||
'random_str' => getSid(),
|
||||
];
|
||||
|
||||
foreach($params as $key=>$value){
|
||||
if($value) $params[$key] = mb_convert_encoding($params[$key], 'GBK', 'UTF-8');
|
||||
}
|
||||
|
||||
$params = array_merge($public_params, $params);
|
||||
$params['sign'] = $this->generateSign($params);
|
||||
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\"?><xml>".$this->toXml($params)."</xml>";
|
||||
|
||||
$response = get_curl($requrl, 'req='.urlencode(urlencode($xml)));
|
||||
$response = urldecode($response);
|
||||
LIBXML_VERSION < 20900 && libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($response)), true);
|
||||
|
||||
if(isset($result['result_code']) && ($result['result_code']=='000000' || $result['result_code']=='030010')){
|
||||
if(!$this->verifyResponse($result)){
|
||||
throw new Exception('返回数据验签失败');
|
||||
}
|
||||
return $result;
|
||||
}elseif(isset($result['result_msg'])){
|
||||
throw new Exception($result['result_msg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//获取待签名字符串
|
||||
private function getSignContent($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && substr($k,0,8)!='reserved'){
|
||||
if(is_array($v))$v = '';
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = substr($signstr,0,-1);
|
||||
return $signstr;
|
||||
}
|
||||
|
||||
//请求参数签名
|
||||
private function generateSign($param){
|
||||
return $this->rsaPrivateSign($this->getSignContent($param));
|
||||
}
|
||||
|
||||
//返回数据验签
|
||||
private function verifyResponse($param){
|
||||
if(empty($param['sign'])) return false;
|
||||
foreach($param as $key=>$value){
|
||||
if(is_array($value)) $param[$key] = '';
|
||||
else $param[$key] = mb_convert_encoding($param[$key], 'GBK', 'UTF-8');
|
||||
}
|
||||
return $this->verifySign($param);
|
||||
}
|
||||
|
||||
//验签方法
|
||||
public function verifySign($param){
|
||||
if(empty($param['sign'])) return false;
|
||||
return $this->rsaPubilcSign($this->getSignContent($param), $param['sign']);
|
||||
}
|
||||
|
||||
//商户私钥签名
|
||||
private function rsaPrivateSign($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('签名失败,商户私钥不正确');
|
||||
}
|
||||
openssl_sign($data, $signature, $pkeyid, OPENSSL_ALGO_MD5);
|
||||
$signature = base64_encode($signature);
|
||||
return $signature;
|
||||
}
|
||||
|
||||
//平台公钥验签
|
||||
private function rsaPubilcSign($data, $signature){
|
||||
$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('验签失败,富友公钥不正确');
|
||||
}
|
||||
$result = openssl_verify($data, base64_decode($signature), $pubkeyid, OPENSSL_ALGO_MD5);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function toXml($data, $eIsArray=FALSE) {
|
||||
if(!$eIsArray) {
|
||||
$this->xml->openMemory();
|
||||
}
|
||||
foreach($data as $key => $value){
|
||||
if(is_array($value)){
|
||||
$this->xml->startElement($key);
|
||||
$this->toXml($value, TRUE);
|
||||
$this->xml->endElement();
|
||||
continue;
|
||||
}
|
||||
$this->xml->writeElement($key, $value);
|
||||
}
|
||||
if(!$eIsArray) {
|
||||
$this->xml->endElement();
|
||||
return $this->xml->outputMemory(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,526 @@
|
||||
<?php
|
||||
|
||||
//http://39.106.84.215:8181/docs/saas/saas-1fdsisa23tp3f
|
||||
class haipay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'haipay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '海科聚合支付', //支付插件显示名称
|
||||
'author' => '海科融通', //支付插件作者
|
||||
'link' => 'https://www.hkrt.cn/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'accessid' => [
|
||||
'name' => 'accessid',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'accesskey' => [
|
||||
'name' => '接入秘钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'agent_no' => [
|
||||
'name' => '服务商编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'merch_no' => [
|
||||
'name' => '商户编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'pn' => [
|
||||
'name' => '终端号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => 'JS支付',
|
||||
],
|
||||
'note' => '需要先加服务器IP白名单,否则无法调用支付', //支付密钥填写说明
|
||||
'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() && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile() && $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' && $channel['appwxmp']>0){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile' && $channel['appwxa']>0){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//预下单
|
||||
static private function prepay($pay_type, $pay_mode, $sub_openid = null, $sub_appid = null){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require_once PAY_ROOT.'inc/HaiPayClient.php';
|
||||
|
||||
$params = [
|
||||
'agent_no' => $channel['agent_no'],
|
||||
'merch_no' => $channel['merch_no'],
|
||||
'pay_type' => $pay_type,
|
||||
'pay_mode' => $pay_mode,
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'pn' => $channel['pn'],
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
];
|
||||
if($sub_openid) $params['openid'] = $sub_openid;
|
||||
if($sub_appid) $params['appid'] = $sub_appid;
|
||||
if($pay_type == 'WX'){
|
||||
$params['extend_params'] = ['body'=>$ordername];
|
||||
}elseif($pay_type == 'ALI'){
|
||||
$params['extend_params'] = ['subject'=>$ordername];
|
||||
}
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->payRequest('/api/v2/pay/pre-pay', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['trade_no']);
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
static private function handleProfits(&$params){
|
||||
global $order;
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver){
|
||||
$relation = [];
|
||||
foreach($psreceiver['info'] as $receiver){
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']) / 100, 2);
|
||||
$relation[] = [
|
||||
'receive_no' => $receiver['account'],
|
||||
'amt' => sprintf('%.2f' , $psmoney),
|
||||
];
|
||||
}
|
||||
$params['ledger_biz'] = [
|
||||
'ledger_type' => $psreceiver['mode'] == 1 ? 'DELAY_SETTLE' : 'REALTIME_SETTLE',
|
||||
'ledger_relation' => $relation,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype']) || empty($channel['apptype'][0])){
|
||||
try{
|
||||
$result = self::prepay('ALI', 'NATIVE');
|
||||
$code_url = $result['ali_qr_code'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}elseif(in_array('2',$channel['apptype'])){
|
||||
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
if(checkalipay() || $mdevice=='alipay'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝JS支付
|
||||
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::prepay('ALI', 'JSAPI', $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$result['ali_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'=>$result['ali_trade_no'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $siteurl, $device, $mdevice, $channel;
|
||||
/*try{
|
||||
$result = self::prepay('WX', 'NATIVE');
|
||||
$code_url = $result['code_url'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}*/
|
||||
if($channel['appwxa']>0 && $channel['appwxmp']==0){
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}
|
||||
|
||||
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, $ordername, $conf, $method;
|
||||
|
||||
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::prepay('WX','JSAPI',$openid,$wxinfo['appid']);
|
||||
$pay_info = $result['wc_pay_data'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$pay_info];
|
||||
}
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$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{
|
||||
$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::prepay('WX','JSAPI',$openid,$wxinfo['appid']);
|
||||
$pay_info = $result['wc_pay_data'];
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'微信支付下单失败 '.$ex->getMessage()]));
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($pay_info, 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(){
|
||||
try{
|
||||
$result = self::prepay('UNIONQR', 'NATIVE');
|
||||
$code_url = $result['uniqr_qr_code'];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//付款码支付
|
||||
static public function scanpay(){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require_once PAY_ROOT.'inc/HaiPayClient.php';
|
||||
|
||||
$params = [
|
||||
'accessid' => $channel['accessid'],
|
||||
'merch_no' => $channel['merch_no'],
|
||||
'auth_code' => $order['auth_code'],
|
||||
'out_trade_no' => TRADE_NO,
|
||||
'total_amount' => $order['realmoney'],
|
||||
'pn' => $channel['pn'],
|
||||
'notify_url' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
];
|
||||
if($order['typename'] == 'wxpay'){
|
||||
$params['extend_params'] = ['body'=>$ordername];
|
||||
}elseif($order['typename'] == 'alipay'){
|
||||
$params['extend_params'] = ['subject'=>$ordername];
|
||||
}
|
||||
$params['terminal_info'] = ['device_ip' => $clientip];
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
|
||||
try{
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
$result = $client->payRequest('/api/v2/pay/passive-pay', $params);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'被扫下单失败!'.$e->getMessage()];
|
||||
}
|
||||
|
||||
$api_trade_no = $result['trade_no'];
|
||||
if($result['trade_status'] == '1'){
|
||||
$result = self::orderQuery($client, $api_trade_no);
|
||||
processNotify($order, $api_trade_no, $result['openid'], $result['bank_trade_no']);
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>$result['out_trade_no'], 'api_trade_no'=>$api_trade_no, 'buyer'=>$result['openid'], 'money'=>$result['order_amount']]];
|
||||
}else{
|
||||
$retry = 0;
|
||||
$success = false;
|
||||
while($retry < 6){
|
||||
sleep(3);
|
||||
try{
|
||||
$result = self::orderQuery($client, $api_trade_no);
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'订单查询失败:'.$e->getMessage()];
|
||||
}
|
||||
if($result['trade_status'] == '1'){
|
||||
$success = true;
|
||||
break;
|
||||
}elseif($result['tranSts'] != '3'){
|
||||
return ['type'=>'error','msg'=>'订单超时或用户取消支付'];
|
||||
}
|
||||
$retry++;
|
||||
}
|
||||
if($success){
|
||||
processNotify($order, $api_trade_no, $result['openid'], $result['bank_trade_no']);
|
||||
return ['type'=>'scan','data'=>['type'=>$order['typename'], 'trade_no'=>$result['out_trade_no'], 'api_trade_no'=>$api_trade_no, 'buyer'=>$result['openid'], 'money'=>$result['order_amount']]];
|
||||
}else{
|
||||
try{
|
||||
self::orderClose($client, $api_trade_no);
|
||||
}catch(Exception $e){
|
||||
}
|
||||
return ['type'=>'error','msg'=>'被扫下单失败!订单已超时'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static private function orderQuery($client, $api_trade_no){
|
||||
global $channel;
|
||||
$params = [
|
||||
'merch_no' => $channel['merch_no'],
|
||||
'trade_no' => $api_trade_no,
|
||||
];
|
||||
$result = $client->payRequest('/api/v2/pay/order-query', $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
static private function orderClose($client, $api_trade_no){
|
||||
global $channel, $clientip;
|
||||
$params = [
|
||||
'merch_no' => $channel['merch_no'],
|
||||
'trade_no' => $api_trade_no,
|
||||
];
|
||||
$result = $client->payRequest('/api/v2/pay/close-order', $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
//异步回调
|
||||
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/HaiPayClient.php';
|
||||
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
|
||||
if($client->verify($arr)){
|
||||
if($arr['trade_status'] == '1'){
|
||||
$out_trade_no = $arr['out_trade_no'];
|
||||
$api_trade_no = $arr['trade_no'];
|
||||
$bill_trade_no = $arr['bank_trade_no'];
|
||||
$money = $arr['order_amount'];
|
||||
$buyer = $arr['openid'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'json','data'=>['return_code'=>'SUCCESS']];
|
||||
}else{
|
||||
return ['type'=>'json','data'=>['return_code'=>'FAIL', 'return_msg'=>'SIGN ERROR']];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $clientip;
|
||||
if(empty($order))exit();
|
||||
|
||||
require_once PAY_ROOT.'inc/HaiPayClient.php';
|
||||
|
||||
$params = [
|
||||
'agent_no' => $channel['agent_no'],
|
||||
'merch_no' => $channel['merch_no'],
|
||||
'trade_no' => $order['api_trade_no'],
|
||||
'out_refund_no' => $order['refund_no'],
|
||||
'refund_amount' => $order['refundmoney'],
|
||||
'pn' => $channel['pn'],
|
||||
];
|
||||
|
||||
try{
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
$result = $client->payRequest('/api/v2/pay/refund', $params);
|
||||
return ['code'=>0, 'trade_no'=>$result['refund_no'], 'refund_fee'=>$result['refund_amount']];
|
||||
}catch(Exception $e){
|
||||
return ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//进件回调
|
||||
static public function applynotify(){
|
||||
global $channel;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json,true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'No data'];
|
||||
|
||||
require_once PAY_ROOT.'inc/HaiPayClient.php';
|
||||
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
|
||||
if($client->verify($arr)){
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($arr);
|
||||
return ['type'=>'json','data'=>['return_code'=>'SUCCESS']];
|
||||
}else{
|
||||
return ['type'=>'json','data'=>['return_code'=>'FAIL', 'return_msg'=>'SIGN ERROR']];
|
||||
}
|
||||
}
|
||||
|
||||
//投诉回调
|
||||
static public function complainnotify(){
|
||||
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/HaiPayClient.php';
|
||||
|
||||
$client = new HaiPayClient($channel['accessid'], $channel['accesskey']);
|
||||
|
||||
if($client->verify($arr)){
|
||||
$thirdid = $arr['complaintId'];
|
||||
if(isset($arr['gmtComplain'])){
|
||||
$channel['type'] = 1;
|
||||
}else{
|
||||
$channel['type'] = 2;
|
||||
}
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($thirdid);
|
||||
return ['type'=>'json','data'=>['return_code'=>'SUCCESS']];
|
||||
}else{
|
||||
return ['type'=>'json','data'=>['return_code'=>'FAIL', 'return_msg'=>'SIGN ERROR']];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* http://opendocs.hkrt.cn:8181/docs/saas
|
||||
*/
|
||||
class HaiPayClient
|
||||
{
|
||||
private $pay_url = 'https://saas-front.hkrt.cn';
|
||||
private $mch_url = 'http://saas.hkrt.cn:8080';
|
||||
|
||||
private $accessid;
|
||||
|
||||
private $accesskey;
|
||||
|
||||
public function __construct($accessid, $accesskey, $isTest = false){
|
||||
$this->accessid = $accessid;
|
||||
$this->accesskey = $accesskey;
|
||||
if($isTest){
|
||||
$this->pay_url = 'http://39.106.187.68:8080';
|
||||
$this->mch_url = 'http://47.95.131.62:8080';
|
||||
}
|
||||
}
|
||||
|
||||
//发起支付请求
|
||||
public function payRequest($path, $params)
|
||||
{
|
||||
$requrl = $this->pay_url . $path;
|
||||
$params['accessid'] = $this->accessid;
|
||||
$params['req_id'] = date('YmdHis').rand(1000, 9999);
|
||||
$params['sign'] = $this->make_sign($params);
|
||||
|
||||
$data = get_curl($requrl, json_encode($params), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['result_code']) && $result['result_code']==10000){
|
||||
return $result;
|
||||
}elseif(!empty($result['result_msg'])){
|
||||
throw new Exception($result['result_msg']);
|
||||
}else{
|
||||
throw new Exception($result['return_msg']?$result['return_msg']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//发起进件请求
|
||||
public function mchRequest($path, $params)
|
||||
{
|
||||
$requrl = $this->mch_url . $path;
|
||||
$params['accessid'] = $this->accessid;
|
||||
$params['sign'] = $this->make_sign($params);
|
||||
|
||||
$data = get_curl($requrl, json_encode($params), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['return_code']) && $result['return_code']==10000){
|
||||
return $result;
|
||||
}elseif(!empty($result['result_msg'])){
|
||||
throw new Exception($result['result_msg']);
|
||||
}else{
|
||||
throw new Exception($result['return_msg']?$result['return_msg']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function mchRequest2($path, $params)
|
||||
{
|
||||
$requrl = $this->mch_url . $path;
|
||||
$params['accessid'] = $this->accessid;
|
||||
$params['sign'] = $this->make_sign($params);
|
||||
|
||||
$data = get_curl($requrl, json_encode($params), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function verify($params){
|
||||
if(!isset($params['sign'])) return false;
|
||||
$sign = $this->make_sign($params);
|
||||
return $sign === $params['sign'];
|
||||
}
|
||||
|
||||
private function get_sign_str($param){
|
||||
if(!is_array($param)) return $param;
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $v!==null && $v!==''){
|
||||
if(is_array($v)){
|
||||
if(empty($v)) continue;
|
||||
if(array_keys($v) === range(0, count($v) - 1)){
|
||||
$strs = [];
|
||||
foreach($v as $vv){
|
||||
$strs[] = self::get_sign_str($vv);
|
||||
}
|
||||
$v = implode('&', $strs);
|
||||
}else{
|
||||
$v = self::get_sign_str($v);
|
||||
}
|
||||
}
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
return substr($signstr, 0, -1);
|
||||
}
|
||||
|
||||
private function make_sign($param){
|
||||
$signstr = self::get_sign_str($param);
|
||||
$signstr .= $this->accesskey;
|
||||
$sign = strtoupper(md5($signstr));
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,696 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://open.heepay.com/www/index.html#/openDoc?type=menu&id=2022
|
||||
*/
|
||||
class heepay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'heepay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '汇付宝', //支付插件显示名称
|
||||
'author' => '汇付宝', //支付插件作者
|
||||
'link' => 'https://www.heepay.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'transtypes' => ['alipay','wxpay','bank'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '商户编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '二级商户号',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,集团模式传参',
|
||||
],
|
||||
'bank_id' => [
|
||||
'name' => '上游商户BankId',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,若需指定上游商户号可填写,多个用,隔开',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '支付密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '退款密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'transfer_key' => [
|
||||
'name' => '付款密钥',
|
||||
'type' => 'input',
|
||||
'note' => '不需要付款功能的可留空',
|
||||
],
|
||||
'transfer_des_key' => [
|
||||
'name' => '付款3DES加密密钥',
|
||||
'type' => 'input',
|
||||
'note' => '不需要付款功能的可留空',
|
||||
],
|
||||
'mch_private_key' => [
|
||||
'name' => '常规业务RSA私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '不需要投诉查询功能的可留空',
|
||||
],
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '小程序H5支付',
|
||||
],
|
||||
'select_bank' => [
|
||||
'1' => '网银支付',
|
||||
'2' => '银联支付',
|
||||
'3' => '云闪付H5',
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static private function getPayParam($pay_type, $sub_appid = null, $sub_openid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $device, $mdevice;
|
||||
|
||||
$param = [
|
||||
'version' => '1',
|
||||
'pay_type' => $pay_type,
|
||||
'agent_id' => $channel['appid'],
|
||||
'agent_bill_id' => TRADE_NO,
|
||||
'agent_bill_time' => date('YmdHis'),
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'user_ip' => str_replace('.', '_', $clientip),
|
||||
'goods_name' => mb_convert_encoding($ordername,'GBK','UTF-8'),
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $param['ref_agent_id'] = $channel['appmchid'];
|
||||
if(checkmobile() || $device=='mobile'){
|
||||
$param['is_phone'] = '1';
|
||||
}
|
||||
$meta_option = [];
|
||||
if($order['profits'] > 0) $meta_option['is_guarantee'] = '1';
|
||||
if($pay_type == '30' && $sub_appid && $sub_openid){
|
||||
$meta_option['s'] = '微信小程序';
|
||||
$meta_option['n'] = '在线商城';
|
||||
$meta_option['id'] = $siteurl;
|
||||
$meta_option['is_minipg'] = '1';
|
||||
$meta_option['wx_openid'] = $sub_openid;
|
||||
$meta_option['wx_sub_appid'] = $sub_appid;
|
||||
}
|
||||
elseif($pay_type == '30' && (checkwechat() || $mdevice=='wechat')){
|
||||
$param['is_frame'] = '1';
|
||||
$meta_option['s'] = 'WAP';
|
||||
$meta_option['n'] = '在线商城';
|
||||
$meta_option['id'] = $siteurl;
|
||||
}
|
||||
if(!empty($meta_option)){
|
||||
$param['meta_option'] = base64_encode(mb_convert_encoding(json_encode($meta_option, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),'GBK','UTF-8'));
|
||||
}
|
||||
if(!empty($channel['bank_id'])){
|
||||
if(strpos($channel['bank_id'], ',') !== false){
|
||||
$bank_ids = explode(',', $channel['bank_id']);
|
||||
$channel['bank_id'] = $bank_ids[array_rand($bank_ids)];
|
||||
}
|
||||
$param['bank_id'] = $channel['bank_id'];
|
||||
}
|
||||
|
||||
$signstr = 'version='.$param['version'].'&agent_id='.$param['agent_id'].'&agent_bill_id='.$param['agent_bill_id'].'&agent_bill_time='.$param['agent_bill_time'].'&pay_type='.$param['pay_type'].'&pay_amt='.$param['pay_amt'].'¬ify_url='.$param['notify_url'].'&return_url='.$param['return_url'].'&user_ip='.$param['user_ip'].'&key='.$channel['appkey'];
|
||||
if(!empty($param['ref_agent_id'])) $signstr .= '&ref_agent_id='.$param['ref_agent_id'];
|
||||
$param['sign'] = md5($signstr);
|
||||
return $param;
|
||||
}
|
||||
|
||||
static private function getBankPayParam(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $device, $mdevice;
|
||||
|
||||
$param = [
|
||||
'version' => '3',
|
||||
'pay_type' => '20',
|
||||
'pay_code' => '0',
|
||||
'agent_id' => $channel['appid'],
|
||||
'agent_bill_id' => TRADE_NO,
|
||||
'agent_bill_time' => date('YmdHis'),
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'user_ip' => str_replace('.', '_', $clientip),
|
||||
'goods_name' => mb_convert_encoding($ordername,'GBK','UTF-8'),
|
||||
'bank_card_type' => '-1',
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $param['ref_agent_id'] = $channel['appmchid'];
|
||||
if($order['profits'] > 0) $param['meta_option'] = base64_encode('{"is_guarantee":"1"}');
|
||||
|
||||
$signstr = 'version='.$param['version'].'&agent_id='.$param['agent_id'].'&agent_bill_id='.$param['agent_bill_id'].'&agent_bill_time='.$param['agent_bill_time'].'&pay_type='.$param['pay_type'].'&pay_amt='.$param['pay_amt'].'¬ify_url='.$param['notify_url'].'&return_url='.$param['return_url'].'&user_ip='.$param['user_ip'].'&bank_card_type='.$param['bank_card_type'].'&key='.$channel['appkey'];
|
||||
if(!empty($param['ref_agent_id'])) $signstr .= '&ref_agent_id='.$param['ref_agent_id'];
|
||||
$param['sign'] = md5($signstr);
|
||||
return $param;
|
||||
}
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order;
|
||||
|
||||
if($order['typename'] == 'alipay'){
|
||||
$pay_type = '22';
|
||||
}elseif($order['typename'] == 'wxpay'){
|
||||
if(checkmobile() && !checkwechat()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
|
||||
}
|
||||
$pay_type = '30';
|
||||
}elseif($order['typename'] == 'bank'){
|
||||
if(in_array('3',$channel['apptype'])){
|
||||
$pay_type = '34';
|
||||
}elseif(in_array('1',$channel['apptype'])){
|
||||
$pay_type = '20';
|
||||
}else{
|
||||
$pay_type = checkmobile() ? '34' : '64';
|
||||
}
|
||||
}
|
||||
|
||||
$apiurl = 'https://pay.Heepay.com/Payment/Index.aspx';
|
||||
$param = $pay_type == '20' ? self::getBankPayParam() : self::getPayParam($pay_type);
|
||||
$url = $apiurl.'?'.http_build_query($param);
|
||||
|
||||
return ['type'=>'jump','url'=>$url];
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $device, $mdevice, $method;
|
||||
|
||||
if($method == 'app' && $order['typename']=='wxpay'){
|
||||
return self::wxapppay();
|
||||
}
|
||||
elseif($order['typename'] == 'alipay'){
|
||||
$pay_type = '22';
|
||||
}elseif($order['typename'] == 'wxpay'){
|
||||
if($device=='mobile' && $mdevice!='wechat'){
|
||||
return self::wxwappay();
|
||||
}
|
||||
$pay_type = '30';
|
||||
}elseif($order['typename'] == 'bank'){
|
||||
if(in_array('3',$channel['apptype'])){
|
||||
$pay_type = '34';
|
||||
}elseif(in_array('1',$channel['apptype'])){
|
||||
$pay_type = '20';
|
||||
}else{
|
||||
$pay_type = $device=='mobile' ? '34' : '64';
|
||||
}
|
||||
}
|
||||
|
||||
$apiurl = 'https://pay.Heepay.com/Payment/Index.aspx';
|
||||
$param = $pay_type == '20' ? self::getBankPayParam() : self::getPayParam($pay_type);
|
||||
$url = $apiurl.'?'.http_build_query($param);
|
||||
|
||||
return ['type'=>'jump','url'=>$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'].'"}');
|
||||
|
||||
//②、统一下单
|
||||
$apiurl = 'https://pay.Heepay.com/Payment/Index.aspx';
|
||||
$param = self::getPayParam('30', $wxinfo['appid'], $openid);
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result['package'])){
|
||||
exit(json_encode(['code'=>0, 'data'=>$result]));
|
||||
}elseif(preg_match('!Object moved to <a href=\"(.*?)\">here!', $response, $match)){
|
||||
if(strpos($match[1], 'Error.aspx?message=')){
|
||||
$message = explode('Error.aspx?message=', $match[1])[1];
|
||||
$message = self::unicode_urldecode($message);
|
||||
exit('{"code":-1,"msg":"'.$message.'"}');
|
||||
}else{
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!"}');
|
||||
}
|
||||
}else{
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!"}');
|
||||
}
|
||||
}
|
||||
|
||||
//汇付宝微信小程序支付
|
||||
static private function appletpay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
$apiurl = 'https://pay.heepay.com/Phone/SDK/PayInit.aspx';
|
||||
$param = [
|
||||
'version' => '1',
|
||||
'pay_type' => '30',
|
||||
'agent_id' => $channel['appid'],
|
||||
'agent_bill_id' => TRADE_NO,
|
||||
'agent_bill_time' => date('YmdHis'),
|
||||
'pay_amt' => $order['realmoney'],
|
||||
'notify_url' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'return_url' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'user_ip' => str_replace('.', '_', $clientip),
|
||||
'goods_name' => mb_convert_encoding($ordername,'GBK','UTF-8'),
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $param['ref_agent_id'] = $channel['appmchid'];
|
||||
$meta_option = ['s' => '微信小程序', 'n' => '在线商城', 'id' => $siteurl];
|
||||
if($order['profits'] > 0) $meta_option['is_guarantee'] = '1';
|
||||
$param['meta_option'] = base64_encode(mb_convert_encoding(json_encode($meta_option, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),'GBK','UTF-8'));
|
||||
if(!empty($channel['bank_id'])){
|
||||
if(strpos($channel['bank_id'], ',') !== false){
|
||||
$bank_ids = explode(',', $channel['bank_id']);
|
||||
$channel['bank_id'] = $bank_ids[array_rand($bank_ids)];
|
||||
}
|
||||
$param['bank_id'] = $channel['bank_id'];
|
||||
}
|
||||
|
||||
$signstr = 'version='.$param['version'].'&agent_id='.$param['agent_id'].'&agent_bill_id='.$param['agent_bill_id'].'&agent_bill_time='.$param['agent_bill_time'].'&pay_type='.$param['pay_type'].'&pay_amt='.$param['pay_amt'].'¬ify_url='.$param['notify_url'].'&user_ip='.$param['user_ip'].'&key='.$channel['appkey'];
|
||||
$param['sign'] = md5($signstr);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($apiurl, $param) {
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
if(preg_match('!<token_id>(.*?)</token_id>!', $response, $match)){
|
||||
$token_id = $match[1];
|
||||
}elseif(preg_match('!<error>(.*?)</error>!', $response, $match)){
|
||||
throw new Exception($match[1]);
|
||||
}else{
|
||||
throw new Exception('接口调用失败');
|
||||
}
|
||||
return $token_id;
|
||||
});
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if(in_array('2',$channel['apptype'])){
|
||||
try{
|
||||
$token_id = self::appletpay();
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败,'.$e->getMessage()];
|
||||
}
|
||||
$url = 'https://pay.heepay.com/MSite/Cashier/Code2Session.aspx?appid=wxfac21f54eeaabb58&token_id='.$token_id;
|
||||
$response = get_curl($url);
|
||||
$arr = json_decode($response, true);
|
||||
if(isset($arr['openlink'])){
|
||||
return ['type'=>'scheme','page'=>'wxpay_mini','url'=>$arr['openlink']];
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'小程序跳转链接生成失败,'.$arr['errmsg']];
|
||||
}
|
||||
}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{
|
||||
$code_url = $siteurl.'pay/submit/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
static public function wxapppay(){
|
||||
try{
|
||||
$token_id = self::appletpay();
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败,'.$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'wxapp','data'=>['appId'=>'wxfac21f54eeaabb58', 'miniProgramId'=>'gh_5c5293af946b', 'path'=>'pages/init/init?token_id='.$token_id]];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
$signstr = 'result='.$_GET['result'].'&agent_id='.$_GET['agent_id'].'&jnet_bill_no='.$_GET['jnet_bill_no'].'&agent_bill_id='.$_GET['agent_bill_id'].'&pay_type='.$_GET['pay_type'].'&pay_amt='.$_GET['pay_amt'].'&remark='.$_GET['remark'].'&key='.$channel['appkey'];
|
||||
$sign = md5($signstr);
|
||||
|
||||
if($sign===$_GET["sign"]){
|
||||
if($_GET['result'] == '1'){
|
||||
$out_trade_no = $_GET['agent_bill_id'];
|
||||
$api_trade_no = $_GET['jnet_bill_no'];
|
||||
$money = $_GET['pay_amt'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)) {
|
||||
processNotify($order, $api_trade_no, $_GET['pay_user'], $_GET['trade_bill_no']);
|
||||
}
|
||||
return ['type'=>'html','data'=>'ok'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'result='.$_GET['result']];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
$signstr = 'result='.$_GET['result'].'&agent_id='.$_GET['agent_id'].'&jnet_bill_no='.$_GET['jnet_bill_no'].'&agent_bill_id='.$_GET['agent_bill_id'].'&pay_type='.$_GET['pay_type'].'&pay_amt='.$_GET['pay_amt'].'&remark='.$_GET['remark'].'&key='.$channel['appkey'];
|
||||
$sign = md5($signstr);
|
||||
|
||||
if($sign===$_GET["sign"]){
|
||||
if($_GET['result'] == '1'){
|
||||
$out_trade_no = $_GET['agent_bill_id'];
|
||||
$api_trade_no = $_GET['jnet_bill_no'];
|
||||
$money = $_GET['pay_amt'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO && round($money,2)==round($order['money'],2)) {
|
||||
processReturn($order, $api_trade_no, $_GET['pay_user']);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'result='.$_GET['result']];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'验证失败!'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel, $conf;
|
||||
if(empty($order))exit();
|
||||
|
||||
$apiurl = 'https://pay.heepay.com/API/Payment/PaymentRefund.aspx';
|
||||
if(round($order['refundmoney'],2) == round($order['money'],2)){
|
||||
$param = [
|
||||
'version' => '1',
|
||||
'agent_id' => $channel['appid'],
|
||||
'agent_bill_id' => $order['trade_no'],
|
||||
'notify_url' => $conf['localurl'].'pay/refundnotify/'.TRADE_NO.'/',
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
$signstr = 'agent_bill_id='.$param['agent_bill_id'].'&agent_id='.$param['agent_id'].'&key='.$channel['appsecret'].'¬ify_url='.$param['notify_url'].'&version='.$param['version'];
|
||||
}else{
|
||||
$refund_details = $order['trade_no'].','.$order['refundmoney'].','.$order['refund_no'];
|
||||
$param = [
|
||||
'version' => '1',
|
||||
'agent_id' => $channel['appid'],
|
||||
'refund_details' => $refund_details,
|
||||
'notify_url' => $conf['localurl'].'pay/refundnotify/'.TRADE_NO.'/',
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
$signstr = 'agent_id='.$param['agent_id'].'&key='.$channel['appsecret'].'¬ify_url='.$param['notify_url'].'&refund_details='.$param['refund_details'].'&version='.$param['version'];
|
||||
}
|
||||
|
||||
$param['sign'] = md5(strtolower($signstr));
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
|
||||
if(isset($result['ret_code']) && $result['ret_code']=='0000'){
|
||||
$result = ['code'=>0];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'返回内容解析失败'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//退款异步回调
|
||||
static public function refundnotify(){
|
||||
global $channel, $order;
|
||||
|
||||
$signstr = 'agent_id='.$_GET['agent_id'].'&hy_bill_no='.$_GET['hy_bill_no'].'&agent_bill_id='.$_GET['agent_bill_id'].'&agent_refund_bill_no='.$_GET['agent_refund_bill_no'].'&refund_amt='.$_GET['refund_amt'].'&refund_status='.$_GET['refund_status'].'&hy_deal_time='.$_GET['hy_deal_time'].'&key='.$channel['appsecret'];
|
||||
$sign = md5(strtolower($signstr));
|
||||
|
||||
if($sign===$_GET["sign"]){
|
||||
return ['type'=>'html','data'=>'ok'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
|
||||
static private function unicode_urldecode($url){
|
||||
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
|
||||
foreach ($a[1] as $uniord) {
|
||||
$dec = hexdec($uniord);
|
||||
$utf = '';
|
||||
if ($dec < 12) {
|
||||
$utf = chr($dec);
|
||||
} else if ($dec < 204) {
|
||||
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
} else {
|
||||
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
|
||||
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
}
|
||||
$url = str_replace('%u' . $uniord, $utf, $url);
|
||||
}
|
||||
return urldecode($url);
|
||||
}
|
||||
|
||||
static private function queryBankCardInfo($channel, $bank_card_no){
|
||||
$apiurl = 'https://pay.heepay.com/API/PayTransit/QueryBankCardInfo.aspx';
|
||||
$param = [
|
||||
'version' => '3',
|
||||
'agent_id' => $channel['appid'],
|
||||
'bank_card_no' => $bank_card_no,
|
||||
];
|
||||
$signstr = 'agent_id='.$param['agent_id'].'&bank_card_no='.$param['bank_card_no'].'&key='.$channel['transfer_key'].'&version='.$param['version'];
|
||||
$param['sign'] = md5(strtolower($signstr));
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
|
||||
if(isset($result['ret_code']) && $result['ret_code']=='0000'){
|
||||
$result = ['code'=>0, 'bank_card_no'=>$result['bank_card_no'], 'bank_name'=>$result['bank_name'], 'bank_type'=>$result['bank_type'], 'bank_card_type'=>$result['bank_card_type']];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'返回内容解析失败'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//转账
|
||||
static public function transfer($channel, $bizParam){
|
||||
global $conf;
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
if($bizParam['type'] == 'bank'){
|
||||
$bank_card_info = self::queryBankCardInfo($channel, $bizParam['payee_account']);
|
||||
if($bank_card_info['code']==-1) return ['code'=>-1, 'msg'=>'查询银行卡信息失败:'.$bank_card_info['msg']];
|
||||
|
||||
$detail_data = $bizParam['out_biz_no'].'^'.$bank_card_info['bank_type'].'^0^'.$bizParam['payee_account'].'^'.$bizParam['payee_real_name'].'^'.sprintf('%.2f' , $bizParam['money']).'^'.$bizParam['transfer_desc'].'^浙江省^杭州市^'.$bank_card_info['bank_name'];
|
||||
$apiurl = 'https://pay.heepay.com/API/PayTransit/PayTransferWithSmallAll.aspx';
|
||||
}else{
|
||||
$detail_data = $bizParam['out_biz_no'].'^0^'.$bizParam['payee_account'].'^'.$bizParam['payee_real_name'].'^'.sprintf('%.2f' , $bizParam['money']).'^'.$bizParam['transfer_desc'];
|
||||
$apiurl = 'https://pay.heepay.com/API/PayTransit/PayTransferThridWithSmall.aspx';
|
||||
if($bizParam['type'] == 'alipay') $transit_type = '4';
|
||||
elseif($bizParam['type'] == 'wxpay') $transit_type = '5';
|
||||
}
|
||||
$param = [
|
||||
'version' => '3',
|
||||
'agent_id' => $channel['appid'],
|
||||
'batch_no' => $bizParam['out_biz_no'],
|
||||
'batch_amt' => sprintf('%.2f' , $bizParam['money']),
|
||||
'batch_num' => '1',
|
||||
'detail_data' => $detail_data,
|
||||
'notify_url' => $conf['localurl'].'pay/transfernotify/'.$channel['id'].'/',
|
||||
'ext_param1' => '123',
|
||||
'transit_type' => $transit_type,
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
$signstr = 'agent_id='.$param['agent_id'].'&batch_amt='.$param['batch_amt'].'&batch_no='.$param['batch_no'].'&batch_num='.$param['batch_num'].'&detail_data='.$param['detail_data'].'&ext_param1='.$param['ext_param1'].'&key='.$channel['transfer_key'].'¬ify_url='.$param['notify_url'].'&version='.$param['version'];
|
||||
$param['sign'] = md5(strtolower($signstr));
|
||||
$param['detail_data'] = mb_convert_encoding($param['detail_data'],'GBK','UTF-8');
|
||||
$param['detail_data'] = self::tripleDesEncrypt($param['detail_data'], $channel['transfer_des_key']);
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
|
||||
if(isset($result['ret_code']) && $result['ret_code']=='0000'){
|
||||
return ['code'=>0, 'status'=>0, 'orderid'=>$bizParam['out_biz_no'], 'paydate'=>date('Y-m-d H:i:s')];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'返回内容解析失败'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//转账查询
|
||||
static public function transfer_query($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
$apiurl = 'https://pay.heepay.com/API/PayTransit/QueryTransfer.aspx';
|
||||
$param = [
|
||||
'version' => '3',
|
||||
'agent_id' => $channel['appid'],
|
||||
'batch_no' => $bizParam['out_biz_no'],
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
$signstr = 'agent_id='.$param['agent_id'].'&batch_no='.$param['batch_no'].'&key='.$channel['transfer_key'].'&version='.$param['version'];
|
||||
$param['sign'] = md5(strtolower($signstr));
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
|
||||
if(isset($result['ret_code']) && $result['ret_code']=='0000'){
|
||||
$status = 0;
|
||||
if($result['detail_data']){
|
||||
$detail_data = self::tripleDesDecrypt($result['detail_data'], $channel['transfer_des_key']);
|
||||
$detail_data = mb_convert_encoding($detail_data,'UTF-8','GBK');
|
||||
$row = explode('|', $detail_data)[0];
|
||||
$arr = explode('^', $row);
|
||||
if($arr[0] == $bizParam['out_biz_no']){
|
||||
$status = $arr[4] == 'S' ? 1 : 2;
|
||||
if($arr[4] == 'S') $paydate = $arr[5];
|
||||
else $errmsg = $arr[5];
|
||||
}
|
||||
}
|
||||
$result = ['code'=>0, 'status'=>$status, 'amount'=>$result['batch_amt'], 'errmsg'=>$errmsg, 'paydate'=>$paydate];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'返回内容解析失败'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//付款凭证
|
||||
static public function transfer_proof($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
$apiurl = 'https://www.heepay.com/API/PayTransit/PayTransferGetProof.aspx';
|
||||
$param = [
|
||||
'version' => '3',
|
||||
'agent_id' => $channel['appid'],
|
||||
'batch_no' => $bizParam['out_biz_no'],
|
||||
'sign_type' => 'MD5'
|
||||
];
|
||||
$signstr = 'agent_id='.$param['agent_id'].'&batch_no='.$param['batch_no'].'&key='.$channel['transfer_key'].'&version='.$param['version'];
|
||||
$param['sign'] = md5(strtolower($signstr));
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
libxml_disable_entity_loader(true);
|
||||
$result = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
|
||||
if(isset($result['ret_code']) && $result['ret_code']=='0000'){
|
||||
if($result['file_path']){
|
||||
$file_path = self::tripleDesDecrypt($result['file_path'], $channel['transfer_des_key']);
|
||||
$result = ['code'=>0, 'url'=>$file_path];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'未返回下载地址'];
|
||||
}
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$result["ret_msg"]?$result["ret_msg"]:'返回内容解析失败'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//余额查询
|
||||
static public function balance_query($channel, $bizParam){
|
||||
if(empty($channel))exit();
|
||||
|
||||
$apiurl = 'https://www.heepay.com/API/Merchant/QueryBank.aspx';
|
||||
$param = [
|
||||
'version' => '1',
|
||||
'agent_id' => $channel['appid'],
|
||||
];
|
||||
$signstr = 'version='.$param['version'].'&agent_id='.$param['agent_id'].'&key='.$channel['appkey'];
|
||||
$param['sign'] = md5($signstr);
|
||||
|
||||
$data = get_curl($apiurl, http_build_query($param));
|
||||
$data = mb_convert_encoding($data,'UTF-8','GBK');
|
||||
$status = substr($data, 0, 1);
|
||||
$ret = str_replace('|', '&', substr($data, 2));
|
||||
parse_str($ret, $result);
|
||||
|
||||
if($status == 'S'){
|
||||
$result = ['code'=>0, 'amount'=>round($result['can_Used_Amt']-$result['lock_Amt'], 2)];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>$ret];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//转账异步回调
|
||||
static public function transfernotify(){
|
||||
global $channel;
|
||||
|
||||
$signstr = 'ret_code='.$_POST['ret_code'].'&ret_msg='.$_POST['ret_msg'].'&agent_id='.$_POST['agent_id'].'&hy_bill_no='.$_POST['hy_bill_no'].'&status='.$_POST['status'].'&batch_no='.$_POST['batch_no'].'&batch_amt='.$_POST['batch_amt'].'&batch_num='.$_POST['batch_num'].'&detail_data='.$_POST['detail_data'].'&ext_param1='.$_POST['ext_param1'].'&key='.$channel['transfer_key'];
|
||||
$signstr = mb_convert_encoding($signstr,'UTF-8','GBK');
|
||||
$sign = md5(strtolower($signstr));
|
||||
|
||||
if($sign===$_POST["sign"]){
|
||||
if($_POST['status']==1){
|
||||
$detail_data = mb_convert_encoding($_POST['detail_data'],'UTF-8','GBK');
|
||||
$detail_data = explode('|', $detail_data);
|
||||
foreach($detail_data as $row){
|
||||
$arr = explode('^', $row);
|
||||
if(!$arr[0]) continue;
|
||||
$out_biz_no = $arr[0];
|
||||
$status = $arr[4] == 'S' ? 1 : 2;
|
||||
$errmsg = $arr[4] == 'F' ? $arr[5] : null;
|
||||
processTransfer($out_biz_no, $status, $errmsg);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'ok'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
|
||||
static private function tripleDesEncrypt($data, $key){
|
||||
$encrypted = openssl_encrypt($data, 'des-ede3', $key, OPENSSL_RAW_DATA);
|
||||
return strtoupper(bin2hex($encrypted));
|
||||
}
|
||||
static private function tripleDesDecrypt($data, $key){
|
||||
$data = hex2bin($data);
|
||||
return openssl_decrypt($data, 'des-ede3', $key, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
//进件通知
|
||||
static public function applynotify(){
|
||||
global $channel;
|
||||
|
||||
$json = file_get_contents("php://input");
|
||||
$data = json_decode($json,true);
|
||||
if(!$data) {
|
||||
return ['type'=>'json','data'=>['code'=>'10001', 'msg'=>'data error']];
|
||||
}
|
||||
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $result = $model->notify($data);
|
||||
|
||||
if(!$result) $result = ['code'=>'40004', 'msg'=>'error'];
|
||||
|
||||
return ['type'=>'json','data'=>$result];
|
||||
}
|
||||
|
||||
//提现通知
|
||||
static public function cashnotify(){
|
||||
global $channel;
|
||||
|
||||
$json = file_get_contents("php://input");
|
||||
$data = json_decode($json,true);
|
||||
if(!$data) {
|
||||
return ['type'=>'html','data'=>'data error'];
|
||||
}
|
||||
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $result = $model->cashnotify($data);
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,801 @@
|
||||
<?php
|
||||
|
||||
//http://xianshang-doc.helipay.com/server/?s=/api/extLogin/bySecretKey&username=pu_user&time=2025060415&token=b2ba7e9c5db86737d5e43fb5e46dabc9
|
||||
class helipay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'helipay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '合利宝', //支付插件显示名称
|
||||
'author' => '合利宝', //支付插件作者
|
||||
'link' => 'https://www.helipay.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','qqpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '商户编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '扫码产品-签名密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '扫码产品-加密密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'public_signkey' => [
|
||||
'name' => '公共产品-签名密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'public_enckey' => [
|
||||
'name' => '公共产品-加密密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'settle_signkey' => [
|
||||
'name' => '结算产品-MD5签名密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'settle_signkey2' => [
|
||||
'name' => '结算产品-RSA签名私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'accpay_signkey' => [
|
||||
'name' => '虚拟账户支付-签名密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'accpay_enckey' => [
|
||||
'name' => '虚拟账户支付-加密密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '子商户号',
|
||||
'type' => 'input',
|
||||
'note' => '留空为使用商户编号发起支付',
|
||||
],
|
||||
'reportid' => [
|
||||
'name' => '扫码支付-报备ID',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,多个报备ID可用,隔开',
|
||||
],
|
||||
'reportid2' => [
|
||||
'name' => '公众号支付-报备ID',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,多个报备ID可用,隔开',
|
||||
],
|
||||
'reportid3' => [
|
||||
'name' => 'H5支付-报备ID',
|
||||
'type' => 'input',
|
||||
'note' => '可留空,多个报备ID可用,隔开',
|
||||
],
|
||||
'split_pubkey' => [
|
||||
'name' => '分账产品-SM2平台公钥',
|
||||
'type' => 'textarea',
|
||||
'note' => 'hex格式',
|
||||
],
|
||||
'split_prikey' => [
|
||||
'name' => '分账产品-SM2商户私钥',
|
||||
'type' => 'textarea',
|
||||
'note' => 'hex格式',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_alipay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '生活号支付',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '扫码支付',
|
||||
'2' => '公众号/小程序支付',
|
||||
'3' => 'H5支付',
|
||||
],
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => true, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
const API_URL = 'http://pay.trx.helipay.com/trx/app/interface.action';
|
||||
|
||||
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('3',$channel['apptype']) || 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']=='qqpay'){
|
||||
return ['type'=>'jump','url'=>'/pay/qqpay/'.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('3',$channel['apptype']) || in_array('2',$channel['apptype']) && $channel['appwxa']>0)){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='qqpay'){
|
||||
return self::qqpay();
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
static private function make_sign($param, $key){
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign"){
|
||||
$signstr .= '&'.$v;
|
||||
}
|
||||
}
|
||||
$signstr .= '&'.$key;
|
||||
$sign = md5($signstr);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
static private function getReportId($reportid){
|
||||
global $order;
|
||||
if(!empty($order['param']) && is_numeric($order['param'])){
|
||||
return $order['param'];
|
||||
}
|
||||
if(strpos($reportid, ',')){
|
||||
$reportids = explode(',', $reportid);
|
||||
$reportid = $reportids[array_rand($reportids)];
|
||||
}
|
||||
global $DB;
|
||||
$DB->update('order', ['param'=>$reportid], ['trade_no'=>TRADE_NO]);
|
||||
return $reportid;
|
||||
}
|
||||
|
||||
//扫码支付预下单
|
||||
static private function qrcode($pay_type){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$params = [
|
||||
'P1_bizType' => 'AppPay',
|
||||
'P2_orderId' => TRADE_NO,
|
||||
'P3_customerNumber' => $channel['appid'],
|
||||
'P4_payType' => 'SCAN',
|
||||
'P5_orderAmount' => $order['realmoney'],
|
||||
'P6_currency' => 'CNY',
|
||||
'P7_authcode' => '1',
|
||||
'P8_appType' => $pay_type,
|
||||
'P9_notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'P10_successToUrl' => '',
|
||||
'P11_orderIp' => $clientip,
|
||||
'P12_goodsName' => $ordername,
|
||||
'P13_goodsDetail' => '',
|
||||
'P14_desc' => '',
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $params['P3_customerNumber'] = $channel['appmchid'];
|
||||
$params['sign'] = self::make_sign($params, $channel['appkey']);
|
||||
$params['signatureType'] = 'MD5';
|
||||
if(!empty($channel['reportid'])) $params['P15_subMerchantId'] = self::getReportId($channel['reportid']);
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($params) {
|
||||
$response = get_curl(self::API_URL, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result["rt2_retCode"]) && ($result["rt2_retCode"]=='0000' || $result["rt2_retCode"]=='0001')){
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['rt6_serialNumber']);
|
||||
return $result['rt8_qrcode'];
|
||||
}else{
|
||||
throw new Exception($result["rt3_retMsg"]?$result["rt3_retMsg"]:'返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//公众号支付预下单
|
||||
static private function publicpay($pay_type, $appid, $openid){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$params = [
|
||||
'P1_bizType' => 'AppPayPublic',
|
||||
'P2_orderId' => TRADE_NO,
|
||||
'P3_customerNumber' => $channel['appid'],
|
||||
'P4_payType' => 'PUBLIC',
|
||||
'P5_appid' => $appid,
|
||||
'P6_deviceInfo' => 'WEB',
|
||||
'P7_isRaw' => $openid == '1' ? '0' : '1',
|
||||
'P8_openid' => $openid,
|
||||
'P9_orderAmount' => $order['realmoney'],
|
||||
'P10_currency' => 'CNY',
|
||||
'P11_appType' => $pay_type,
|
||||
'P12_notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'P13_successToUrl' => $siteurl . 'pay/return/' . TRADE_NO . '/',
|
||||
'P14_orderIp' => $clientip,
|
||||
'P15_goodsName' => $ordername,
|
||||
'P16_goodsDetail' => '',
|
||||
'P17_limitCreditPay' => '',
|
||||
'P18_desc' => '',
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $params['P3_customerNumber'] = $channel['appmchid'];
|
||||
$params['sign'] = self::make_sign($params, $channel['appkey']);
|
||||
$params['signatureType'] = 'MD5';
|
||||
if(!empty($channel['reportid2'])) $params['P20_subMerchantId'] = self::getReportId($channel['reportid2']);
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($params) {
|
||||
$response = get_curl(self::API_URL, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result["rt2_retCode"]) && ($result["rt2_retCode"]=='0000' || $result["rt2_retCode"]=='0001')){
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['rt6_serialNumber']);
|
||||
return $result['rt10_payInfo'];
|
||||
}else{
|
||||
throw new Exception($result["rt3_retMsg"]?$result["rt3_retMsg"]:'返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//小程序支付预下单
|
||||
static private function appletpay($pay_type, $appid, $openid){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$params = [
|
||||
'P1_bizType' => 'AppPayApplet',
|
||||
'P2_orderId' => TRADE_NO,
|
||||
'P3_customerNumber' => $channel['appid'],
|
||||
'P4_payType' => 'APPLET',
|
||||
'P5_appid' => $appid,
|
||||
'P6_deviceInfo' => 'WEB',
|
||||
'P7_isRaw' => '1',
|
||||
'P8_openid' => $openid,
|
||||
'P9_orderAmount' => $order['realmoney'],
|
||||
'P10_currency' => 'CNY',
|
||||
'P11_appType' => $pay_type,
|
||||
'P12_notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'P13_successToUrl' => $siteurl . 'pay/return/' . TRADE_NO . '/',
|
||||
'P14_orderIp' => $clientip,
|
||||
'P15_goodsName' => $ordername,
|
||||
'P16_goodsDetail' => '',
|
||||
'P17_limitCreditPay' => '',
|
||||
'P18_desc' => '',
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $params['P3_customerNumber'] = $channel['appmchid'];
|
||||
$params['sign'] = self::make_sign($params, $channel['appkey']);
|
||||
$params['signatureType'] = 'MD5';
|
||||
if(!empty($channel['reportid2'])) $params['P20_subMerchantId'] = self::getReportId($channel['reportid2']);
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($params);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($params) {
|
||||
$response = get_curl(self::API_URL, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result["rt2_retCode"]) && ($result["rt2_retCode"]=='0000' || $result["rt2_retCode"]=='0001')){
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['rt6_serialNumber']);
|
||||
return $result['rt10_payInfo'];
|
||||
}else{
|
||||
throw new Exception($result["rt3_retMsg"]?$result["rt3_retMsg"]:'返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//H5支付预下单
|
||||
static private function h5pay($pay_type){
|
||||
global $siteurl, $conf, $channel, $order, $ordername, $clientip;
|
||||
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$params = [
|
||||
'P1_bizType' => 'AppPayH5WFT',
|
||||
'P2_orderId' => TRADE_NO,
|
||||
'P3_customerNumber' => $channel['appid'],
|
||||
'P4_orderAmount' => $order['realmoney'],
|
||||
'P5_currency' => 'CNY',
|
||||
'P6_orderIp' => $clientip,
|
||||
'P7_notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
|
||||
'P8_appPayType' => $pay_type,
|
||||
'P9_payType' => 'WAP',
|
||||
'P10_appName' => $conf['sitename'],
|
||||
'P11_deviceInfo' => 'AND_WAP',
|
||||
'P12_applicationId' => $siteurl,
|
||||
'P13_goodsName' => $ordername,
|
||||
'P14_goodsDetail' => '',
|
||||
'P15_desc' => '',
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $params['P3_customerNumber'] = $channel['appmchid'];
|
||||
$params['sign'] = self::make_sign($params, $channel['appkey']);
|
||||
$params['signatureType'] = 'MD5';
|
||||
if(!empty($channel['reportid3'])) $params['subMerchantId'] = self::getReportId($channel['reportid3']);
|
||||
$params['isRaw'] = '0';
|
||||
$params['nonRawMode'] = '1';
|
||||
$params['appId'] = 'wxd11af679e86cdf65';
|
||||
$params['successToUrl'] = $siteurl . 'pay/return/' . TRADE_NO . '/';
|
||||
if($order['profits'] > 0){
|
||||
self::handleProfits($param);
|
||||
}
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($params) {
|
||||
$response = get_curl(self::API_URL, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result["rt2_retCode"]) && ($result["rt2_retCode"]=='0000' || $result["rt2_retCode"]=='0001')){
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['rt6_serialNumber']);
|
||||
return $result['rt8_payInfo'];
|
||||
}else{
|
||||
throw new Exception($result["rt3_retMsg"]?$result["rt3_retMsg"]:'返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static private function handleProfits(&$param){
|
||||
global $order, $channel;
|
||||
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
|
||||
if($psreceiver && $psreceiver['mode'] == 0){
|
||||
$rules = [];
|
||||
foreach($psreceiver['info'] as $receiver){
|
||||
$psmoney = round(floor($order['realmoney'] * $receiver['rate']) / 100, 2);
|
||||
$rules[] = [
|
||||
'splitBillMerchantNo' => $receiver['account'],
|
||||
'splitBillAmount' => $psmoney,
|
||||
];
|
||||
}
|
||||
$param['splitBillType'] = 'FIXED_AMOUNT';
|
||||
$des = new DES3();
|
||||
$param['ruleJson'] = $des->encrypt2(json_encode($rules), $channel['appsecret']);
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
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::qrcode('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{
|
||||
$pay_info = self::publicpay('ALIPAY', '1', $user_id);
|
||||
$pay_info = json_decode($pay_info, true);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$pay_info['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'=>$pay_info['tradeNO'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
try{
|
||||
$code_url = self::qrcode('WXPAY');
|
||||
}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.'/';
|
||||
}elseif($channel['appwxa']>0){
|
||||
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::publicpay('WXPAY', '1', '1');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
$code_url = self::h5pay('WXPAY');
|
||||
}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, $ordername, $conf, $method;
|
||||
|
||||
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{
|
||||
$pay_info = self::publicpay('WXPAY', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$pay_info];
|
||||
}
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$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{
|
||||
$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{
|
||||
$pay_info = self::appletpay('WXPAY', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'微信支付下单失败 '.$ex->getMessage()]));
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($pay_info, true)]));
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if(in_array('3',$channel['apptype'])){
|
||||
try{
|
||||
$code_url = self::h5pay('WXPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
return ['type'=>'jump','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();
|
||||
}
|
||||
}
|
||||
|
||||
//QQ扫码支付
|
||||
static public function qqpay(){
|
||||
global $siteurl, $device, $mdevice;
|
||||
try{
|
||||
$code_url = self::qrcode('QQPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'QQ钱包支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if(checkmobbileqq() || $mdevice == 'qq'){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
} elseif((checkmobile() || $device == 'mobile') && !isset($_GET['qrcode'])){
|
||||
return ['type'=>'qrcode','page'=>'qqpay_wap','url'=>$code_url];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'qqpay_qrcode','url'=>$code_url];
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode('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;
|
||||
|
||||
$sign_param = [
|
||||
'rt1_customerNumber' => $_POST['rt1_customerNumber'],
|
||||
'rt2_orderId' => $_POST['rt2_orderId'],
|
||||
'rt3_systemSerial' => $_POST['rt3_systemSerial'],
|
||||
'rt4_status' => $_POST['rt4_status'],
|
||||
'rt5_orderAmount' => $_POST['rt5_orderAmount'],
|
||||
'rt6_currency' => $_POST['rt6_currency'],
|
||||
'rt7_timestamp' => $_POST['rt7_timestamp'],
|
||||
'rt8_desc' => $_POST['rt8_desc'],
|
||||
];
|
||||
$sign = self::make_sign($sign_param, $channel['appkey']);
|
||||
|
||||
if($sign === $_POST["sign"]){
|
||||
if($_POST['rt4_status'] == 'SUCCESS'){
|
||||
$out_trade_no = $_POST['rt2_orderId'];
|
||||
$api_trade_no = $_POST['rt3_systemSerial'];
|
||||
$money = $_POST['rt5_orderAmount'];
|
||||
$buyer = $_POST['rt19_subOpenId'];
|
||||
$bill_trade_no = $_POST['rt17_outTransactionOrderId'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
|
||||
}
|
||||
}
|
||||
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/DES3.class.php");
|
||||
|
||||
$params = [
|
||||
'P1_bizType' => 'AppPayRefund',
|
||||
'P2_orderId' => $order['trade_no'],
|
||||
'P3_customerNumber' => $channel['appid'],
|
||||
'P4_refundOrderId' => $order['refund_no'],
|
||||
'P5_amount' => $order['refundmoney'],
|
||||
'P6_callbackUrl' => '',
|
||||
];
|
||||
if(!empty($channel['appmchid'])) $params['P3_customerNumber'] = $channel['appmchid'];
|
||||
$params['sign'] = self::make_sign($params, $channel['appkey']);
|
||||
$params['signatureType'] = 'MD5';
|
||||
if($order['profits'] > 0){
|
||||
$psorder = \lib\ProfitSharing\CommUtil::getOrder($order['trade_no']);
|
||||
if($psorder && $psorder['rdata']){
|
||||
$leftmoney = (float)$order['refundmoney'];
|
||||
$rules = [];
|
||||
foreach($psorder['rdata'] as $receiver){
|
||||
$money = $receiver['money'] > $leftmoney ? $leftmoney : $receiver['money'];
|
||||
$rules[] = [
|
||||
'merchantNo' => $receiver['account'],
|
||||
'refundAmount' => round($money, 2),
|
||||
];
|
||||
$leftmoney -= $money;
|
||||
if($leftmoney <= 0) break;
|
||||
}
|
||||
if($leftmoney > 0){
|
||||
$rules[] = [
|
||||
'merchantNo' => $params['P3_customerNumber'],
|
||||
'refundAmount' => round($leftmoney, 2),
|
||||
];
|
||||
}
|
||||
$des = new DES3();
|
||||
$params['ruleJson'] = $des->encrypt2(json_encode($rules), $channel['appsecret']);
|
||||
}
|
||||
}
|
||||
|
||||
$response = get_curl(self::API_URL, http_build_query($params));
|
||||
$result = json_decode($response, true);
|
||||
if(isset($result["rt2_retCode"]) && ($result["rt2_retCode"]=='0000' || $result["rt2_retCode"]=='0001')){
|
||||
return ['code'=>0, 'trade_no'=>$result['rt7_serialNumber'], 'refund_fee'=>$result['rt8_amount']];
|
||||
} elseif(isset($result['rt3_retMsg'])) {
|
||||
return ['code'=>-1, 'msg'=>$result['rt3_retMsg']];
|
||||
}else{
|
||||
return ['code'=>-1, 'msg'=>'未知错误'];
|
||||
}
|
||||
}
|
||||
|
||||
//进件异步回调
|
||||
static public function applynotify(){
|
||||
global $channel, $order;
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
$sign = md5($arr['data'].'&'.$channel['public_signkey']);
|
||||
if($sign === $arr["sign"]){
|
||||
$des = new \DES3();
|
||||
$decrypted = $des->decrypt2($arr['data'], $channel['public_enckey']);
|
||||
if($decrypted){
|
||||
$data = json_decode($decrypted, true);
|
||||
$model = \lib\Applyments\CommUtil::getModel2($channel);
|
||||
if($model) $model->notify($data);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//结算异步回调
|
||||
static public function settlenotify(){
|
||||
global $channel, $order, $DB;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
unset($arr['rt3_retMsg']);
|
||||
$sign = self::make_sign($arr, $channel['settle_signkey']);
|
||||
if($sign === $arr["sign"]){
|
||||
$records = json_decode($arr['rt4_settleRecords'], true);
|
||||
if(!empty($records)){
|
||||
$srow = $records[0];
|
||||
$trade_row = $DB->find('helipay_settle', '*', ['orderno'=>$srow['orderId']]);
|
||||
if($trade_row && $trade_row['status'] != $srow['orderStatus']){
|
||||
$DB->update('helipay_settle', [
|
||||
'money'=>$srow['settlementAmount'],
|
||||
'fee'=>$srow['settleFee'],
|
||||
'status'=>$srow['orderStatus'],
|
||||
'reason'=>$srow['reason'],
|
||||
'finishtime'=>$srow['completeDate']?$srow['completeDate']:null,
|
||||
], ['id'=>$trade_row['id']]);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//转账异步回调
|
||||
static public function tradenotify(){
|
||||
global $channel, $order, $DB;
|
||||
|
||||
if(!$_POST) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
uksort($_POST, function ($a, $b) {
|
||||
if ($a == 'sign') return 1;
|
||||
if ($b == 'sign') return -1;
|
||||
$na = substr($a, 2, strpos($a, '_') - 2);
|
||||
$nb = substr($b, 2, strpos($b, '_') - 2);
|
||||
return $na - $nb;
|
||||
});
|
||||
$sign = self::make_sign($_POST, $channel['accpay_signkey']);
|
||||
if($sign === $_POST["sign"]){
|
||||
$trade_row = $DB->find('helipay_trade', '*', ['orderno'=>$_POST['rt7_orderId']]);
|
||||
if($trade_row && $trade_row['status'] != $_POST['rt10_orderStatus']){
|
||||
$DB->update('helipay_trade', [
|
||||
'status'=>$_POST['rt10_orderStatus'],
|
||||
'reason'=>$_POST['rt12_reason'],
|
||||
'endtime'=>date('Y-m-d H:i:s'),
|
||||
], ['id'=>$trade_row['id']]);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//投诉异步回调
|
||||
static public function complainnotify(){
|
||||
global $channel, $order;
|
||||
require(PAY_ROOT."inc/DES3.class.php");
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) return ['type'=>'html','data'=>'no data'];
|
||||
|
||||
$sign = md5($arr['data'].'&'.$channel['public_signkey']);
|
||||
if($sign === $arr["sign"]){
|
||||
$des = new \DES3();
|
||||
$decrypted = $des->decrypt2($arr['data'], $channel['public_enckey']);
|
||||
if($decrypted){
|
||||
$data = json_decode($decrypted, true);
|
||||
if($data['appPayType'] == 'ALIPAY') $channel['type'] = 1;
|
||||
else $channel['type'] = 2;
|
||||
$channel['appmchid'] = $data['merchantNo'];
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($data['complaintId']);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
class DES3 {
|
||||
|
||||
// 数据加密
|
||||
function encrypt($input, $key) {
|
||||
// 使用 OpenSSL 3DES-CBC 加密
|
||||
$key = str_pad($key, 24, '0'); // 确保密钥长度为 24 字节
|
||||
$iv = openssl_random_pseudo_bytes(8); // 3DES 的 IV 长度为 8 字节
|
||||
$input = $this->pkcs5_pad($input, 8); // 3DES 块大小为 8 字节
|
||||
$encrypted = openssl_encrypt(
|
||||
$input,
|
||||
'des-ede3-cbc', // 3DES-CBC 模式
|
||||
$key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$iv
|
||||
);
|
||||
return base64_encode($iv . $encrypted); // 返回 IV + 加密数据
|
||||
}
|
||||
|
||||
// 数据解密
|
||||
function decrypt($encrypted, $key) {
|
||||
$encrypted = base64_decode($encrypted);
|
||||
$key = str_pad($key, 24, '0'); // 确保密钥长度为 24 字节
|
||||
$iv = substr($encrypted, 0, 8); // 提取前 8 字节作为 IV
|
||||
$encrypted = substr($encrypted, 8); // 剩余部分为加密数据
|
||||
$decrypted = openssl_decrypt(
|
||||
$encrypted,
|
||||
'des-ede3-cbc', // 3DES-CBC 模式
|
||||
$key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$iv
|
||||
);
|
||||
return $this->pkcs5_unpad($decrypted); // 去除填充
|
||||
}
|
||||
|
||||
// PKCS5 填充
|
||||
function pkcs5_pad($text, $blocksize) {
|
||||
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||
return $text . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
// PKCS5 去除填充
|
||||
function pkcs5_unpad($text) {
|
||||
$pad = ord($text[strlen($text) - 1]);
|
||||
if ($pad > strlen($text)) {
|
||||
return false;
|
||||
}
|
||||
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
|
||||
return false;
|
||||
}
|
||||
return substr($text, 0, -1 * $pad);
|
||||
}
|
||||
|
||||
function encrypt2($input, $key)
|
||||
{
|
||||
$key = str_pad($key, 24, '0');
|
||||
$encrypted = openssl_encrypt($input, 'des-ede3', $key, OPENSSL_RAW_DATA);
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
|
||||
function decrypt2($encrypted, $key)
|
||||
{
|
||||
$key = str_pad($key, 24, '0');
|
||||
$encrypted = base64_decode($encrypted);
|
||||
$decrypted = openssl_decrypt($encrypted, 'des-ede3', $key, OPENSSL_RAW_DATA);
|
||||
return $decrypted;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
class HelipayClient
|
||||
{
|
||||
/** 签名类型 */
|
||||
const SIGN_TYPE = 'SM3WITHSM2';
|
||||
|
||||
/** 版本号 */
|
||||
const VERSION = '1.0';
|
||||
|
||||
/** SM4-CBC 固定IV (Base64),与Java demo保持一致,勿修改 */
|
||||
const SM4_IV_BASE64 = 'AQ4Zvt54xKn9QaW86ZzWdg==';
|
||||
|
||||
/** @var string 商户编号 */
|
||||
private $customerNumber;
|
||||
|
||||
/** @var string 合利宝平台SM2公钥(hex格式: 128位或04+128位) */
|
||||
private $platformPublicKey;
|
||||
|
||||
/** @var string 商户SM2私钥(hex格式: 64位) */
|
||||
private $merchantPrivateKey;
|
||||
|
||||
/** @var string 网关基础URL */
|
||||
private $gatewayUrl = 'https://pay.trx.helipay.com';
|
||||
|
||||
/**
|
||||
* @param string $customerNumber 商户编号
|
||||
* @param string $platformPublicKey 合利宝平台公钥(hex: 128位xy或130位04+xy)
|
||||
* @param string $merchantPrivateKey 商户私钥(hex: 64位)
|
||||
* @param string $gatewayUrl 网关URL,留空使用默认
|
||||
*/
|
||||
public function __construct($customerNumber, $platformPublicKey, $merchantPrivateKey)
|
||||
{
|
||||
if (!function_exists('gmp_init')) {
|
||||
throw new Exception('请先安装GMP扩展');
|
||||
}
|
||||
$this->customerNumber = $customerNumber;
|
||||
$this->platformPublicKey = $platformPublicKey;
|
||||
$this->merchantPrivateKey = $merchantPrivateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起国密API请求
|
||||
*
|
||||
* @param string $path 接口路径
|
||||
* @param array $data 业务数据
|
||||
* @return array
|
||||
*/
|
||||
public function execute($path, $data)
|
||||
{
|
||||
$params = $this->assemblyRequestParams($data);
|
||||
$url = $this->gatewayUrl . $path;
|
||||
$body = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$response = get_curl(
|
||||
$url,
|
||||
$body,
|
||||
0, 0, 0, 0, 0,
|
||||
['Content-Type: application/json; charset=utf-8']
|
||||
);
|
||||
|
||||
$result = json_decode($response, true);
|
||||
if ($result === null) {
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
|
||||
if (isset($result['code']) && $result['code'] == '0000') {
|
||||
if (!empty($result['sign']) && isset($result['data'])) {
|
||||
if (!$this->verifySign($result['data'], $result['sign'])) {
|
||||
throw new Exception('返回数据验签失败');
|
||||
}
|
||||
}
|
||||
return json_decode($result['data'], true);
|
||||
}
|
||||
|
||||
$msg = isset($result['message']) ? $result['message'] : '请求失败';
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装国密请求参数
|
||||
* 流程:SM4加密data -> SM2加密SM4密钥 -> SM2签名data密文
|
||||
*
|
||||
* @param array $data 业务数据
|
||||
* @return array
|
||||
*/
|
||||
public function assemblyRequestParams($data)
|
||||
{
|
||||
$dataJson = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 1. 生成16位SM4随机密钥
|
||||
$sm4Key = random(16);
|
||||
|
||||
// 2. 使用平台公钥加密SM4密钥
|
||||
$encryptionKey = $this->sm2Encrypt($sm4Key);
|
||||
|
||||
// 3. 使用SM4-CBC加密业务数据
|
||||
$encryptedData = $this->sm4Encrypt($dataJson, $sm4Key);
|
||||
|
||||
// 4. 使用商户私钥对data密文进行SM2签名
|
||||
$sign = $this->sm2Sign($encryptedData);
|
||||
|
||||
return [
|
||||
'data' => $encryptedData,
|
||||
'customerNumber' => $this->customerNumber,
|
||||
'encryptionKey' => $encryptionKey,
|
||||
'signType' => self::SIGN_TYPE,
|
||||
'sign' => $sign,
|
||||
'version' => self::VERSION,
|
||||
'timestamp' => (string)(microtime(true) * 1000),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验签(用于响应或回调)
|
||||
* @param mixed $data 待验签数据,数组会被json_encode
|
||||
* @param string $sign Base64签名
|
||||
* @return bool
|
||||
*/
|
||||
public function verifySign($data, $sign)
|
||||
{
|
||||
$dataStr = is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : (string)$data;
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64', true);
|
||||
return $sm2->verifySign($dataStr, $sign, $this->platformPublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* SM2加密(平台公钥)
|
||||
* @param string $plaintext 明文
|
||||
* @return string Base64密文
|
||||
*/
|
||||
private function sm2Encrypt($plaintext)
|
||||
{
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64');
|
||||
$hex = $sm2->doEncrypt($plaintext, $this->platformPublicKey);
|
||||
return base64_encode(hex2bin('04' . $hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* SM2签名(商户私钥)
|
||||
* @param string $data 待签名内容
|
||||
* @return string Base64签名,去除换行
|
||||
*/
|
||||
private function sm2Sign($data)
|
||||
{
|
||||
$sm2 = new Rtgm\sm\RtSm2('base64', true);
|
||||
$sign = $sm2->doSign($data, $this->merchantPrivateKey);
|
||||
return str_replace(["\r", "\n"], '', trim($sign));
|
||||
}
|
||||
|
||||
/**
|
||||
* SM4-CBC加密
|
||||
* @param string $plaintext 明文
|
||||
* @param string $key 16字节密钥
|
||||
* @return string Base64密文
|
||||
*/
|
||||
private function sm4Encrypt($plaintext, $key)
|
||||
{
|
||||
$iv = base64_decode(self::SM4_IV_BASE64);
|
||||
if (strlen($iv) !== 16) {
|
||||
throw new Exception('SM4 IV长度必须为16字节');
|
||||
}
|
||||
$sm4 = new Rtgm\sm\RtSm4($key);
|
||||
return $sm4->encrypt($plaintext, 'sm4-cbc', $iv, 'base64');
|
||||
}
|
||||
|
||||
/**
|
||||
* SM4-CBC解密(用于解析加密响应时使用)
|
||||
* @param string $ciphertext Base64密文
|
||||
* @param string $key 16字节密钥
|
||||
* @return string 明文
|
||||
*/
|
||||
public function sm4Decrypt($ciphertext, $key)
|
||||
{
|
||||
$iv = base64_decode(self::SM4_IV_BASE64);
|
||||
$sm4 = new Rtgm\sm\RtSm4($key);
|
||||
return $sm4->decrypt($ciphertext, 'sm4-cbc', $iv, 'base64');
|
||||
}
|
||||
}
|
||||
@@ -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']];
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCf21zJo95Uf9KKPLxagqzaT+L0
|
||||
fvsKuLG5cW5rzzHKwgfe8TkU2/ZnI2T0DowRvz7w98kfKBKxu0q/VV8QV21Ui/Ax
|
||||
OXdfrbQEQ/QVSXtF8NtCpaXqcSOdNQF9dDNpx/VrDpaarv6xp/4nfbeAlf+t6IdU
|
||||
kfo8Rz0Ne5fihpsSRwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -0,0 +1,6 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSU82GM2kEr/s9mvUmMvZjm/Yq
|
||||
15nWSHWl+rPemOP0/WGCu7xI96OnK94IA5YMMdmou27Nlk2M8+g29IEOBleAwZkI
|
||||
8MW9FO8ceFI+l0uyBuisd6GEKPLOB7CQb7XKkis/a9dLqxR+aGiWgkC7/E8dlNUm
|
||||
JUV53TGrgZ2yiVeyVQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -0,0 +1,709 @@
|
||||
<?php
|
||||
/***
|
||||
* https://www.yuque.com/chenyanfei-sjuaz/uhng8q
|
||||
*/
|
||||
|
||||
class hnapay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'hnapay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '新生支付', //支付插件显示名称
|
||||
'author' => '新生支付', //支付插件作者
|
||||
'link' => 'https://www.hnapay.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'transtypes' => ['bank'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '商户ID',
|
||||
'type' => 'input',
|
||||
'note' => '新生用户ID',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '新生公钥(新收款密钥)',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '商户私钥(新收款密钥)',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '报备编号',
|
||||
'type' => 'input',
|
||||
'note' => '仅支付宝&微信需要填写',
|
||||
],
|
||||
'appswitch' => [
|
||||
'name' => '接口类型',
|
||||
'type' => 'select',
|
||||
'options' => [0 => '公众号/生活号支付', 1 => '支付宝H5', 2 => '扫码支付'],
|
||||
],
|
||||
'wxmchid' => [
|
||||
'name' => '微信服务商商户号',
|
||||
'type' => 'input',
|
||||
'note' => '用于获取微信支付投诉',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '需要使用RSA密钥!<br/>如使用扫码支付,需将<b>收款密钥</b>中的<b>商户私钥</b>上传到/plugins/hnapay/cert/mch.key(或cert/商户ID/mch.key)<br/>如使用付款功能,需将<b>付款密钥</b>中的<b>商户私钥</b>上传到/plugins/hnapay/cert/pay.key(或cert/商户ID/pay.key)', //支付密钥填写说明
|
||||
'bindwxmp' => true, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
if($channel['appswitch']==0 && checkalipay()){
|
||||
return ['type' => 'jump', 'url' => '/pay/alipayjs/' . TRADE_NO . '/?d=1'];
|
||||
}elseif($channel['appswitch']==1 && checkalipay()){
|
||||
return ['type' => 'jump', 'url' => '/pay/alipayh5/' . TRADE_NO . '/'];
|
||||
}else{
|
||||
return ['type' => 'jump', 'url' => '/pay/alipay/' . TRADE_NO . '/'];
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($channel['appswitch']==0 && checkwechat()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($channel['appswitch']==0 && checkmobile()){
|
||||
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
|
||||
}else{
|
||||
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
if($channel['appswitch']==1){
|
||||
return ['type'=>'jump','url'=>'/pay/quickpay/'.TRADE_NO.'/'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>'/pay/bank/'.TRADE_NO.'/'];
|
||||
}
|
||||
}
|
||||
|
||||
static public function mapi(){
|
||||
global $siteurl, $channel, $order, $conf, $device, $mdevice, $method;
|
||||
|
||||
if($channel['appswitch']==0 && $method=='jsapi'){
|
||||
if($order['typename']=='alipay'){
|
||||
return self::alipayjs();
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
return self::wxjspay();
|
||||
}
|
||||
}elseif($order['typename']=='alipay'){
|
||||
if($channel['appswitch']==0 && $mdevice=='alipay'){
|
||||
return ['type' => 'jump', 'url' => '/pay/alipayjs/' . TRADE_NO . '/?d=1'];
|
||||
}elseif($channel['appswitch']==1 && $mdevice=='alipay'){
|
||||
return ['type' => 'jump', 'url' => '/pay/alipayh5/' . TRADE_NO . '/'];
|
||||
}else{
|
||||
return self::alipay();
|
||||
}
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($channel['appswitch']==0 && $mdevice=='wechat'){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($channel['appswitch']==0 && $device=='mobile'){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
if($channel['appswitch']==1){
|
||||
return self::quickpay();
|
||||
}
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//二维码下单通用
|
||||
static private function qrcode($orgCode){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$param = [
|
||||
'merOrderNum' => TRADE_NO,
|
||||
'tranAmt' => strval($order['realmoney']*100),
|
||||
'submitTime' => substr(TRADE_NO, 0, 14),
|
||||
'orgCode' => $orgCode,
|
||||
'goodsName' => $ordername,
|
||||
'tranIP' => $clientip,
|
||||
'notifyUrl' => $conf['localurl'].'pay/notifys/'.TRADE_NO.'/',
|
||||
'weChatMchId' => $channel['appmchid'],
|
||||
];
|
||||
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 1);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($pay, $param) {
|
||||
$result = $pay->scanPay($param);
|
||||
return $result['qrCodeUrl'];
|
||||
});
|
||||
}
|
||||
|
||||
//JSAPI下单通用
|
||||
static private function jsapi($orgCode, $appId, $openId){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$param = [
|
||||
'tranAmt' => $order['realmoney'],
|
||||
'orgCode' => $orgCode,
|
||||
'notifyServerUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'merUserIp' => $clientip,
|
||||
'goodsInfo' => $ordername,
|
||||
'orderSubject' => $ordername,
|
||||
'merchantId' => $channel['appmchid'],
|
||||
];
|
||||
if($orgCode == 'WECHATPAY'){
|
||||
$param += [
|
||||
'appId' => $appId,
|
||||
'openId' => $openId,
|
||||
];
|
||||
}elseif($orgCode == 'ALIPAY'){
|
||||
$param += [
|
||||
'aliAppId' => $appId,
|
||||
'buyerId' => $openId,
|
||||
];
|
||||
}
|
||||
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($pay, $param) {
|
||||
$result = $pay->jsapiPay($param, TRADE_NO);
|
||||
return $result['payInfo'];
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $siteurl;
|
||||
if($channel['appswitch']==2){
|
||||
try{
|
||||
$code_url = self::qrcode('ALIPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}elseif($channel['appswitch']==1){
|
||||
if(checkmobile()){
|
||||
return self::alipayh5();
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/alipayh5/'.TRADE_NO.'/?d=1';
|
||||
}
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
}
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//支付宝JS支付
|
||||
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;
|
||||
|
||||
$achannel = \lib\Channel::get($conf['alipay_web_login']);
|
||||
|
||||
try{
|
||||
$retData = self::jsapi('ALIPAY', $achannel['appid'], $user_id);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>$retData['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'=>$retData['tradeNO'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
|
||||
//支付宝H5支付
|
||||
static public function alipayh5(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if($_GET['d']=='1'){
|
||||
$front_url=$siteurl.'pay/ok/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$front_url=$siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
}
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
$param = [
|
||||
'tranAmt' => $order['realmoney'],
|
||||
'payType' => 'HnaZFB',
|
||||
'exPayMode'=>'',
|
||||
'cardNo'=>'',
|
||||
'holderName'=>'',
|
||||
'identityCode'=>'',
|
||||
'merUserId'=>'',
|
||||
'orderExpireTime'=>'10',
|
||||
'frontUrl' => $front_url,
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'riskExpand'=>'',
|
||||
'goodsInfo'=>'',
|
||||
'orderSubject' => $ordername,
|
||||
'orderDesc'=>'',
|
||||
'merchantId' => json_encode(['02'=>$channel['appmchid']]),
|
||||
'bizProtocolNo'=>'',
|
||||
'payProtocolNo'=>'',
|
||||
'merUserIp' => $clientip,
|
||||
'payLimit'=>'',
|
||||
];
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
$html = $pay->h5Pay($param, TRADE_NO);
|
||||
return ['type'=>'html','data'=>$html];
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $siteurl, $device, $mdevice;
|
||||
if($channel['appswitch']==2){
|
||||
try {
|
||||
$code_url = self::qrcode('WECHATPAY');
|
||||
} catch (Exception $ex) {
|
||||
return ['type' => 'error', 'msg' => '微信支付下单失败!' . $ex->getMessage()];
|
||||
}
|
||||
}else{
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
}
|
||||
if($mdevice == 'wechat' || checkwechat()){
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
} elseif ($device == 'mobile' || 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, $method, $conf, $clientip;
|
||||
|
||||
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{
|
||||
$pay_info = self::jsapi('WECHATPAY', $wxinfo['appid'], $openid);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败 '.$ex->getMessage()];
|
||||
}
|
||||
if($method == 'jsapi'){
|
||||
return ['type'=>'jsapi','data'=>json_encode($pay_info)];
|
||||
}
|
||||
|
||||
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{
|
||||
$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{
|
||||
$pay_info = self::jsapi('WECHATPAY', $wxinfo['appid'], $openid);
|
||||
}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];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::qrcode('UNIONPAY');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'银联云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
|
||||
}
|
||||
|
||||
//快捷支付
|
||||
static public function quickpay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $cdnpublic, $DB;
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
|
||||
if(isset($_POST['action'])){
|
||||
switch($_POST['action']){
|
||||
case 'query_card':
|
||||
$cardno = trim($_POST['cardno']);
|
||||
if(empty($cardno)) exit(json_encode(['code'=>-1, 'msg'=>'银行卡号不能为空']));
|
||||
try{
|
||||
$result = getBankCardInfo($cardno);
|
||||
exit(json_encode(['code'=>0, 'data'=>$result]));
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>$ex->getMessage()]));
|
||||
}
|
||||
break;
|
||||
case 'request':
|
||||
$phone = trim($_POST['phone']);
|
||||
$cardno = trim($_POST['cardno']);
|
||||
$cardtype = trim($_POST['cardtype']);
|
||||
$name = trim($_POST['name']);
|
||||
$idcard = trim($_POST['idcard']);
|
||||
$expiry = str_replace('/', '', trim($_POST['expiry']));
|
||||
$cvv = trim($_POST['cvv']);
|
||||
if(empty($phone) || empty($cardno) || empty($name) || empty($idcard)){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'参数不能为空']));
|
||||
}
|
||||
if(!is_idcard($idcard)) exit(json_encode(['code'=>-1, 'msg'=>'身份证号码不正确']));
|
||||
|
||||
$DB->update('order', ['mobile'=>$phone, 'buyer'=>$cardno], ['trade_no'=>TRADE_NO]);
|
||||
$black = $DB->find('blacklist', '*', ['type'=>0, 'content'=>$phone], null, 1);
|
||||
if($black) exit(json_encode(['code'=>-1, 'msg'=>'系统异常无法完成付款']));
|
||||
$black = $DB->find('blacklist', '*', ['type'=>0, 'content'=>$cardno], null, 1);
|
||||
if($black) exit(json_encode(['code'=>-1, 'msg'=>'系统异常无法完成付款']));
|
||||
|
||||
$param = [
|
||||
'tranAmt' => $order['realmoney'],
|
||||
'payType' => '2',
|
||||
'cardNo' => $cardno,
|
||||
'holderName' => $name,
|
||||
'cardAvailableDate' => $expiry,
|
||||
'cvv2' => $cvv,
|
||||
'mobileNo' => $phone,
|
||||
'identityType' => '01',
|
||||
'identityCode' => $idcard,
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'merUserId' => $phone,
|
||||
'merUserIp' => $clientip,
|
||||
'goodsInfo' => $ordername,
|
||||
];
|
||||
try{
|
||||
$result = $pay->quickPayRequest($param, TRADE_NO);
|
||||
exit(json_encode(['code'=>0, 'token'=>$result['hnapayOrderId']]));
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'快捷支付下单失败!'.$ex->getMessage()]));
|
||||
}
|
||||
break;
|
||||
case 'confirm':
|
||||
$token = trim($_POST['token']);
|
||||
$smscode = trim($_POST['smscode']);
|
||||
if(empty($token) || empty($smscode)) exit(json_encode(['code'=>-1, 'msg'=>'参数不能为空']));
|
||||
$paymentTerminalInfo = (checkmobile() ? '02|' : '01|') . substr(md5($_POST['phone']), 0, 10);
|
||||
$param = [
|
||||
'hnapayOrderId' => $token,
|
||||
'smsCode' => $smscode,
|
||||
'merUserIp' => $clientip,
|
||||
'paymentTerminalInfo' => $paymentTerminalInfo,
|
||||
'receiverTerminalInfo' => '01|00001|CN|110000',
|
||||
'deviceInfo' => $clientip.'||||||',
|
||||
];
|
||||
try{
|
||||
$result = $pay->quickPayConfirm($param, TRADE_NO);
|
||||
$DB->update('order', ['ext'=>json_encode(['bizProtocolNo'=>$result['bizProtocolNo'], 'payProtocolNo'=>$result['payProtocolNo']])], ['trade_no'=>TRADE_NO]);
|
||||
exit(json_encode(['code'=>0, 'backurl'=>'/pay/return/'.TRADE_NO.'/']));
|
||||
}catch(Exception $ex){
|
||||
exit(json_encode(['code'=>-1, 'msg'=>'快捷支付下单失败!'.$ex->getMessage()]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
include PAY_ROOT.'inc/pay.page.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function agreement(){
|
||||
global $siteurl, $cdnpublic;
|
||||
include PAY_ROOT.'inc/agreement.page.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
if(!isset($_POST)) return ['type'=>'html','data'=>'no_data'];
|
||||
//file_put_contents('logs.txt' , http_build_query($_POST));
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
|
||||
if($_POST['tranCode'] == 'MUP11'){
|
||||
$verify_result = $pay->alipayh5Verify($_POST);
|
||||
}elseif($_POST['tranCode'] == 'EXP13'){
|
||||
$verify_result = $pay->quickpayVerify($_POST);
|
||||
}else{
|
||||
$verify_result = $pay->jsapiVerify($_POST);
|
||||
}
|
||||
if($verify_result){
|
||||
if($_POST['resultCode'] == '0000'){
|
||||
$out_trade_no = $_POST['merOrderId'];
|
||||
$trade_no = $_POST['hnapayOrderId'];
|
||||
$bill_mch_trade_no = $_POST['bankOrderId'];
|
||||
$bill_trade_no = $_POST['realBankOrderId'];
|
||||
if($order['type'] == 1 && substr($bill_trade_no, 0, 4) != date('Y') && substr($bill_trade_no, 2, 4) == date('Y')) $bill_trade_no = substr($bill_trade_no, 2);
|
||||
$money = $_POST['tranAmt'];
|
||||
$buyer = $_POST['userId'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'sign_error'];
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调(扫码支付)
|
||||
static public function notifys(){
|
||||
global $channel, $order;
|
||||
|
||||
//file_put_contents('logs.txt' , http_build_query($_POST));
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 1);
|
||||
|
||||
if($pay->scanVerify($_POST)){
|
||||
if($_POST['respCode'] == '0000'){
|
||||
$out_trade_no = $_POST['merOrderNum'];
|
||||
$trade_no = $_POST['hnapayOrderId'];
|
||||
$bill_mch_trade_no = $_POST['bankOrderId'];
|
||||
$bill_trade_no = $_POST['realBankOrderId'];
|
||||
if($order['type'] == 1 && substr($bill_trade_no, 0, 4) != date('Y') && substr($bill_trade_no, 2, 4) == date('Y')) $bill_trade_no = substr($bill_trade_no, 2);
|
||||
$money = $_POST['tranAmt'];
|
||||
$buyer = $_POST['userId'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'sign_error'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
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, $conf;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
|
||||
$param = [
|
||||
'orgMerOrderId' => $order['trade_no'],
|
||||
'orgSubmitTime' => substr($order['trade_no'], 0, 14),
|
||||
'orderAmt' => $order['realmoney'],
|
||||
'refundOrderAmt' => $order['refundmoney'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/refundnotify/'.TRADE_NO.'/',
|
||||
];
|
||||
|
||||
try{
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
$result = $pay->refund($param, $order['refund_no']);
|
||||
return ['code'=>0, 'trade_no'=>$result['orgMerOrderId'], 'refund_fee'=>$result['refundAmt']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//退款异步回调
|
||||
static public function refundnotify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
if($pay->jsapiVerify($_POST)){
|
||||
if($_POST['resultCode'] == '0000'){
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'status_error'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'sign_error'];
|
||||
}
|
||||
}
|
||||
|
||||
//转账
|
||||
static public function transfer($channel, $bizParam){
|
||||
global $conf, $clientip;
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require(PLUGIN_ROOT.'hnapay/inc/HnaPayApi.class.php');
|
||||
|
||||
$param = [
|
||||
'tranAmt' => $bizParam['money'],
|
||||
'payType' => '1',
|
||||
'auditFlag' => '0',
|
||||
'payeeName' => $bizParam['payee_real_name'],
|
||||
'payeeAccount' => $bizParam['payee_account'],
|
||||
'note' => '',
|
||||
'remark' => $bizParam['transfer_desc'],
|
||||
'bankCode' => '',
|
||||
'payeeType' => '1',
|
||||
'notifyUrl' => $conf['localurl'].'pay/transfernotify/'.$channel['id'].'/',
|
||||
'paymentTerminalInfo' => '01|A10001',
|
||||
'deviceInfo' => $clientip,
|
||||
];
|
||||
|
||||
try{
|
||||
$client = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 2);
|
||||
$result = $client->transfer($param, $bizParam['out_biz_no']);
|
||||
return ['code'=>0, 'status'=>0, 'orderid'=>$result['hnapayOrderId'], 'paydate'=>date('Y-m-d H:i:s')];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//转账查询
|
||||
static public function transfer_query($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require(PLUGIN_ROOT.'hnapay/inc/HnaPayApi.class.php');
|
||||
|
||||
try{
|
||||
$client = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 2);
|
||||
$result = $client->transferQuery($bizParam['out_biz_no']);
|
||||
if($result['orderStatus'] == '1'){
|
||||
$status = 1;
|
||||
}elseif($result['orderStatus'] == '0' || $result['orderStatus'] == '3'){
|
||||
$status = 0;
|
||||
}else{
|
||||
$status = 2;
|
||||
}
|
||||
if($result['orderFailedCode']){
|
||||
$errmsg = '['.$result['orderFailedCode'].']'.$result['orderFailedMsg'];
|
||||
}
|
||||
return ['code'=>0, 'status'=>$status, 'amount'=>$result['tranAmt'], 'paydate'=>date('Y-m-d H:i:s', strtotime($result['successTime'])), 'errmsg'=>$errmsg];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//电子回单
|
||||
static public function transfer_proof($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
require(PLUGIN_ROOT.'hnapay/inc/HnaPayApi.class.php');
|
||||
|
||||
try{
|
||||
$client = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 2);
|
||||
$result = $client->transferProof($bizParam['orderid']);
|
||||
$filename = basename($bizParam['orderid']).'.png';
|
||||
file_put_contents(ROOT.'assets/uploads/'.$filename, base64_decode($result['payCertificate']));
|
||||
$image = '/assets/uploads/'.$filename;
|
||||
return ['code'=>0, 'msg'=>'电子回单生成成功!', 'download_url'=>$image];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//余额查询
|
||||
static public function balance_query($channel, $bizParam){
|
||||
if(empty($channel))exit();
|
||||
|
||||
require(PLUGIN_ROOT.'hnapay/inc/HnaPayApi.class.php');
|
||||
|
||||
try{
|
||||
$client = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret']);
|
||||
$result = $client->queryBalance();
|
||||
return ['code'=>0, 'amount'=>$result['avaBalance'], 'msg'=>'当前账户可用余额:'.$result['avaBalance'].' 元,待结转金额:'.$result['pendAmt']];
|
||||
}catch(Exception $ex){
|
||||
return ['code'=>-1, 'msg'=>$ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//付款异步回调
|
||||
static public function transfernotify(){
|
||||
global $channel;
|
||||
|
||||
require(PAY_ROOT.'inc/HnaPayApi.class.php');
|
||||
$pay = new HnaPayApi($channel['appid'], $channel['appkey'], $channel['appsecret'], 2);
|
||||
if($pay->transferVerify($_POST)){
|
||||
if($_POST['resultCode'] == '0000'){
|
||||
$status = 1;
|
||||
}else{
|
||||
$status = 2;
|
||||
}
|
||||
if($_POST['errorMsg']){
|
||||
$errmsg = '['.$_POST['errorCode'].']'.$_POST['errorMsg'];
|
||||
}
|
||||
processTransfer($_POST['merOrderId'], $status, $errmsg);
|
||||
return ['type'=>'html','data'=>'200'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'sign_error'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,568 @@
|
||||
<?php
|
||||
/**
|
||||
* 新生支付API
|
||||
* @see https://www.yuque.com/chenyanfei-sjuaz/uhng8q
|
||||
* @see https://www.yuque.com/chenyanfei-sjuaz/kbvzit
|
||||
*/
|
||||
class HnaPayApi
|
||||
{
|
||||
protected $mer_id;
|
||||
protected $sign_type = '1'; //1:RSA 3:国密交易证书 4:国密密钥
|
||||
protected $charset = '1';
|
||||
private $platform_public_key;
|
||||
private $merchant_private_key;
|
||||
|
||||
public function __construct($mer_id, $platform_public_key, $merchant_private_key, $key_type = 0)
|
||||
{
|
||||
$this->mer_id = $mer_id;
|
||||
if($key_type == 2){
|
||||
$platform_public_key_path = PLUGIN_ROOT.'hnapay/cert/hnapaypay.pem';
|
||||
if(file_exists(PLUGIN_ROOT.'hnapay/cert/'.$mer_id.'/pay.key')){
|
||||
$merchant_private_key_path = PLUGIN_ROOT.'hnapay/cert/'.$mer_id.'/pay.key';
|
||||
}else{
|
||||
$merchant_private_key_path = PLUGIN_ROOT.'hnapay/cert/pay.key';
|
||||
}
|
||||
if(!file_exists($merchant_private_key_path)) {
|
||||
throw new Exception('商户私钥文件pay.key不存在');
|
||||
}
|
||||
$this->platform_public_key = $this->loadPublicKeyFile($platform_public_key_path);
|
||||
$this->merchant_private_key = $this->loadPrivateKeyFile($merchant_private_key_path);
|
||||
}elseif($key_type == 1){
|
||||
$platform_public_key_path = PLUGIN_ROOT.'hnapay/cert/hnapay.pem';
|
||||
if(file_exists(PLUGIN_ROOT.'hnapay/cert/'.$mer_id.'/mch.key')){
|
||||
$merchant_private_key_path = PLUGIN_ROOT.'hnapay/cert/'.$mer_id.'/mch.key';
|
||||
}else{
|
||||
$merchant_private_key_path = PLUGIN_ROOT.'hnapay/cert/mch.key';
|
||||
}
|
||||
if(!file_exists($merchant_private_key_path)) {
|
||||
throw new Exception('商户私钥文件mch.key不存在');
|
||||
}
|
||||
$this->platform_public_key = $this->loadPublicKeyFile($platform_public_key_path);
|
||||
$this->merchant_private_key = $this->loadPrivateKeyFile($merchant_private_key_path);
|
||||
}else{
|
||||
$this->platform_public_key = $this->loadPublicKey($platform_public_key);
|
||||
$this->merchant_private_key = $this->loadPrivateKey($merchant_private_key);
|
||||
}
|
||||
}
|
||||
|
||||
//扫码支付
|
||||
public function scanPay($params){
|
||||
$apiurl = 'https://gateway.hnapay.com/website/scanPay.do';
|
||||
$publicParams = [
|
||||
'tranCode' => 'WS01',
|
||||
'version' => '2.1',
|
||||
'merId' => $this->mer_id,
|
||||
'payType' => 'QRCODE_B2C',
|
||||
'charset' => $this->charset,
|
||||
'signType' => $this->sign_type
|
||||
];
|
||||
$params = array_merge($publicParams, $params);
|
||||
|
||||
$sign_order = ['tranCode', 'version', 'merId', 'submitTime', 'merOrderNum', 'tranAmt', 'payType', 'orgCode', 'notifyUrl', 'charset', 'signType'];
|
||||
$params['signMsg'] = $this->generateSignOld($params, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($params));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
if(!empty($arr['signMsg'])){
|
||||
$sign_order = ['tranCode', 'version', 'merId', 'merOrderNum', 'tranAmt', 'submitTime', 'qrCodeUrl', 'hnapayOrderId', 'resultCode', 'charset', 'signType'];
|
||||
if(!$this->verifySignOld($arr, $sign_order, $arr['signMsg'])){
|
||||
throw new Exception('返回结果验签失败');
|
||||
}
|
||||
}
|
||||
$arr['qrCodeUrl'] = getSubstr($arr['qrCodeUrl'], 'qrContent=', '&sign=');
|
||||
return $arr;
|
||||
}elseif(isset($arr['resultCode'])){
|
||||
throw new Exception('['.$arr['resultCode'].']'.$arr['msgExt']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//扫码支付查单
|
||||
public function scanQuery($trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/website/queryOrderResult.htm';
|
||||
$param = [
|
||||
'version' => "2.8",
|
||||
'serialID' => date("YmdHis").rand(11111,99999),
|
||||
'mode' => '1',
|
||||
'type' => "1",
|
||||
'orderID' => $trade_no,
|
||||
'partnerID' => $this->mer_id,
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$sign_order = ['version', 'serialID', 'mode', 'type', 'orderID', 'beginTime', 'endTime', 'partnerID', 'remark', 'charset', 'signType'];
|
||||
$signStr = '';
|
||||
foreach($sign_order as $key){
|
||||
$signStr .= $key.'='.$param[$key].'&';
|
||||
}
|
||||
$signStr = substr($signStr, 0, -1);
|
||||
$param['signMsg'] = $this->rsaPrivateSign($signStr, true);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = [];
|
||||
parse_str($response, $arr);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['resultCode'])){
|
||||
throw new Exception('['.$arr['resultCode'].']'.$arr['ErrorCode']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//扫码支付回调验签
|
||||
public function scanVerify($param){
|
||||
if(!$param['signMsg']) return false;
|
||||
$sign_order = ['tranCode', 'version', 'merId', 'merOrderNum', 'tranAmt', 'submitTime', 'hnapayOrderId', 'tranFinishTime', 'respCode', 'charset', 'signType'];
|
||||
return $this->verifySignOld($param, $sign_order, $param['signMsg']);
|
||||
}
|
||||
|
||||
//JSAPI支付
|
||||
public function jsapiPay($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/ita/inCharge.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "ITA10",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => substr($trade_no, 0, 14),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
//print_r($arr);exit;
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
if(!empty($arr['signValue'])){
|
||||
$sign_order = ['version', 'tranCode', 'merOrderId', 'merId', 'charset', 'signType', 'resultCode', 'errorCode', 'hnapayOrderId', 'payInfo'];
|
||||
if(!$this->verifySign($arr, $sign_order, $arr['signValue'])){
|
||||
throw new Exception('返回结果验签失败');
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//JSAPI支付与H5支付查单
|
||||
public function jsapiQuery($trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/exp/query.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "EXP08",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => substr($trade_no, 0, 8),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//JSAPI回调验签
|
||||
public function jsapiVerify($param){
|
||||
if(!$param['signValue']) return false;
|
||||
$sign_order = ['version', 'tranCode', 'merOrderId', 'merId', 'merAttach', 'charset', 'signType', 'hnapayOrderId', 'resultCode', 'tranAmt', 'submitTime', 'tranFinishTime'];
|
||||
return $this->verifySign($param, $sign_order, $param['signValue']);
|
||||
}
|
||||
|
||||
//支付宝H5支付
|
||||
public function h5Pay($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/multipay/h5.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "MUP11",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => substr($trade_no, 0, 14),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'signType', 'charset', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$html = "<form id='alipaysubmit' name='alipaysubmit' action='{$apiurl}' method='POST'>";
|
||||
foreach ($param as $key => $value) {
|
||||
$value = htmlentities($value, ENT_QUOTES | ENT_HTML5);
|
||||
$html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
|
||||
}
|
||||
$html .= "<input type='submit' value='ok' style='display:none;'></form>";
|
||||
$html .= "<script>document.forms['alipaysubmit'].submit();</script>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
//支付宝H5回调验签
|
||||
public function alipayh5Verify($param){
|
||||
if(!$param['signValue']) return false;
|
||||
$sign_order = ['version', 'tranCode', 'merOrderId', 'merId', 'charset', 'signType', 'resultCode', 'hnapayOrderId'];
|
||||
return $this->verifySign($param, $sign_order, $param['signValue']);
|
||||
}
|
||||
|
||||
//退款
|
||||
public function refund($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/exp/refund.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "EXP09",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => date('YmdHis'),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//付款到银行
|
||||
public function transfer($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/website/singlePay.do';
|
||||
$param = [
|
||||
'version' => "2.1",
|
||||
'tranCode' => "SGP01",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => date('YmdHis'),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext', 'signType'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//商户账户余额查询
|
||||
public function transferQuery($orderid){
|
||||
$apiurl = 'https://gateway.hnapay.com/website/singlePayQuery.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "SGP02",
|
||||
'merOrderId' => $orderid,
|
||||
'submitTime' => substr($orderid, 0, 14),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//付款凭证下载
|
||||
public function transferProof($hnapayOrderId){
|
||||
$trade_no = date('YmdHis').rand(1000, 9999);
|
||||
$apiurl = 'https://gateway.hnapay.com/website/payCertificate.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "SGP03",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => date('YmdHis'),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$params = [
|
||||
'hnapayOrderId' => $hnapayOrderId
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//商户账户余额查询
|
||||
public function queryBalance(){
|
||||
$apiurl = 'https://gateway.hnapay.com/merchant/acct/queryBalance.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "QB01",
|
||||
'merId' => $this->mer_id,
|
||||
'acctType' => '11',
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'acctType', 'charset', 'signType'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//付款回调验签
|
||||
public function transferVerify($param){
|
||||
if(!$param['signValue']) return false;
|
||||
$sign_order = ['version', 'tranCode', 'merOrderId', 'merId', 'charset', 'signType', 'resultCode', 'hnapayOrderId'];
|
||||
return $this->verifySign($param, $sign_order, $param['signValue']);
|
||||
}
|
||||
|
||||
public function quickPayRequest($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/exp/payRequest2Step.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "EXP12",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => date('YmdHis'),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && $arr['resultCode'] == '0000'){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function quickPayConfirm($params, $trade_no){
|
||||
$apiurl = 'https://gateway.hnapay.com/exp/payConfirm2Step.do';
|
||||
$param = [
|
||||
'version' => "2.0",
|
||||
'tranCode' => "EXP13",
|
||||
'merId' => $this->mer_id,
|
||||
'merOrderId' => $trade_no,
|
||||
'submitTime' => date('YmdHis'),
|
||||
'signType' => $this->sign_type,
|
||||
'charset' => $this->charset,
|
||||
];
|
||||
|
||||
$param['msgCiphertext'] = $this->encryptParams($params);
|
||||
|
||||
$sign_order = ['version', 'tranCode', 'merId', 'merOrderId', 'submitTime', 'msgCiphertext'];
|
||||
$param['signValue'] = $this->generateSign($param, $sign_order);
|
||||
|
||||
$response = get_curl($apiurl, http_build_query($param));
|
||||
$arr = json_decode($response, true);
|
||||
|
||||
if(isset($arr['resultCode']) && ($arr['resultCode'] == '0000' || $arr['resultCode'] == '9999')){
|
||||
return $arr;
|
||||
}elseif(isset($arr['errorCode'])){
|
||||
throw new Exception('['.$arr['errorCode'].']'.$arr['errorMsg']);
|
||||
}else{
|
||||
throw new Exception('返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//快捷支付回调验签
|
||||
public function quickpayVerify($param){
|
||||
if(!$param['signValue']) return false;
|
||||
$sign_order = ['version', 'tranCode', 'merOrderId', 'merId', 'charset', 'signType', 'resultCode', 'errorCode', 'hnapayOrderId', 'bizProtocolNo', 'payProtocolNo', 'tranAmt', 'checkDate', 'bankCode', 'cardType', 'shortCardNo'];
|
||||
return $this->verifySign($param, $sign_order, $param['signValue']);
|
||||
}
|
||||
|
||||
//请求参数签名(新收款密钥)
|
||||
protected function generateSign($param, $sign_order){
|
||||
$signStr = $this->getSignContent($param, $sign_order);
|
||||
return $this->rsaPrivateSign($signStr);
|
||||
}
|
||||
|
||||
//请求参数签名(收款密钥)
|
||||
protected function generateSignOld($param, $sign_order){
|
||||
$signStr = $this->getSignContent($param, $sign_order);
|
||||
return $this->rsaPrivateSign($signStr, true);
|
||||
}
|
||||
|
||||
//参数验签(新收款密钥)
|
||||
protected function verifySign($param, $sign_order, $sign){
|
||||
$signStr = $this->getSignContent($param, $sign_order);
|
||||
return $this->rsaPubilcVerify($signStr, $sign);
|
||||
}
|
||||
|
||||
//参数验签(收款密钥)
|
||||
protected function verifySignOld($param, $sign_order, $sign){
|
||||
$signStr = $this->getSignContent($param, $sign_order);
|
||||
return $this->rsaPubilcVerify($signStr, $sign, true);
|
||||
}
|
||||
|
||||
//生成待签名字符串
|
||||
private function getSignContent($param, $sign_order){
|
||||
$signStr = '';
|
||||
foreach($sign_order as $key){
|
||||
if(!isset($param[$key])){
|
||||
throw new Exception('缺少参数'.$key);
|
||||
}
|
||||
if(is_array($param[$key])) $param[$key] = json_encode($param[$key], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
$signStr .= $key.'=['.$param[$key].']';
|
||||
}
|
||||
return $signStr;
|
||||
}
|
||||
|
||||
//请求参数加密
|
||||
protected function encryptParams($params){
|
||||
$key = openssl_get_publickey($this->platform_public_key);
|
||||
if(!$key){
|
||||
throw new Exception('加密失败,平台公钥不正确');
|
||||
}
|
||||
$data = json_encode($params);
|
||||
$dataArray = str_split($data, 117);
|
||||
$crypted = '';
|
||||
foreach($dataArray as $subData){
|
||||
$subCrypted = null;
|
||||
openssl_public_encrypt($subData, $subCrypted, $key);
|
||||
$crypted .= $subCrypted;
|
||||
}
|
||||
$crypted = base64_encode($crypted);
|
||||
return $crypted;
|
||||
}
|
||||
|
||||
//商户私钥签名
|
||||
protected function rsaPrivateSign($data, $is_hex = false){
|
||||
openssl_sign($data, $sign, $this->merchant_private_key, OPENSSL_ALGO_SHA1);
|
||||
$sign = $is_hex ? bin2hex($sign) : base64_encode($sign);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
//平台公钥验签
|
||||
protected function rsaPubilcVerify($data, $sign, $is_hex = false){
|
||||
$sign = $is_hex ? hex2bin($sign) : base64_decode($sign);
|
||||
$result = openssl_verify($data, $sign, $this->platform_public_key);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//加载平台公钥
|
||||
private function loadPublicKey($public_key){
|
||||
$res = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($public_key, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$pubkeyid = openssl_get_publickey($res);
|
||||
if(!$pubkeyid){
|
||||
throw new Exception('平台公钥不正确');
|
||||
}
|
||||
return $pubkeyid;
|
||||
}
|
||||
|
||||
//加载商户私钥
|
||||
private function loadPrivateKey($private_key){
|
||||
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
|
||||
wordwrap($private_key, 64, "\n", true) .
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
$prikeyid = openssl_get_privatekey($res);
|
||||
if(!$prikeyid){
|
||||
throw new Exception('商户私钥不正确');
|
||||
}
|
||||
return $prikeyid;
|
||||
}
|
||||
|
||||
//从文件加载平台公钥
|
||||
private function loadPublicKeyFile($public_key_path){
|
||||
$res = file_get_contents($public_key_path);
|
||||
$pubkeyid = openssl_get_publickey($res);
|
||||
if(!$pubkeyid){
|
||||
throw new Exception('平台公钥不正确');
|
||||
}
|
||||
return $pubkeyid;
|
||||
}
|
||||
|
||||
//从文件加载商户私钥
|
||||
private function loadPrivateKeyFile($private_key_path){
|
||||
$res = file_get_contents($private_key_path);
|
||||
$prikeyid = openssl_get_privatekey($res);
|
||||
if(!$prikeyid){
|
||||
throw new Exception('商户私钥不正确');
|
||||
}
|
||||
return $prikeyid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>新生支付服务协议</title>
|
||||
<style>
|
||||
body{margin: 18px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="border:none;padding:0cm 0cm 15.0pt 0cm;background:white;">
|
||||
<h2 align="center" style="text-align:center;background:white;">
|
||||
新生支付服务协议<span></span>
|
||||
</h2>
|
||||
</div>
|
||||
<p class="MsoNormal" align="left" style="text-align:left;text-indent:21.0pt;background:white;">
|
||||
新生支付有限公司(以下简称“新生支付”)在此提醒您(以下称“您”或称“用户”)认真阅读理解《新生支付服务协议》(以下简称“本协议”),包括免除或者限制新生支付责任的免责条款及对您的权利限制条款;您确认,在您使用新生支付的支付服务之前,您已充分阅读、理解并接受本协议的全部内容,一旦您在“同意《新生支付服务协议》”前勾选,即表示您同意遵循本协议之所有约定,一旦您使用新生支付的全部或部分服务<span>,</span>亦表示您同意遵循本协议之所有约定。本协议在您和新生支付之间具有合同上的法律效力。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第一章 用户<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>1</span>条
|
||||
您确认,您是具备完全民事权利能力和完全民事行为能力的自然人。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>2</span>条
|
||||
您同意,新生支付有权随时对本协议内容进行单方面的变更,并以公告的方式予以公布,无需另行单独通知您;若您在本协议内容公告变更后继续使用新生支付的支付服务,表示您已充分阅读、理解并接受修改后的协议内容,也将遵循修改后的协议内容;若您不同意修改后的协议内容,您应停止使用新生支付服务。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第<span>3</span>条
|
||||
您有义务确保您提交的信息准确、完整,并及时更新,若您所提供的信息有任何错误、不实、过时或不完整,或新生支付有合理的理由怀疑资料错误、不实、过时或不完整,新生支付有权暂停或终止向您提供全部或部分服务,暂停或终止您的用户资格。由上述原因导致服务无法正常提供,并由此导致的任何直接或间接损失由您自行承担,新生支付不承担任何责任。<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>4</span>条
|
||||
您不得利用新生支付服务进行任何违法违规、违反道德、有损新生支付利益的活动。如有违反,新生支付有权限制您使用新生支付服务部分功能、暂停或停止向您提供新生支付服务,同时保留追究相关责任人责任的权利。 <span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>5</span>条
|
||||
您的个人资料受到严格保护,不接受新生支付及您之外的任何个人或单位的查询请求。但法律法规(含行政规章、民族自治地方的自治条例和单行条例,下同)、司法机关、监管机构、本协议另有规定或要求,或新生支付为执行本协议确有必要披露的除外。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>6</span>条
|
||||
您有义务遵守法律法规、政策、道德以及新生支付相关业务规则等,不将新生支付的服务用于任何非法目的,也不以任何非法方式使用新生支付所提供的服务,不得利用新生支付的服务损害国家、集体和他人利益。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<br />
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第二章 新生支付服务<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>7</span>条
|
||||
新生支付服务,是指新生支付作为第三方支付服务提供商,按照您或与您交易的对方的指令向交易双方提供的支付服务,新生支付服务包括但不限于网银支付服务、快捷支付服务、协议支付服务。在您使用新生支付服务的过程中,新生支付将在新生支付平台为您分配一个新生支付账户。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>8</span>条
|
||||
网银支付,是指由您的发卡银行通过网银系统验证您的身份认证安全信息以完成支付交易的支付方式。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>9</span>条
|
||||
快捷支付,是指您在新生支付平台上输入银行卡的相关信息、银行预留的手机号码,由新生支付平台向银行系统发起认证并认证成功后即可完成交易的支付方式。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>10</span>条
|
||||
协议支付服务是指,用户将其银行卡信息与其在商户平台的交易账户绑定后,用户在商户平台进行交易时只需要选择绑定的卡片,并输入一次手机安全验证码即可完成支付交易的支付方式。<span></span>
|
||||
</p>
|
||||
<p style="background:white;">
|
||||
第<span>11</span>条
|
||||
云闪付是一个<span>APP</span>,是一种非现金收付款移动交易<a href="https://baike.so.com/doc/2506030-2648181.html" target="https://baike.so.com/doc/_blank"><span>结算工具</span></a>,是在中国人民银行的指导下,由中国银联携手各商业银行、支付机构等产业各方共同开发建设、共同维护运营的移动支付<span>APP</span>,于<span>2017</span>年<span>12</span>月<span>11</span>日正式发布。云闪付<span>APP</span>具有收付款、享优惠、卡管理三大核心功能, 云闪付<span>APP</span>与银联手机闪付、银联二维码支付同为银联三大移动支付产品。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>12</span>条
|
||||
一旦您开通协议支付服务,您同意以下事项:<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
(<span>1</span>)您在绑定您的交易账户与您的银行卡信息时,新生支付有权对您的姓名、身份证号、卡号、银行预留手机号码等要素进行校验,同时新生支付保留随时变更上述确认要素作为校验标准的权利。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>(<span>2</span>)您同意并确认,您在使用协议支付服务向您的交易方进行支付时,新生支付将通过向您的银行预留手机号码发送手机校验码的方式,对交易的真实性进行验证,在您准确输入校验码后,方能扣款成功。<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>13</span>条
|
||||
您同意本协议规定的及新生支付规定的新生支付服务的业务流程及相关操作。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>14</span>条
|
||||
您同意,新生支付依据本协议向新生支付的合作银行或者其他合作方发送的您的信息的行为以及委托银行等合作方对您的银行卡的操作(包括但不限于扣款)的行为均已经获得您的充分授权。您同意并授权新生支付有权委托银行或其它合作方按照您或者商户或商户的合作方或其他方向新生支付发送的扣款指令从您的银行卡账户中进行扣款。您同意新生支付及银行、其他主体的操作。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第<span>15</span>条
|
||||
您确认商户或商户的合作方向新生支付发送的指令,即为您本人作出的指令。您确认新生支付发送的扣款指令即为您本人作出的指令。您同意,从您指定的银行卡进行扣款的行为均视为由您自己做出。您不得变更和撤回及撤销该行为。<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>16</span>条
|
||||
您同意新生支付有权将您的信用卡支付的金额,按照新生支付与商户或商户的合作方或其他方之间的约定以及新生支付的规定支付给商户及<span>/</span>或商户的合作方。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>17</span>条
|
||||
您同意,商户或商户的合作方或其他方有权向新生支付传输您的信息,您同意并授权新生支付有权为因向您提供服务使用该等信息。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>18</span>条
|
||||
商户或商户的合作方或其他方可能会知悉您提交的信用卡信息及<span>/</span>或您的个人信息的情况,您同意接受此点并自行承担该风险,您同意新生支付对此无需承担任何责任。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>19</span>条
|
||||
在使用本协议项下的服务时,您可获得新生支付为您提供的服务以服务的实时功能为准。新生支付有权随时增加、修改或者删除任何服务功能。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>20</span>条
|
||||
您应当遵守本协议的约定和遵守各家银行的相关业务条款以及新生支付的其他相关业务规定和要求。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第<span>21</span>条
|
||||
您及持卡人(持卡人指银行卡账户的开户主体,下同)应妥善保管银行卡信息。对所有使用该银行卡信息发生的行为均视为您本人及持卡人作出,并由您本人及持卡人承担全部责任,无论该等行为是否为您本人及<span>/</span>或持卡人作出。因保管、设置、使用不当等造成的损失和责任,由您本人及持卡人自行承担。<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>22</span>条
|
||||
新生支付有权根据您的资信情况、交易记录及<span>/</span>或其他信息,决定是否为您提供新生支付服务。您同意新生支付有权对您的信息进行相关验证,保存并使用您的信息以便对您提供服务。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>23</span>条
|
||||
新生支付有权根据自身业务的发展增加、减少银行卡的种类,调整新生支付服务的内容。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>24</span>条
|
||||
您在使用新生支付服务时,将可能会受到银行对银行卡单笔转账最高金额和每日累计转账最高金额的限制。因该限制以及新生支付之外的主体的限制导致的服务失败,新生支付不承担任何责任。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<br />
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第三章 新生支付的权利及义务<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>25</span>条
|
||||
新生支付有权对用户的身份、信息、权限等进行审核,当新生支付向用户提出查询时,用户应积极配合,并及时向新生支付反馈意见及向新生支付提供相关材料。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>26</span>条
|
||||
新生支付有权根据法律法规、司法机关、监管机构、本协议的规定或要求或者新生支付依据单方判断,包含但不限于新生支付认为您已经违反本协议的明文规定或精神,暂停或终止向您提供新生支付全部或部分服务,暂停或终止您的用户资格,保存有关信息或移除您的资料,并向有关部门报告、移送相关资料等。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>27</span>条
|
||||
新生支付有权对服务进行维护、改动、升级,并暂停及<span>/</span>或终止全部或部分服务。 <span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>28</span>条
|
||||
您同意,一旦您成为新生支付的用户,新生支付即有权向您进行与新生支付业务相关的信息的发送,并且新生支付有权将您的信息,出于为您提供服务的目的提供给新生支付关联公司,您同意新生支付关联公司亦有权向您进行信息发送。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>29</span>条
|
||||
新生支付在停止提供金融产品或服务时,会及时停止继续收集您个人金融信息的活动。新生支付也会严格按照《中华人民共和国个人信息保护法》合法合规的开展相关业务。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第四章 权利声明<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>30</span>条
|
||||
新生支付拥有提供支付服务相关信息、内容的全部合法权利,包括但不限于图标、界面设计、有关数据、电子文档等的知识产权等权利受到法律法规的保护。包括您在内的其他任何个人或组织不得进行反向工程、反向汇编、反向编译,不得将图片或软件数据取出使用,也不得进行任何违法违规行为。未经新生支付许可,任何个人或组织不得用于商业用途。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<br />
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第五章 责任声明<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>31</span>条
|
||||
您与商户或商户的合作方或其他方之间的纠纷,新生支付不承担任何责任。无论何种情形,新生支付都没有责任向用户承担任何退款义务。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>32</span>条
|
||||
新生支付无法保证用户信息的准确、及时和完整;您应对您提供的信息承担全部责任,包括但不限于信息的合法合规性、真实性、准确性、完整性、及时性、有效性。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>33</span>条
|
||||
新生支付不保证服务相关信息、内容的合法合规性、真实性、准确性、可靠性、完整性、及时性、有效性、适用性、持续性、适用于某一特定用途。同时,新生支付也不对新生支付服务的质量、稳定,以及准确性、可靠性、完整性、及时性、有效性、适用性、持续性、适用于某一特定用途作出任何承诺和保证。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>34</span>条
|
||||
用户在新生支付服务中或通过新生支付服务所传送的任何内容并不代表或暗示新生支付的观点或政策,新生支付对此不承担任何责任。 <span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>35</span>条
|
||||
您应妥善保管注册的用户名称、密码等信息以及您的其他信息,所有使用该信息发生的行为均视为您作出,并由您承担全部责任,无论该等行为是否为您作出。因您保管、设置、使用不当等造成的损失和责任,由您自行承担,与新生支付无关。使用新生支付服务可能存在他人通过非法途径获得用户密码,冒用用户身份进行操作的风险,您须明白并自行承担以上风险,新生支付对账号以及密码认证通过后不对任何有关操作的真实性承担责任。 <span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>36</span>条
|
||||
您因使用新生支付的服务而产生的损失,由您自行承担,新生支付及您之外的其他主体不承担任何责任。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>37</span>条
|
||||
如您未按新生支付的规定或要求操作,或由于您自身其他原因造成新生支付服务未执行、未正确执行、延迟执行的,由您自行承担责任,新生支付及您之外的其他主体不承担任何责任。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>38</span>条
|
||||
新生支付对于与本协议有关或由本协议引起的任何间接的、惩罚性的、特殊的、派生的损失(包括但不限于业务损失、收益损失、利润损失、或其他利益的损失)不承担任何责任。用户因违反相关规定而触犯法律法规的,责任由用户自负。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>39</span>条
|
||||
由于法律法规变化或有新的法律法规、政策调整或有新的政策规定、政府行为、台风<span>/</span>地震<span>/</span>海啸<span>/</span>洪水或者其他自然灾害、战争、恐怖袭击或任何其它类似事件或其他不可抗力因素或国家金融政策调整导致新生支付不能或者部分不能提供服务或延迟履行本协议,或银行、电信运营商系统故障、调整、升级,或者由于电信运营商提供的通信线路等原因造成中断<span>/</span>终断,或电力中断<span>/</span>终断,或黑客攻击、技术调整或故障或其他技术问题,网站<span>/</span>网络<span>/</span>电脑<span>/</span>手机故障、调整、升级,系统不稳定性等原因造成的新生支付不能或者部分不能提供服务或延迟履行本协议,新生支付不承担任何责任。新生支付对于与本协议有关或由本协议引起的任何间接的、惩罚性的、特殊的、派生的损失(包括但不限于业务损失、收益损失、利润损失、或其他利益的损失)不承担任何责任。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<br />
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第六章 其他条款<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>40</span>条
|
||||
本协议适用中华人民共和国大陆法律。您同意新生支付所在地的人民法院作为争议和纠纷的管辖法院。 <span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>41</span>条
|
||||
本协议的著作权归新生支付所有,新生支付保留一切解释和修改权利。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
第<span>42</span>条
|
||||
您确认,您已经按照新生支付的提醒,充分了解并注意了本协议中免除或者限制新生支付责任的条款,以及可能加重您责任或对您的权利限制、排除您权利的条款。<span></span>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<b>第七章 附件<span></span></b>
|
||||
</p>
|
||||
<p class="MsoNormal">
|
||||
<a href="https://yunshanfu.unionpay.com/privacy/2"><span>《云闪付用户<span>隐私政策<span>》</span></span></span></a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,476 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>快捷支付页面</title>
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="<?php echo $cdnpublic ?>twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- Font Awesome 图标 -->
|
||||
<link rel="stylesheet" href="<?php echo $cdnpublic ?>font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<link href="/assets/css/datepicker.css" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #4361ee;
|
||||
--secondary-color: #3f37c9;
|
||||
--success-color: #4cc9f0;
|
||||
--light-bg: #f8f9fa;
|
||||
--card-shadow: 0 4px 12px rgba(0,0,0,0.08);
|
||||
}
|
||||
|
||||
body {
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
.payment-container {
|
||||
max-width: 800px;
|
||||
margin: 40px auto;
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
box-shadow: var(--card-shadow);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.payment-header {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
padding: 25px 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.payment-header h2 {
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.payment-header h2 i {
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.payment-body {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.credit-card-fields {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.credit-card-fields .form-group {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--primary-color);
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--secondary-color);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 0.25rem rgba(67, 97, 238, 0.25);
|
||||
}
|
||||
|
||||
.bank-info-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
display: none; /* 默认隐藏 */
|
||||
}
|
||||
|
||||
.bank-name-display {
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.card-type-display {
|
||||
background: var(--success-color);
|
||||
color: white;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(10px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.sms-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.sms-group .form-group {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.timer {
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.payment-body {
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="payment-container">
|
||||
<div class="payment-header">
|
||||
<h2><i class="fa fa-bolt"></i> 快捷支付</h2>
|
||||
<p class="mb-0">安全、便捷的支付体验</p>
|
||||
</div>
|
||||
|
||||
<form id="paymentForm" class="payment-body">
|
||||
<div class="mb-4">
|
||||
<div class="card mb-4" style="border-left: 4px solid var(--primary-color);">
|
||||
<div class="card-body py-2">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fa fa-book me-2 fa-fw text-muted"></i>
|
||||
<div>
|
||||
<small class="text-muted">订单号</small>
|
||||
<div><?php echo TRADE_NO ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fa fa-leaf me-2 fa-fw text-muted"></i>
|
||||
<div>
|
||||
<small class="text-muted">订单金额</small>
|
||||
<div class="fw-bold" style="color:coral">¥<?php echo $order['realmoney'] ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="mb-3">请输入快捷支付绑卡信息</h4>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">银行卡号</label>
|
||||
<input type="text" class="form-control form-control-lg" id="card-number" placeholder="请输入银行卡号" required pattern="\d{15,19}" maxlength="19">
|
||||
<div class="invalid-feedback">请输入有效的银行卡号</div>
|
||||
<div class="bank-info-row mt-2" id="bank-info-display">
|
||||
<span class="bank-name-display" id="bank-name-display">-</span>
|
||||
<span class="card-type-display" id="card-type-display">-</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">手机号码</label>
|
||||
<input type="tel" class="form-control form-control-lg" id="phone-number" placeholder="银行卡绑定的手机号码" required pattern="1[3-9]\d{9}" maxlength="11">
|
||||
<div class="invalid-feedback">请输入有效的手机号码</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">持卡人姓名</label>
|
||||
<input type="text" class="form-control form-control-lg" id="cardholder-name" placeholder="请输入姓名" required pattern="[\u4E00-\u9FA5]{2,20}" maxlength="20">
|
||||
<div class="invalid-feedback">请输入正确的姓名</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">身份证号码</label>
|
||||
<input type="text" class="form-control form-control-lg" id="id-number" placeholder="请输入身份证号" required pattern="\d{17}[\dXx]" maxlength="18">
|
||||
<div class="invalid-feedback">请输入有效的身份证号码</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="credit-card-fields" class="mb-3" style="display:none;">
|
||||
<label class="form-label">信用卡信息</label>
|
||||
<div class="credit-card-fields">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control form-control-lg" id="expiry-date" placeholder="到期时间" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control form-control-lg" id="cvv" placeholder="CVV码" maxlength="3" required pattern="\d{3}">
|
||||
<div class="invalid-feedback">请输入有效的CVV码</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label">短信验证码</label>
|
||||
<div class="sms-group">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control form-control-lg" id="bind-sms-code" placeholder="请输入短信验证码" required>
|
||||
</div>
|
||||
<button class="btn btn-outline-primary" id="get-sms-code">
|
||||
获取验证码
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="agree-protocol" required>
|
||||
<label class="form-check-label" for="agree-protocol">
|
||||
我已阅读并同意<a href="/pay/agreement/<?php echo TRADE_NO?>/" target="_blank">《新生支付服务协议》</a>
|
||||
</label>
|
||||
<div class="invalid-feedback">请阅读并同意支付服务协议</div>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button class="btn btn-primary btn-lg" id="confirm-payment" disabled>
|
||||
确认支付 <i class="fa fa-check ms-2"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="<?php echo $cdnpublic ?>jquery/3.4.1/jquery.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.zh-CN.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
|
||||
<script src="<?php echo $cdnpublic ?>layer/3.1.1/layer.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
// 当前状态
|
||||
let currentStep = 1;
|
||||
let smsToken = null;
|
||||
let bankCardType = null;
|
||||
let protocol = null;
|
||||
|
||||
$('input').on('input', function() {
|
||||
$(this).removeClass('is-invalid');
|
||||
});
|
||||
|
||||
$('#phone-number').on('input', function() {
|
||||
this.value = this.value.replace(/\D/g, '');
|
||||
});
|
||||
|
||||
$('#card-number').on('input', function() {
|
||||
this.value = this.value.replace(/\D/g, '');
|
||||
});
|
||||
|
||||
$('#expiry-date').datepicker({
|
||||
format: 'mm/yy',
|
||||
startView: "months",
|
||||
minViewMode: "months",
|
||||
autoclose: true,
|
||||
clearBtn: true,
|
||||
language: 'zh-CN'
|
||||
});
|
||||
|
||||
// 银行卡号输入事件
|
||||
$('#card-number').on('change', function() {
|
||||
let cardNumber = $(this).val().replace(/\s/g, '');
|
||||
|
||||
if (/^\d{16,19}$/.test(cardNumber)) {
|
||||
const formData = {
|
||||
action: 'query_card',
|
||||
cardno: cardNumber,
|
||||
};
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
url: '?',
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
layer.close(ii);
|
||||
if (response.code == 0) {
|
||||
$('#bank-name-display').text(response.data.bank_name);
|
||||
var card_type_arr = {
|
||||
'DC': '储蓄卡',
|
||||
'CC': '信用卡',
|
||||
'SCC': '准贷记卡',
|
||||
'PC': '预付费卡',
|
||||
};
|
||||
$('#card-type-display').text(card_type_arr[response.data.card_type]);
|
||||
$('#bank-info-display').show();
|
||||
bankCardType = response.data.card_type == 'CC' ? 'credit' : 'debit';
|
||||
if(response.data.card_type == 'CC'){
|
||||
$('#credit-card-fields').show();
|
||||
}else{
|
||||
$('#credit-card-fields').hide();
|
||||
}
|
||||
} else {
|
||||
$('#bank-info-display').hide();
|
||||
layer.alert(response.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(ii);
|
||||
alert('网络请求异常,请检查网络连接');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#bank-info-display').hide();
|
||||
$('#credit-card-fields').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#get-sms-code').click(function(){
|
||||
let isValid = true;
|
||||
|
||||
$('#paymentForm input:visible').each(function() {
|
||||
const $input = $(this);
|
||||
const pattern = new RegExp($input.attr('pattern'));
|
||||
|
||||
if (!pattern.test($input.val())) {
|
||||
$input.addClass('is-invalid');
|
||||
isValid = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!isValid) return;
|
||||
|
||||
const $btn = $(this).prop('disabled', true);
|
||||
|
||||
const formData = {
|
||||
action: 'request',
|
||||
phone: $('#phone-number').val(),
|
||||
cardno: $('#card-number').val(),
|
||||
cardtype: bankCardType,
|
||||
name: $('#cardholder-name').val(),
|
||||
idcard: $('#id-number').val(),
|
||||
expiry: $('#expiry-date').val(),
|
||||
cvv: $('#cvv').val(),
|
||||
};
|
||||
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
url: '?',
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
layer.close(ii);
|
||||
$btn.prop('disabled', false);
|
||||
if (response.code == 0) {
|
||||
smsToken = response.token;
|
||||
layer.msg('短信验证码已发送,请注意查收', {icon: 1, time: 1500});
|
||||
$('#confirm-payment').prop('disabled', false);
|
||||
startBindSmsCountdown();
|
||||
} else {
|
||||
layer.alert(response.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(ii);
|
||||
$btn.prop('disabled', false);
|
||||
alert('网络请求异常,请检查网络连接');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
$('#confirm-payment').click(function(){
|
||||
if (!smsToken) {
|
||||
layer.alert('请先获取短信验证码');
|
||||
return;
|
||||
}
|
||||
const smsCode = $('#bind-sms-code').val();
|
||||
if (smsCode == '') {
|
||||
layer.alert('请输入短信验证码');
|
||||
return;
|
||||
}
|
||||
if(!$('#agree-protocol').is(':checked')) {
|
||||
layer.alert('请阅读并同意支付服务协议');
|
||||
return;
|
||||
}
|
||||
|
||||
const $btn = $(this).prop('disabled', true);
|
||||
|
||||
const formData = {
|
||||
action: 'confirm',
|
||||
phone: $('#phone-number').val(),
|
||||
token: smsToken,
|
||||
smscode: smsCode,
|
||||
};
|
||||
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
url: '?',
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
layer.close(ii);
|
||||
$btn.prop('disabled', false);
|
||||
if (response.code == 0) {
|
||||
$.cookie('fastpay_phone', $('#phone-number').val(), {expires: 365, path: '/'});
|
||||
$.cookie('fastpay_cardno', $('#card-number').val(), {expires: 365, path: '/'});
|
||||
$.cookie('fastpay_name', $('#cardholder-name').val(), {expires: 365, path: '/'});
|
||||
$.cookie('fastpay_idcard', $('#id-number').val(), {expires: 365, path: '/'});
|
||||
layer.msg('支付成功,正在跳转中...', {icon: 16,shade: 0.1,time: 15000});
|
||||
setTimeout(window.location.href=response.backurl, 1000);
|
||||
} else {
|
||||
layer.alert(response.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(ii);
|
||||
$btn.prop('disabled', false);
|
||||
alert('网络请求异常,请检查网络连接');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
function startBindSmsCountdown() {
|
||||
let timeLeft = 60;
|
||||
const button = $('#get-sms-code');
|
||||
const originalHtml = button.html();
|
||||
|
||||
button.prop('disabled', true);
|
||||
|
||||
const countdown = setInterval(function() {
|
||||
timeLeft--;
|
||||
button.html(`重新发送(${timeLeft})`);
|
||||
|
||||
if (timeLeft <= 0) {
|
||||
clearInterval(countdown);
|
||||
button.html(originalHtml);
|
||||
button.prop('disabled', false);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
if($.cookie('fastpay_phone') && $.cookie('fastpay_cardno')) {
|
||||
$('#phone-number').val($.cookie('fastpay_phone'));
|
||||
$('#card-number').val($.cookie('fastpay_cardno'));
|
||||
$('#cardholder-name').val($.cookie('fastpay_name'));
|
||||
$('#id-number').val($.cookie('fastpay_idcard'));
|
||||
$('#card-number').change();
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/getshop.php",
|
||||
data: {type: "bank", trade_no: "<?php echo $order['trade_no']?>"},
|
||||
success: function (data) {
|
||||
if (data.code == 1) {
|
||||
layer.msg('支付成功,正在跳转中...', {icon: 16,shade: 0.1,time: 15000});
|
||||
setTimeout(window.location.href=data.backurl, 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
class HuifuClient
|
||||
{
|
||||
const BASE_API_URL = "https://api.huifu.com";
|
||||
|
||||
//汇付系统号
|
||||
private $sys_id;
|
||||
|
||||
//汇付产品号
|
||||
private $product_id;
|
||||
|
||||
//商户私钥
|
||||
private $merchant_private_key;
|
||||
|
||||
//汇付公钥
|
||||
private $huifu_public_key;
|
||||
|
||||
/**
|
||||
* @param $config 商户配置信息
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (empty($config['sys_id'])) {
|
||||
throw new \InvalidArgumentException('汇付系统号不能为空');
|
||||
}
|
||||
if (empty($config['product_id'])) {
|
||||
throw new \InvalidArgumentException("汇付产品号不能为空");
|
||||
}
|
||||
if (empty($config['merchant_private_key'])) {
|
||||
throw new \InvalidArgumentException("商户私钥不能为空");
|
||||
}
|
||||
if (empty($config['huifu_public_key'])) {
|
||||
throw new \InvalidArgumentException("汇付公钥不能为空");
|
||||
}
|
||||
$this->sys_id = $config['sys_id'];
|
||||
$this->product_id = $config['product_id'];
|
||||
$this->merchant_private_key = $this->loadPrivateKey($config['merchant_private_key']);
|
||||
$this->huifu_public_key = $this->loadPublicKey($config['huifu_public_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求API接口并解析返回数据
|
||||
*/
|
||||
public function requestApi($path, $data)
|
||||
{
|
||||
$url = self::BASE_API_URL . $path;
|
||||
$body = [
|
||||
'sys_id' => $this->sys_id,
|
||||
'product_id' => $this->product_id,
|
||||
'data' => $data
|
||||
];
|
||||
$body['sign'] = $this->makeSign($data);
|
||||
$response = $this->curlPost($url, $body);
|
||||
$result = json_decode($response, true);
|
||||
if (!$result || empty($result['data']) || empty($result['sign'])) {
|
||||
throw new \Exception("接口返回数据解析失败");
|
||||
}
|
||||
//print_r($result);
|
||||
if (!$this->checkResponseSign($result['data'], $result['sign'])) {
|
||||
throw new \Exception("接口返回数据验签失败");
|
||||
}
|
||||
return $result['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
public function upload($path, $data, $file_path, $file_name)
|
||||
{
|
||||
$url = self::BASE_API_URL . $path;
|
||||
$body = [
|
||||
'sys_id' => $this->sys_id,
|
||||
'product_id' => $this->product_id,
|
||||
'data' => $data
|
||||
];
|
||||
$file = new \CURLFile($file_path, '', $file_name);
|
||||
$body['sign'] = $this->makeSign($data);
|
||||
$response = $this->curlPost($url, $body, $file);
|
||||
$result = json_decode($response, true);
|
||||
if (!$result || empty($result['data'])) {
|
||||
throw new \Exception("接口返回数据解析失败");
|
||||
}
|
||||
return $result['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起POST请求
|
||||
* @param string $url 请求URL
|
||||
* @param array $body POST数据
|
||||
* @param \CURLFile $file 上传文件
|
||||
* @return string
|
||||
*/
|
||||
private function curlPost($url, $body, $file = null)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if ($file) {
|
||||
$body['data'] = json_encode($body['data'], JSON_UNESCAPED_UNICODE);
|
||||
$body['file'] = $file;
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch) > 0) {
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new \Exception($errmsg, 0);
|
||||
}
|
||||
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpStatusCode != 200) {
|
||||
curl_close($ch);
|
||||
throw new \Exception($response ? $response : 'http_code=' . $httpStatusCode, $httpStatusCode);
|
||||
}
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求签名
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
private function makeSign($params)
|
||||
{
|
||||
$params = array_filter($params, function ($value) {
|
||||
return $value !== null;
|
||||
});
|
||||
ksort($params);
|
||||
$content = json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
return $this->rsaPrivateSign($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验通知数据签名
|
||||
* @param string $data
|
||||
* @param string $sign
|
||||
* @return bool
|
||||
*/
|
||||
public function checkNotifySign($data, $sign)
|
||||
{
|
||||
if (empty($sign)) return false;
|
||||
return $this->rsaPublicVerify($data, $sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验返回数据签名
|
||||
* @param array $params
|
||||
* @param string $sign
|
||||
* @return bool
|
||||
*/
|
||||
private function checkResponseSign($params, $sign)
|
||||
{
|
||||
if (empty($sign)) return false;
|
||||
ksort($params);
|
||||
$content = json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
return $this->rsaPublicVerify($content, $sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户私钥签名
|
||||
* @param string $data 待签名字符串
|
||||
* @return string
|
||||
*/
|
||||
private function rsaPrivateSign($data)
|
||||
{
|
||||
openssl_sign($data, $signature, $this->merchant_private_key, OPENSSL_ALGO_SHA256);
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台公钥验签
|
||||
* @param string $data 待验签字符串
|
||||
* @return bool
|
||||
*/
|
||||
private function rsaPublicVerify($data, $signature)
|
||||
{
|
||||
$result = openssl_verify($data, base64_decode($signature), $this->huifu_public_key, OPENSSL_ALGO_SHA256);
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台公钥加密
|
||||
* @param string $data 待加密字符串
|
||||
* @return string
|
||||
*/
|
||||
private function rsaPublicEncrypt($data)
|
||||
{
|
||||
openssl_public_encrypt($data, $encryptResult, $this->huifu_public_key, OPENSSL_PKCS1_PADDING);
|
||||
return base64_encode($encryptResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载汇付公钥
|
||||
*/
|
||||
private function loadPublicKey($public_key)
|
||||
{
|
||||
$res = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($public_key, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$pubkeyid = openssl_get_publickey($res);
|
||||
if (!$pubkeyid) {
|
||||
throw new Exception('汇付公钥不正确');
|
||||
}
|
||||
return $pubkeyid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载商户私钥
|
||||
*/
|
||||
private function loadPrivateKey($private_key)
|
||||
{
|
||||
$res = "-----BEGIN PRIVATE KEY-----\n" .
|
||||
wordwrap($private_key, 64, "\n", true) .
|
||||
"\n-----END PRIVATE KEY-----";
|
||||
$prikeyid = openssl_get_privatekey($res);
|
||||
if (!$prikeyid) {
|
||||
throw new Exception('商户私钥不正确');
|
||||
}
|
||||
return $prikeyid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
<?php
|
||||
|
||||
class huolian_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'huolian', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '火脸支付', //支付插件显示名称
|
||||
'author' => '火脸', //支付插件作者
|
||||
'link' => 'https://www.lianok.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '对接商授权编号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '对接商MD5加密盐',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户ID',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appurl' => [
|
||||
'name' => '收银员手机号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appsecret' => [
|
||||
'name' => '退款密码(管理密码)',
|
||||
'type' => 'input',
|
||||
'note' => '如不需要退款功能可留空',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'select_wxpay' => [
|
||||
'1' => '聚合支付',
|
||||
'2' => 'H5预下单',
|
||||
],
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if(checkmobile() && !checkwechat() && ($channel['appwxa']>0 || in_array('2',$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, $conf, $device, $mdevice, $method;
|
||||
|
||||
if($method == 'wxplugin'){
|
||||
return self::wxplugin();
|
||||
}
|
||||
elseif($method == 'app'){
|
||||
return self::wxapppay();
|
||||
}
|
||||
elseif($order['typename']=='alipay'){
|
||||
return self::alipay();
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($device=='mobile' && $device!='wechat' && ($channel['appwxa']>0 || in_array('2',$channel['apptype']))){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
//聚合支付
|
||||
static private function addOrder($pay_type){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $mdevice;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
|
||||
$params = [
|
||||
'businessOrderNo' => TRADE_NO,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'subject' => $ordername,
|
||||
'payWay' => $pay_type,
|
||||
'clientIp' => $clientip,
|
||||
//'callBackUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
];
|
||||
if(checkwechat() || $mdevice=='wechat')$params['callBackUrl'] = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('api.hl.order.pay.unified', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['orderNo']);
|
||||
return $result['payUrl'];
|
||||
});
|
||||
}
|
||||
|
||||
//原生支付预下单
|
||||
static private function prepay($pay_type){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip, $mdevice;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
|
||||
$params = [
|
||||
'businessOrderNo' => TRADE_NO,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'subject' => $ordername,
|
||||
'payWay' => $pay_type,
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('api.hl.order.pay.native', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['orderNo']);
|
||||
return $result['qrCodeUrl'];
|
||||
});
|
||||
}
|
||||
|
||||
//微信小程序支付
|
||||
static private function wechat_applet($appid, $openid = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
|
||||
$params = [
|
||||
'businessOrderNo' => TRADE_NO,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'subject' => $ordername,
|
||||
'payWay' => 'wechat',
|
||||
'appId' => $appid,
|
||||
'openId' => $openid,
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('api.hl.order.pay.applet', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['orderNo']);
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
//微信小程序托管支付
|
||||
static private function wechat_applet_host(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
|
||||
$params = [
|
||||
'businessOrderNo' => TRADE_NO,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'subject' => $ordername,
|
||||
'payWay' => 'wechat',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('api.hl.order.pre.pay.applet', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['orderNo']);
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
//H5预下单
|
||||
static private function h5pay($pay_type){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
|
||||
$params = [
|
||||
'businessOrderNo' => TRADE_NO,
|
||||
'payAmount' => $order['realmoney'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'subject' => $ordername,
|
||||
'payWay' => $pay_type,
|
||||
'pageNotifyUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
|
||||
'clientIp' => $clientip,
|
||||
];
|
||||
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
|
||||
$result = $client->execute('api.hl.order.pay.h5', $params);
|
||||
\lib\Payment::updateOrder(TRADE_NO, $result['orderNo']);
|
||||
return $result['payUrl'];
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
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 wxpay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
try{
|
||||
$code_url = self::addOrder('wechat');
|
||||
}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 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::wechat_applet($wxinfo['appid'], $openid);
|
||||
$jsApiParameters = $result['jsPayInfo'];
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($jsApiParameters, true)]));
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
|
||||
if(in_array('2',$channel['apptype'])){
|
||||
try{
|
||||
$code_url = self::h5pay('wechat');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
return ['type'=>'jump','url'=>$code_url];
|
||||
}else{
|
||||
$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 wxplugin(){
|
||||
$appId = 'wxf51d01cf670e28d3';
|
||||
try{
|
||||
$result = self::wechat_applet($appId);
|
||||
$payinfo = ['appId'=>$appId, 'merchantNo'=>$result['merchantNo'], 'orderNo'=>$result['orderNo']];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'wxplugin','data'=>$payinfo];
|
||||
}
|
||||
|
||||
//微信小程序托管支付
|
||||
static public function wxapppay(){
|
||||
try{
|
||||
$result = self::wechat_applet_host();
|
||||
$payinfo = ['appId'=>$result['appId'], 'miniProgramId'=>$result['miniProgramId'], 'path'=>$result['payPath']];
|
||||
}catch(Exception $e){
|
||||
return ['type'=>'error','msg'=>$e->getMessage()];
|
||||
}
|
||||
return ['type'=>'wxapp','data'=>$payinfo];
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
try{
|
||||
$code_url = self::addOrder('cloud');
|
||||
}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) exit;
|
||||
|
||||
require_once(PAY_ROOT.'inc/HuolianClient.class.php');
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
$verify_result = $client->verify($arr);
|
||||
|
||||
if($verify_result){
|
||||
$data = json_decode($arr['respBody'], true);
|
||||
if($data['orderStatus'] == 2){
|
||||
$out_trade_no = $data['businessOrderNo'];
|
||||
$api_trade_no = $data['orderNo'];
|
||||
$money = $data['payAmount'];
|
||||
$buyer = $data['userId'];
|
||||
$bill_trade_no = $data['topChannelOrderNo'];
|
||||
$bill_mch_trade_no = $data['channelOrderNo'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO) {
|
||||
processNotify($order, $api_trade_no, $buyer, $bill_trade_no, $bill_mch_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'SUCCESS'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'status='.$data['orderStatus']];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'FAIL'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
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/HuolianClient.class.php');
|
||||
$client = new HuolianClient($channel['appid'], $channel['appkey']);
|
||||
|
||||
$params = [
|
||||
'orderNo' => $order['api_trade_no'],
|
||||
'businessRefundNo' => $order['refund_no'],
|
||||
'refundAmount' => $order['refundmoney'],
|
||||
'refundPassword' => $channel['appsecret'],
|
||||
'merchantNo' => $channel['appmchid'],
|
||||
'operatorAccount' => $channel['appurl'],
|
||||
];
|
||||
|
||||
try{
|
||||
$retData = $client->execute('api.hl.order.refund.operation', $params);
|
||||
$result = ['code'=>0, 'trade_no'=>$retData['refundNo'], 'refund_fee'=>$retData['refundAmount']];
|
||||
}catch(Exception $e){
|
||||
$result = ['code'=>-1, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function complainnotify(){
|
||||
global $channel;
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$arr = json_decode($json, true);
|
||||
if(!$arr) exit;
|
||||
|
||||
if(substr($channel['appmchid'],0,1)=='['){
|
||||
$channel['appmchid'] = $arr['merchantNo'];
|
||||
}
|
||||
|
||||
$model = \lib\Complain\CommUtil::getModel($channel);
|
||||
$model->refreshNewInfo($arr['huolianComplaintNo'], $arr['operateType']);
|
||||
|
||||
return ['type'=>'html','data'=>'SUCCESS'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://www.yuque.com/youyun-8yqqt/vpbgq7
|
||||
*/
|
||||
class HuolianClient
|
||||
{
|
||||
//支付接口地址
|
||||
private $gateway_url = 'https://open.lianok.com/open/v1/api/biz/do';
|
||||
|
||||
private $upload_url = 'https://open.lianok.com/open/v1/api/biz/file';
|
||||
|
||||
//对接商授权编号
|
||||
private $authCode;
|
||||
|
||||
//对接商MD5加密盐
|
||||
private $salt;
|
||||
|
||||
|
||||
public function __construct($authCode, $salt){
|
||||
$this->authCode = $authCode;
|
||||
$this->salt = $salt;
|
||||
}
|
||||
|
||||
//发起请求
|
||||
public function execute($resource, $params)
|
||||
{
|
||||
$params = array_filter($params, function($v){
|
||||
return $v!==null;
|
||||
});
|
||||
$commonData = [
|
||||
'authCode' => $this->authCode,
|
||||
'requestTime' => date('YmdHis'),
|
||||
'resource' => $resource,
|
||||
'versionNo' => '1'
|
||||
];
|
||||
$commonData['sign'] = $this->make_sign(array_merge($commonData, $params));
|
||||
$commonData['params'] = json_encode($params, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$data = get_curl($this->gateway_url, json_encode($commonData, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE), 0, 0, 0, 0, 0, ['Content-Type: application/json; charset=utf-8']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['code']) && $result['code']==0 && $result['status'] == 200){
|
||||
return $result['data'];
|
||||
}else{
|
||||
throw new Exception($result['message']?$result['message']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
//上传文件
|
||||
public function upload($resource, $file_path, $file_name)
|
||||
{
|
||||
$params = [
|
||||
'authCode' => $this->authCode,
|
||||
'requestTime' => date('YmdHis'),
|
||||
'resource' => $resource,
|
||||
];
|
||||
$params['sign'] = $this->make_sign($params);
|
||||
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
$mime_type = self::mime_content_type($file_ext);
|
||||
if(empty($mime_type)) $mime_type = 'image/jpeg';
|
||||
$params['file'] = new \CURLFile($file_path, $mime_type, $file_name);
|
||||
|
||||
$data = get_curl($this->upload_url, $params);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['code']) && $result['code']==0){
|
||||
return $result['data'];
|
||||
}else{
|
||||
throw new Exception($result['message']?$result['message']:'返回数据解析失败');
|
||||
}
|
||||
}
|
||||
|
||||
private static function mime_content_type($ext)
|
||||
{
|
||||
$mime_types = [
|
||||
'png' => 'image/png',
|
||||
'jpe' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'bmp' => 'image/bmp',
|
||||
];
|
||||
return $mime_types[$ext];
|
||||
}
|
||||
|
||||
public function verify($param){
|
||||
if(!isset($param['sign'])) return false;
|
||||
unset($param['code']);
|
||||
unset($param['message']);
|
||||
$sign = $this->make_sign($param);
|
||||
return $sign === $param['sign'];
|
||||
}
|
||||
|
||||
private function make_sign($param){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $v!==null){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr = strtolower($signstr);
|
||||
$signstr .= $this->salt;
|
||||
$sign = md5($signstr);
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKE5N2xm3NIrXON8Zj19GNtLZ8
|
||||
xwEQ6uDIyrS3S03UhgBJMkGl4msfq4Xuxv6XUAN7oU1XhV3/xtabr9rXto4Ke3d6
|
||||
WwNbxwXnK5LSgsQc1BhT5NcXHXpGBdt7P8NMez5qGieOKqHGvT0qvjyYnYA29a8Z
|
||||
4wzNR7vAVHp36uD5RwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* HTTP工具类
|
||||
*
|
||||
* @author wywangzhenlong
|
||||
*
|
||||
*/
|
||||
class HttpUtils {
|
||||
|
||||
public function http_post_data($url, $data_string ) {
|
||||
|
||||
$TIMEOUT = 30; //超时时间(秒)
|
||||
|
||||
$ch = curl_init ();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $TIMEOUT);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $TIMEOUT-2);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml;charset=utf-8'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$return_content = curl_exec($ch);
|
||||
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
return array (
|
||||
$return_code,
|
||||
$return_content
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
class RSAUtils{
|
||||
public static function encryptByPrivateKey($data) {
|
||||
$pi_key = openssl_pkey_get_private(file_get_contents(PAY_ROOT.'inc/cert/seller_rsa_private_key.pem'));//这个函数可用来判断私钥是否是可用的,可用返回资源id Resource id
|
||||
$encrypted="";
|
||||
openssl_private_encrypt($data,$encrypted,$pi_key,OPENSSL_PKCS1_PADDING);//私钥加密
|
||||
$encrypted = base64_encode($encrypted);//加密后的内容通常含有特殊字符,需要编码转换下,在网络间通过url传输时要注意base64编码是否是url安全的
|
||||
return $encrypted;
|
||||
}
|
||||
|
||||
public static function decryptByPublicKey($data) {
|
||||
$pu_key = openssl_pkey_get_public(file_get_contents(PAY_ROOT.'inc/cert/wy_rsa_public_key.pem'));//这个函数可用来判断公钥是否是可用的,可用返回资源id Resource id
|
||||
$decrypted = "";
|
||||
$data = base64_decode($data);
|
||||
openssl_public_decrypt($data,$decrypted,$pu_key);//公钥解密
|
||||
return $decrypted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
|
||||
include PAY_ROOT.'inc/common/RSAUtils.php';
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*
|
||||
*
|
||||
*/
|
||||
class SignUtil {
|
||||
|
||||
// public static $unSignKeyList = array (
|
||||
// "merchantSign",
|
||||
// "version",
|
||||
// "successCallbackUrl",
|
||||
// "forPayLayerUrl"
|
||||
// );
|
||||
public static function signWithoutToHex($params,$unSignKeyList) {
|
||||
ksort($params);
|
||||
$sourceSignString = SignUtil::signString ( $params, $unSignKeyList );
|
||||
//echo "sourceSignString=".htmlspecialchars($sourceSignString)."<br/>";
|
||||
//error_log("=========>sourceSignString:".$sourceSignString, 0);
|
||||
$sha256SourceSignString = hash ( "sha256", $sourceSignString);
|
||||
//error_log($sha256SourceSignString, 0);
|
||||
//echo "sha256SourceSignString=".htmlspecialchars($sha256SourceSignString)."<br/>";
|
||||
return RSAUtils::encryptByPrivateKey ($sha256SourceSignString);
|
||||
}
|
||||
|
||||
public static function sign($params,$unSignKeyList) {
|
||||
ksort($params);
|
||||
$sourceSignString = SignUtil::signString ( $params, $unSignKeyList );
|
||||
//error_log($sourceSignString, 0);
|
||||
$sha256SourceSignString = hash ( "sha256", $sourceSignString);
|
||||
//error_log($sha256SourceSignString, 0);
|
||||
return RSAUtils::encryptByPrivateKey ($sha256SourceSignString);
|
||||
}
|
||||
|
||||
public static function signString($data, $unSignKeyList) {
|
||||
$linkStr="";
|
||||
$isFirst=true;
|
||||
ksort($data);
|
||||
foreach($data as $key=>$value){
|
||||
if($value=="" || in_array($key, $unSignKeyList)) continue;
|
||||
$linkStr.=$key."=".$value."&";
|
||||
}
|
||||
return substr($linkStr,0,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
class TDESUtil {
|
||||
|
||||
/**
|
||||
* 将元数据进行补位后进行3DES加密
|
||||
* <p/>
|
||||
* 补位后 byte[] = 描述有效数据长度(int)的byte[]+原始数据byte[]+补位byte[]
|
||||
*
|
||||
* @param
|
||||
* sourceData 元数据字符串
|
||||
* @return 返回3DES加密后的16进制表示的字符串
|
||||
*/
|
||||
public static function encrypt2HexStr($keys, $sourceData) {
|
||||
$length = strlen($sourceData);
|
||||
$result = '';
|
||||
for($i = 0; $i < 4; $i ++) {
|
||||
$shift = (4 - 1 - $i) * 8;
|
||||
$result .= chr(($length >> $shift) & 0x000000FF);
|
||||
}
|
||||
$result .= $sourceData;
|
||||
$add = 8 - ($length+4) % 8;
|
||||
if($add>0){
|
||||
for($i=0; $i<$add; $i++){
|
||||
$result .= chr(0);
|
||||
}
|
||||
}
|
||||
$desdata = self::encrypt( $result, $keys );
|
||||
return bin2hex( $desdata );
|
||||
}
|
||||
|
||||
/**
|
||||
* 3DES 解密 进行了补位的16进制表示的字符串数据
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
public static function decrypt4HexStr($keys, $data) {
|
||||
$unDesResult = self::decrypt(hex2bin($data),$keys);
|
||||
|
||||
$length=0;
|
||||
for($i = 0; $i < 4; $i ++) {
|
||||
$shift = (4 - 1 - $i) * 8;
|
||||
$length += (ord($unDesResult[$i]) & 0x000000FF) << $shift;
|
||||
}
|
||||
$result = substr($unDesResult, 4, $length);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 加密算法
|
||||
public static function encrypt($input, $key) {
|
||||
return openssl_encrypt($input, 'des-ede3', $key, OPENSSL_NO_PADDING, "");
|
||||
}
|
||||
// 解密算法
|
||||
public static function decrypt($encrypted, $key) {
|
||||
return openssl_decrypt($encrypted, 'des-ede3', $key, OPENSSL_NO_PADDING, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
include PAY_ROOT.'inc/common/RSAUtils.php';
|
||||
include PAY_ROOT.'inc/common/TDESUtil.php';
|
||||
|
||||
class XMLUtil{
|
||||
public static function arrtoxml($arr,$dom=0,$item=0){
|
||||
//ksort($arr);
|
||||
if (!$dom){
|
||||
|
||||
$dom = new DOMDocument("1.0","UTF-8");
|
||||
}
|
||||
if(!$item){
|
||||
$item = $dom->createElement("jdpay");
|
||||
$item = $dom->appendChild($item);
|
||||
}
|
||||
|
||||
foreach ($arr as $key=>$val){
|
||||
$itemx = $dom->createElement(is_string($key)?$key:"item");
|
||||
$itemx = $item->appendChild($itemx);
|
||||
if (!is_array($val)){
|
||||
$text = $dom->createTextNode($val);
|
||||
$text = $itemx->appendChild($text);
|
||||
|
||||
}else {
|
||||
XMLUtil::arrtoxml($val,$dom,$itemx);
|
||||
}
|
||||
}
|
||||
return $dom;
|
||||
}
|
||||
|
||||
public static function xmlToString($dom){
|
||||
$xmlStr = $dom->saveXML();
|
||||
$xmlStr = str_replace("\r", "", $xmlStr);
|
||||
$xmlStr = str_replace("\n", "", $xmlStr);
|
||||
$xmlStr = str_replace("\t", "", $xmlStr);
|
||||
$xmlStr = preg_replace("/>\s+</", "><", $xmlStr);
|
||||
$xmlStr = preg_replace("/\s+\/>/", "/>", $xmlStr);
|
||||
$xmlStr = str_replace("=utf-8", "=UTF-8", $xmlStr);
|
||||
return $xmlStr;
|
||||
}
|
||||
|
||||
public static function encryptReqXml($param){
|
||||
$dom = XMLUtil::arrtoxml($param);
|
||||
$xmlStr = XMLUtil::xmlToString($dom);
|
||||
//echo "源串:".htmlspecialchars($xmlStr)."<br/>";
|
||||
$sha256SourceSignString = hash("sha256", $xmlStr);
|
||||
//echo "摘要:".$sha256SourceSignString."<br/>";
|
||||
$sign = RSAUtils::encryptByPrivateKey($sha256SourceSignString);
|
||||
$rootDom = $dom->getElementsByTagName("jdpay");
|
||||
$signDom = $dom->createElement("sign");
|
||||
$signDom = $rootDom[0]->appendChild($signDom);
|
||||
$signText = $dom->createTextNode($sign);
|
||||
$signText = $signDom->appendChild($signText);
|
||||
$data = XMLUtil::xmlToString($dom);
|
||||
//echo "封装后:".htmlspecialchars($data)."<br/>";
|
||||
|
||||
$desKey = Confid_desKey;
|
||||
$keys = base64_decode($desKey);
|
||||
$encrypt = TDESUtil::encrypt2HexStr($keys, $data);
|
||||
//echo "3DES后:".$encrypt."<br/>";
|
||||
$encrypt = base64_encode($encrypt);
|
||||
//echo "base64后:".$encrypt."<br/>";
|
||||
$reqParam;
|
||||
$reqParam["version"]=$param["version"];
|
||||
$reqParam["merchant"]=$param["merchant"];
|
||||
$reqParam["encrypt"]=$encrypt;
|
||||
$reqDom = XMLUtil::arrtoxml($reqParam,0,0);
|
||||
$reqXmlStr = XMLUtil::xmlToString($reqDom);
|
||||
//echo htmlspecialchars($reqXmlStr)."<br/>";
|
||||
return $reqXmlStr;
|
||||
}
|
||||
|
||||
public static function decryptResXml($resultData,&$resData){
|
||||
$resultXml = simplexml_load_string($resultData);
|
||||
$resultObj = json_decode(json_encode($resultXml),TRUE);
|
||||
$encryptStr = $resultObj["encrypt"];
|
||||
$encryptStr=base64_decode($encryptStr);
|
||||
$desKey = Confid_desKey;
|
||||
$keys = base64_decode($desKey);
|
||||
$reqBody = TDESUtil::decrypt4HexStr($keys, $encryptStr);
|
||||
//echo "请求返回encrypt Des解密后:".$reqBody."\n";
|
||||
|
||||
$bodyXml = simplexml_load_string($reqBody);
|
||||
//echo "请求返回encrypt Des解密后:".$bodyXml->saveXML()."\n";
|
||||
$resData = json_decode(json_encode($bodyXml),TRUE);
|
||||
|
||||
$inputSign = $resData["sign"];
|
||||
// $bodyDom = XMLUtil::arrtoxml($bodyObj,0,0);
|
||||
// $rootDom = $bodyDom->getElementsByTagName("jdpay");
|
||||
// $signNodelist = $rootDom[0]->getElementsByTagName("sign");
|
||||
// $rootDom[0]->removeChild($signNodelist[0]);
|
||||
|
||||
// $reqBodyStr = XMLUtil::xmlToString($bodyDom);
|
||||
|
||||
$startIndex = strpos($reqBody,"<sign>");
|
||||
$endIndex = strpos($reqBody,"</sign>");
|
||||
|
||||
if($startIndex!=false && $endIndex!=false){
|
||||
$xmls = substr($reqBody, 0,$startIndex);
|
||||
$xmle = substr($reqBody,$endIndex+7,strlen($reqBody));
|
||||
$xml=$xmls.$xmle;
|
||||
}
|
||||
|
||||
//echo "本地摘要原串:".$xml."\n";
|
||||
$sha256SourceSignString = hash("sha256", $xml);
|
||||
//echo "本地摘要:".$sha256SourceSignString."\n";
|
||||
|
||||
$decryptStr = RSAUtils::decryptByPublicKey($inputSign);
|
||||
//echo "解密后摘要:".$decryptStr."\n";
|
||||
if($decryptStr==$sha256SourceSignString){
|
||||
//echo "验签成功<br/>";
|
||||
$flag=true;
|
||||
}else{
|
||||
//echo "验签失败<br/>";
|
||||
$flag=false;
|
||||
}
|
||||
$resData["version"]=$resultObj["version"];
|
||||
$resData["merchant"]=$resultObj["merchant"];
|
||||
$resData["result"]=$resultObj["result"];
|
||||
//echo var_dump($resData);
|
||||
return $flag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
class jdpay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'jdpay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => '京东支付', //支付插件显示名称
|
||||
'author' => '京东支付', //支付插件作者
|
||||
'link' => 'https://www.jdpay.com/', //支付插件作者链接
|
||||
'types' => ['jdpay'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '商户DES密钥',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select' => null,
|
||||
'note' => '需要将商户私钥seller_rsa_private_key.pem上传到 /plugins/jdpay/inc/cert 文件夹内', //支付密钥填写说明
|
||||
'bindwxmp' => false, //是否支持绑定微信公众号
|
||||
'bindwxa' => false, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $ordername, $sitename, $submit2, $conf;
|
||||
|
||||
require(PAY_ROOT."inc/common/SignUtil.php");
|
||||
require(PAY_ROOT."inc/common/TDESUtil.php");
|
||||
|
||||
if(checkmobile()){
|
||||
$oriUrl = 'https://h5pay.jd.com/jdpay/saveOrder';
|
||||
}else{
|
||||
$oriUrl = 'https://wepay.jd.com/jdpay/saveOrder';
|
||||
}
|
||||
|
||||
$param=array();
|
||||
$param["version"]='V2.0';
|
||||
$param["merchant"]=$channel['appid'];
|
||||
$param["tradeNum"]=TRADE_NO;
|
||||
$param["tradeName"]=$ordername;
|
||||
$param["tradeTime"]= date('YmdHis');
|
||||
$param["amount"]= strval($order['realmoney']*100);
|
||||
$param["currency"]= 'CNY';
|
||||
$param["callbackUrl"]= $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
$param["notifyUrl"]= $conf['localurl'].'pay/notify/'.TRADE_NO.'/';
|
||||
$param["ip"]= $clientip;
|
||||
$param["userId"]= '';
|
||||
$param["orderType"]= '1';
|
||||
$unSignKeyList = array("sign");
|
||||
$desKey = $channel['appkey'];
|
||||
$sign = SignUtil::signWithoutToHex($param, $unSignKeyList);
|
||||
//echo $sign."<br/>";
|
||||
$param["sign"] = $sign;
|
||||
$keys = base64_decode($desKey);
|
||||
|
||||
$param["tradeNum"]=TDESUtil::encrypt2HexStr($keys, $param["tradeNum"]);
|
||||
if($param["tradeName"] != null && $param["tradeName"]!=""){
|
||||
$param["tradeName"]=TDESUtil::encrypt2HexStr($keys, $param["tradeName"]);
|
||||
}
|
||||
$param["tradeTime"]=TDESUtil::encrypt2HexStr($keys, $param["tradeTime"]);
|
||||
$param["amount"]=TDESUtil::encrypt2HexStr($keys, $param["amount"]);
|
||||
$param["currency"]=TDESUtil::encrypt2HexStr($keys, $param["currency"]);
|
||||
$param["callbackUrl"]=TDESUtil::encrypt2HexStr($keys, $param["callbackUrl"]);
|
||||
$param["notifyUrl"]=TDESUtil::encrypt2HexStr($keys, $param["notifyUrl"]);
|
||||
$param["ip"]=TDESUtil::encrypt2HexStr($keys, $param["ip"]);
|
||||
|
||||
if($param["userId"] != null && $param["userId"]!=""){
|
||||
$param["userId"]=TDESUtil::encrypt2HexStr($keys, $param["userId"]);
|
||||
}
|
||||
if($param["orderType"] != null && $param["orderType"]!=""){
|
||||
$param["orderType"]=TDESUtil::encrypt2HexStr($keys, $param["orderType"]);
|
||||
}
|
||||
//print_R($param);exit;
|
||||
|
||||
$html_text = '<form action="'.$oriUrl.'" method="post" id="dopay">';
|
||||
foreach($param as $k => $v) {
|
||||
$html_text .= "<input type=\"hidden\" name=\"{$k}\" value=\"{$v}\" />\n";
|
||||
}
|
||||
$html_text .= '<input type="submit" value="正在跳转"></form><script>document.getElementById("dopay").submit();</script>';
|
||||
|
||||
return ['type'=>'html','data'=>$html_text];
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/common/XMLUtil.php");
|
||||
|
||||
define("Confid_desKey",$channel['appkey']);
|
||||
$xml = file_get_contents("php://input");
|
||||
$flag = XMLUtil::decryptResXml($xml, $param);
|
||||
//var_dump($flag);
|
||||
if($flag){
|
||||
$trade_no = daddslashes($param["tradeNum"]);
|
||||
$out_trade_no = daddslashes($param["tradeNum"]);
|
||||
if($param["status"]==2) {
|
||||
if($out_trade_no == TRADE_NO && $param["amount"]==strval($order['realmoney']*100)){
|
||||
processNotify($order, $trade_no);
|
||||
}
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'error'];
|
||||
}
|
||||
}
|
||||
|
||||
//同步回调
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
require(PAY_ROOT."inc/common/SignUtil.php");
|
||||
require(PAY_ROOT."inc/common/TDESUtil.php");
|
||||
|
||||
$desKey = $channel['appkey'];
|
||||
$keys = base64_decode($desKey);
|
||||
$param = array();
|
||||
if(!empty($_POST["tradeNum"])){
|
||||
$param["tradeNum"]=TDESUtil::decrypt4HexStr($keys, $_POST["tradeNum"]);
|
||||
}
|
||||
if(!empty($_POST["amount"])){
|
||||
$param["amount"]=TDESUtil::decrypt4HexStr($keys, $_POST["amount"]);
|
||||
}
|
||||
if(!empty($_POST["currency"])){
|
||||
$param["currency"]=TDESUtil::decrypt4HexStr($keys, $_POST["currency"]);
|
||||
}
|
||||
if(!empty($_POST["tradeTime"])){
|
||||
$param["tradeTime"]=TDESUtil::decrypt4HexStr($keys, $_POST["tradeTime"]);
|
||||
}
|
||||
if(!empty($_POST["status"])){
|
||||
$param["status"]=TDESUtil::decrypt4HexStr($keys, $_POST["status"]);
|
||||
}
|
||||
|
||||
$sign = $_POST["sign"];
|
||||
$strSourceData = SignUtil::signString($param, array());
|
||||
//echo "strSourceData=".htmlspecialchars($strSourceData)."<br/>";
|
||||
//$decryptBASE64Arr = base64_decode($sign);
|
||||
$decryptStr = RSAUtils::decryptByPublicKey($sign);
|
||||
//echo "decryptStr=".htmlspecialchars($decryptStr)."<br/>";
|
||||
$sha256SourceSignString = hash ( "sha256", $strSourceData);
|
||||
//echo "sha256SourceSignString=".htmlspecialchars($sha256SourceSignString)."<br/>";
|
||||
if($decryptStr == $sha256SourceSignString){
|
||||
$trade_no = daddslashes($param["tradeNum"]);
|
||||
$out_trade_no = daddslashes($param["tradeNum"]);
|
||||
if($out_trade_no == TRADE_NO && $param["amount"]==$order['realmoney']*100){
|
||||
processReturn($order, $trade_no);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'验证签名失败!strSourceData='.htmlspecialchars($strSourceData)];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
require(PAY_ROOT."inc/common/XMLUtil.php");
|
||||
require(PAY_ROOT."inc/common/HttpUtils.php");
|
||||
|
||||
define("Confid_desKey",$channel['appkey']);
|
||||
|
||||
$param["version"]="V2.0";
|
||||
$param["merchant"]=$channel['appid'];
|
||||
$param["tradeNum"]=$order['refund_no'];
|
||||
$param["oTradeNum"]=$order['api_trade_no'];
|
||||
$param["amount"]=$order['refundmoney']*100;
|
||||
$param["currency"]="CNY";
|
||||
|
||||
$reqXmlStr = XMLUtil::encryptReqXml($param);
|
||||
$url = 'https://paygate.jd.com/service/refund';
|
||||
|
||||
$httputil = new HttpUtils();
|
||||
list ( $return_code, $return_content ) = $httputil->http_post_data($url, $reqXmlStr);
|
||||
//echo $return_content."\n";
|
||||
|
||||
$flag=XMLUtil::decryptResXml($return_content,$resData);
|
||||
//echo var_dump($resData);
|
||||
|
||||
if($flag){
|
||||
if($resData['status'] == "1"){
|
||||
$result = ['code'=>0, 'trade_no'=>$resData['oTradeNum'], 'refund_fee'=>$resData['amount']];
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>'['.$resData['result']['code'].']'.$resData['result']['desc']];
|
||||
}
|
||||
}else{
|
||||
$result = ['code'=>-1, 'msg'=>'验签失败'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,665 @@
|
||||
<?php
|
||||
|
||||
class jeepay_plugin
|
||||
{
|
||||
static public $info = [
|
||||
'name' => 'jeepay', //支付插件英文名称,需和目录名称一致,不能有重复
|
||||
'showname' => 'Jeepay聚合支付', //支付插件显示名称
|
||||
'author' => 'Jeepay', //支付插件作者
|
||||
'link' => 'https://www.jeequan.com/', //支付插件作者链接
|
||||
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'transtypes' => ['alipay','wxpay','bank'], //支付插件支持的转账方式,可选的有alipay,qqpay,wxpay,bank
|
||||
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
|
||||
'appurl' => [
|
||||
'name' => '接口地址',
|
||||
'type' => 'input',
|
||||
'note' => '必须以http://或https://开头,以/结尾',
|
||||
],
|
||||
'appmchid' => [
|
||||
'name' => '商户号',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appid' => [
|
||||
'name' => '应用AppId',
|
||||
'type' => 'input',
|
||||
'note' => '',
|
||||
],
|
||||
'appkey' => [
|
||||
'name' => '私钥AppSecret',
|
||||
'type' => 'textarea',
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
'select_alipay' => [
|
||||
'1' => '支付宝扫码',
|
||||
'2' => '支付宝PC网站',
|
||||
'3' => '支付宝WAP',
|
||||
'7' => '支付宝APP',
|
||||
'4' => '支付宝生活号',
|
||||
'5' => '聚合扫码',
|
||||
'6' => 'WEB收银台',
|
||||
],
|
||||
'select_wxpay' => [
|
||||
'1' => '微信扫码',
|
||||
'2' => '微信H5',
|
||||
'7' => '微信APP',
|
||||
'3' => '微信公众号',
|
||||
'4' => '微信小程序',
|
||||
'5' => '聚合扫码',
|
||||
'6' => 'WEB收银台',
|
||||
],
|
||||
'select_bank' => [
|
||||
'1' => '云闪付扫码',
|
||||
'5' => '聚合扫码',
|
||||
'6' => 'WEB收银台',
|
||||
],
|
||||
'note' => '', //支付密钥填写说明
|
||||
'bindwxmp' => true, //是否支持绑定微信公众号
|
||||
'bindwxa' => true, //是否支持绑定微信小程序
|
||||
];
|
||||
|
||||
static public function submit(){
|
||||
global $siteurl, $channel, $order, $sitename;
|
||||
|
||||
if($order['typename']=='alipay'){
|
||||
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if(checkwechat() && in_array('3',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif(checkmobile()){
|
||||
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($order['typename']=='alipay'){
|
||||
return self::alipay();
|
||||
}elseif($order['typename']=='wxpay'){
|
||||
if($mdevice=='wechat' && in_array('3',$channel['apptype'])){
|
||||
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/?d=1'];
|
||||
}elseif($device=='mobile'){
|
||||
return self::wxwappay();
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}elseif($order['typename']=='bank'){
|
||||
return self::bank();
|
||||
}
|
||||
}
|
||||
|
||||
static private function make_sign($param, $key){
|
||||
ksort($param);
|
||||
$signstr = '';
|
||||
|
||||
foreach($param as $k => $v){
|
||||
if($k != "sign" && $v!=''){
|
||||
$signstr .= $k.'='.$v.'&';
|
||||
}
|
||||
}
|
||||
$signstr .= 'key=' . $key;
|
||||
$sign = strtoupper(md5($signstr));
|
||||
return $sign;
|
||||
}
|
||||
|
||||
static private function getMillisecond()
|
||||
{
|
||||
list($s1, $s2) = explode(' ', microtime());
|
||||
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
//下单通用
|
||||
static private function addOrder($wayCode, $channelExtra = null){
|
||||
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if($_GET['r'] == 1){
|
||||
$returnUrl = $siteurl.'pay/ok/'.TRADE_NO.'/';
|
||||
}else{
|
||||
$returnUrl = $siteurl.'pay/return/'.TRADE_NO.'/';
|
||||
}
|
||||
$apiurl = $channel['appurl'].'api/pay/unifiedOrder';
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'mchOrderNo' => TRADE_NO,
|
||||
'wayCode' => $wayCode,
|
||||
'amount' => round($order['realmoney']*100),
|
||||
'currency' => 'cny',
|
||||
'clientIp' => $clientip,
|
||||
'subject' => $ordername,
|
||||
'body' => $ordername,
|
||||
'notifyUrl' => $conf['localurl'].'pay/notify/'.TRADE_NO.'/',
|
||||
'returnUrl' => $returnUrl,
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
if($channelExtra) $param['channelExtra'] = $channelExtra;
|
||||
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
|
||||
return \lib\Payment::lockPayData(TRADE_NO, function() use($apiurl, $param) {
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if(isset($result['code']) && $result['code']==0){
|
||||
if($result['data']['errMsg']){
|
||||
throw new Exception('['.$result['data']['errCode'].']'.$result['data']['errMsg']);
|
||||
}elseif($result['data']['error']){
|
||||
throw new Exception($result['data']['error']);
|
||||
}
|
||||
return [strtolower($result['data']['payDataType']), $result['data']['payData']];
|
||||
}else{
|
||||
throw new Exception($result['msg']?$result['msg']:'返回数据解析失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//支付宝扫码支付
|
||||
static public function alipay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('3',$channel['apptype']) && ($device=='mobile' || checkmobile())){
|
||||
$wayCode = 'ALI_WAP';
|
||||
}elseif(in_array('2',$channel['apptype']) && ($device=='pc' || !checkmobile())){
|
||||
$wayCode = 'ALI_PC';
|
||||
}elseif(in_array('1',$channel['apptype'])){
|
||||
$wayCode = 'ALI_QR';
|
||||
}elseif(in_array('7',$channel['apptype'])){
|
||||
$wayCode = 'ALI_APP';
|
||||
}elseif(in_array('4',$channel['apptype'])){
|
||||
$qrcode_url = $siteurl.'pay/alipayjs/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$qrcode_url];
|
||||
}elseif(in_array('5',$channel['apptype'])){
|
||||
$wayCode = 'QR_CASHIER';
|
||||
}elseif(in_array('6',$channel['apptype'])){
|
||||
$wayCode = 'WEB_CASHIER';
|
||||
}elseif(in_array('3',$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{
|
||||
list($type, $payData) = self::addOrder($wayCode);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($wayCode == 'QR_CASHIER' && strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient')===false && $mdevice!='alipay'){
|
||||
$type = 'codeurl';
|
||||
}
|
||||
|
||||
if($type == 'payurl'){
|
||||
if(checkwechat()){
|
||||
return ['type'=>'page','page'=>'wxopen'];
|
||||
}
|
||||
return ['type'=>'jump','url'=>$payData];
|
||||
}elseif($type == 'form'){
|
||||
return ['type'=>'html','url'=>$payData];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$payData];
|
||||
}
|
||||
}
|
||||
|
||||
//支付宝生活号支付
|
||||
static public function alipayjs(){
|
||||
global $channel;
|
||||
|
||||
if (!isset($_GET['channelUserId'])) {
|
||||
$apiurl = $channel['appurl'].'api/channelUserId/jump';
|
||||
$redirect_url = (is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'ifCode' => 'AUTO',
|
||||
'redirectUrl' => $redirect_url,
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
$jump_url = $apiurl.'?'.http_build_query($param);
|
||||
return ['type'=>'jump','url'=>$jump_url];
|
||||
}else{
|
||||
$openId = $_GET['channelUserId'];
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($openId, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
try{
|
||||
$extra = json_encode(['buyerUserId' => $openId]);
|
||||
list($type, $payData) = self::addOrder('ALI_JSAPI', $extra);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'支付宝下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($type == 'payurl'){
|
||||
return ['type'=>'jump','url'=>$payData];
|
||||
}elseif($type == 'form'){
|
||||
return ['type'=>'html','url'=>$payData];
|
||||
}else{
|
||||
if($_GET['d']=='1'){
|
||||
$redirect_url='data.backurl';
|
||||
}else{
|
||||
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
|
||||
}
|
||||
$arr = json_decode($payData, true);
|
||||
return ['type'=>'page','page'=>'alipay_jspay','data'=>['alipay_trade_no'=>$arr['alipayTradeNo'], 'redirect_url'=>$redirect_url]];
|
||||
}
|
||||
}
|
||||
|
||||
//微信扫码支付
|
||||
static public function wxpay(){
|
||||
global $channel, $device, $mdevice, $siteurl;
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
$wayCode = 'WX_NATIVE';
|
||||
}elseif(in_array('3',$channel['apptype'])){
|
||||
$qrcode_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$qrcode_url];
|
||||
}elseif(in_array('4',$channel['apptype']) || in_array('7',$channel['apptype'])){
|
||||
$qrcode_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$qrcode_url];
|
||||
}elseif(in_array('5',$channel['apptype'])){
|
||||
$wayCode = 'QR_CASHIER';
|
||||
}elseif(in_array('6',$channel['apptype'])){
|
||||
$wayCode = 'WEB_CASHIER';
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'当前支付通道没有开启的支付方式'];
|
||||
}
|
||||
try{
|
||||
list($type, $payData) = self::addOrder($wayCode);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($wayCode == 'QR_CASHIER' && !checkwechat() && $mdevice!='wechat'){
|
||||
$type = 'codeurl';
|
||||
}
|
||||
if($type == 'payurl'){
|
||||
return ['type'=>'jump','url'=>$payData];
|
||||
}elseif($type == 'form'){
|
||||
return ['type'=>'html','url'=>$payData];
|
||||
}elseif (checkmobile() || $device=='mobile') {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$payData];
|
||||
} else {
|
||||
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$payData];
|
||||
}
|
||||
}
|
||||
|
||||
//云闪付扫码支付
|
||||
static public function bank(){
|
||||
global $channel;
|
||||
if(in_array('1',$channel['apptype'])){
|
||||
$wayCode = 'YSF_NATIVE';
|
||||
}elseif(in_array('5',$channel['apptype'])){
|
||||
$wayCode = 'QR_CASHIER';
|
||||
}elseif(in_array('6',$channel['apptype'])){
|
||||
$wayCode = 'WEB_CASHIER';
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'当前支付通道没有开启的支付方式'];
|
||||
}
|
||||
|
||||
try{
|
||||
list($type, $payData) = self::addOrder($wayCode);
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
|
||||
if($type == 'payurl'){
|
||||
return ['type'=>'jump','url'=>$payData];
|
||||
}elseif($type == 'form'){
|
||||
return ['type'=>'html','url'=>$payData];
|
||||
}else{
|
||||
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$payData];
|
||||
}
|
||||
}
|
||||
|
||||
//微信公众号支付
|
||||
static public function wxjspay(){
|
||||
global $siteurl, $channel, $order, $ordername, $conf;
|
||||
|
||||
//①、获取用户openid
|
||||
if($channel['appwxmp']>0){
|
||||
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
|
||||
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
|
||||
$openid = wechat_oauth($wxinfo);
|
||||
}else{
|
||||
if (!isset($_GET['channelUserId'])) {
|
||||
$apiurl = $channel['appurl'].'api/channelUserId/jump';
|
||||
$redirect_url = (is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'ifCode' => 'AUTO',
|
||||
'redirectUrl' => $redirect_url,
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
$jump_url = $apiurl.'?'.http_build_query($param);
|
||||
return ['type'=>'jump','url'=>$jump_url];
|
||||
}else{
|
||||
$openid = $_GET['channelUserId'];
|
||||
}
|
||||
}
|
||||
|
||||
$blocks = checkBlockUser($openid, TRADE_NO);
|
||||
if($blocks) return $blocks;
|
||||
|
||||
//②、统一下单
|
||||
try{
|
||||
$extra = json_encode(['openid' => $openid]);
|
||||
list($type, $jsApiParameters) = self::addOrder('WX_JSAPI', $extra);
|
||||
}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'=>$jsApiParameters, '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{
|
||||
$extra = json_encode(['openid' => $openid]);
|
||||
list($type, $jsApiParameters) = self::addOrder('WX_LITE', $extra);
|
||||
}catch(Exception $ex){
|
||||
exit('{"code":-1,"msg":"微信支付下单失败!'.$ex->getMessage().'"}');
|
||||
}
|
||||
|
||||
exit(json_encode(['code'=>0, 'data'=>json_decode($jsApiParameters, true)]));
|
||||
}
|
||||
|
||||
//微信手机支付
|
||||
static public function wxwappay(){
|
||||
global $siteurl,$channel, $order, $ordername, $conf, $clientip;
|
||||
|
||||
if(in_array('2',$channel['apptype'])){ //H5支付
|
||||
try{
|
||||
list($type,$jump_url) = self::addOrder('WX_H5');
|
||||
return ['type'=>'jump','url'=>$jump_url];
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信H5支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
}elseif(in_array('7',$channel['apptype'])){ //APP支付
|
||||
try{
|
||||
list($type,$code_url) = self::addOrder('WX_APP');
|
||||
}catch(Exception $ex){
|
||||
return ['type'=>'error','msg'=>'微信H5支付下单失败!'.$ex->getMessage()];
|
||||
}
|
||||
return ['type'=>'qrcode','page'=>'wxpay_h5','url'=>$code_url];
|
||||
}elseif(in_array('4',$channel['apptype']) && $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(in_array('3',$channel['apptype'])){ //公众号支付
|
||||
$code_url = $siteurl.'pay/wxjspay/'.TRADE_NO.'/';
|
||||
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$code_url];
|
||||
}else{
|
||||
return self::wxpay();
|
||||
}
|
||||
}
|
||||
|
||||
//异步回调
|
||||
static public function notify(){
|
||||
global $channel, $order;
|
||||
|
||||
if(strpos($_SERVER['CONTENT_TYPE'], 'application/json')!==false){
|
||||
$data = file_get_contents('php://input');
|
||||
$arr = json_decode($data, true);
|
||||
}elseif(isset($_POST['sign'])){
|
||||
$arr = $_POST;
|
||||
}elseif(isset($_GET['sign'])){
|
||||
$arr = $_GET;
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'no data'];
|
||||
}
|
||||
|
||||
$sign = self::make_sign($arr,$channel['appkey']);
|
||||
|
||||
if($sign===$arr["sign"]){
|
||||
if($arr['state'] == '2'){
|
||||
$out_trade_no = $arr['mchOrderNo'];
|
||||
$api_trade_no = $arr['payOrderId'];
|
||||
$money = $arr['amount'];
|
||||
$bill_trade_no = $arr['channelOrderNo'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO && $money==strval($order['realmoney']*100)) {
|
||||
processNotify($order, $api_trade_no, null, $bill_trade_no);
|
||||
}
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'state='.$arr['state']];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付返回页面
|
||||
static public function return(){
|
||||
global $channel, $order;
|
||||
|
||||
$sign = self::make_sign($_GET,$channel['appkey']);
|
||||
|
||||
if($sign===$_GET["sign"]){
|
||||
if($_GET['state'] == '2'){
|
||||
$out_trade_no = daddslashes($_GET['mchOrderNo']);
|
||||
$api_trade_no = daddslashes($_GET['payOrderId']);
|
||||
$money = $_GET['amount'];
|
||||
|
||||
if ($out_trade_no == TRADE_NO && $money==strval($order['realmoney']*100)) {
|
||||
processReturn($order, $api_trade_no);
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'订单信息校验失败'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'page','page'=>'return'];
|
||||
}
|
||||
}else{
|
||||
return ['type'=>'error','msg'=>'签名验证失败'];
|
||||
}
|
||||
}
|
||||
|
||||
//退款
|
||||
static public function refund($order){
|
||||
global $channel;
|
||||
if(empty($order))exit();
|
||||
|
||||
$apiurl = $channel['appurl'].'api/refund/refundOrder';
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'payOrderId' => $order['api_trade_no'],
|
||||
'mchRefundNo' => $order['refund_no'],
|
||||
'refundAmount' => round($order['refundmoney']*100),
|
||||
'currency' => 'cny',
|
||||
'refundReason' => '申请退款',
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if (isset($result['code']) && $result['code'] == 0) {
|
||||
if($result['data']['errMsg']){
|
||||
return ['code'=>-1, 'msg'=>'['.$result['data']['errCode'].']'.$result['data']['errMsg']];
|
||||
}elseif($result['data']['error']){
|
||||
return ['code'=>-1, 'msg'=>$result['data']['error']];
|
||||
}
|
||||
return ['code'=>0, 'trade_no'=>$result['data']['refundOrderId'], 'refund_fee'=>$order['refundmoney']];
|
||||
} else {
|
||||
return ['code'=>-1, 'msg'=>$result['msg']?$result['msg']:'返回数据解析失败'];
|
||||
}
|
||||
}
|
||||
|
||||
//转账
|
||||
static public function transfer($channel, $bizParam){
|
||||
global $clientip, $conf;
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
$type = $bizParam['type'];
|
||||
if($type == 'alipay'){
|
||||
$entryType = 'ALIPAY_CASH';
|
||||
}elseif($type == 'wxpay'){
|
||||
$entryType = 'WX_CASH';
|
||||
}elseif($type == 'bank'){
|
||||
$entryType = 'BANK_CARD';
|
||||
}
|
||||
|
||||
$apiurl = $channel['appurl'].'api/transferOrder';
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'mchOrderNo' => $bizParam['out_biz_no'],
|
||||
'ifCode' => $type,
|
||||
'entryType' => $entryType,
|
||||
'amount' => round($bizParam['money']*100),
|
||||
'currency' => 'cny',
|
||||
'accountNo' => $bizParam['payee_account'],
|
||||
'accountName' => $bizParam['payee_real_name'],
|
||||
'clientIp' => $clientip,
|
||||
'transferDesc' => $bizParam['transfer_desc'],
|
||||
'notifyUrl' => $conf['localurl'].'pay/transfernotify/'.$channel['id'].'/',
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if (isset($result['code']) && $result['code'] == 0) {
|
||||
if($result['data']['errMsg']){
|
||||
return ['code'=>-1, 'errcode'=>$result['data']['errCode'], 'msg'=>'['.$result['data']['errCode'].']'.$result['data']['errMsg']];
|
||||
}elseif($result['data']['error']){
|
||||
return ['code'=>-1, 'msg'=>$result['data']['error']];
|
||||
}
|
||||
if($result['data']['state'] == 2){
|
||||
$status = 1;
|
||||
}else{
|
||||
$status = 0;
|
||||
}
|
||||
return ['code'=>0, 'status'=>$status, 'orderid'=>$result['data']['transferId'], 'paydate'=>date('Y-m-d H:i:s')];
|
||||
} else {
|
||||
return ['code'=>-1, 'msg'=>$result['msg']?$result['msg']:'返回数据解析失败'];
|
||||
}
|
||||
}
|
||||
|
||||
//转账查询
|
||||
static public function transfer_query($channel, $bizParam){
|
||||
if(empty($channel) || empty($bizParam))exit();
|
||||
|
||||
$apiurl = $channel['appurl'].'api/transfer/query';
|
||||
$param = [
|
||||
'mchNo' => $channel['appmchid'],
|
||||
'appId' => $channel['appid'],
|
||||
'transferId' => $bizParam['orderid'],
|
||||
'reqTime' => self::getMillisecond(),
|
||||
'version' => '1.0',
|
||||
'signType' => 'MD5',
|
||||
];
|
||||
|
||||
$param['sign'] = self::make_sign($param, $channel['appkey']);
|
||||
|
||||
$data = get_curl($apiurl, json_encode($param), 0, 0, 0, 0, 0, ['Content-Type: application/json']);
|
||||
|
||||
$result = json_decode($data, true);
|
||||
|
||||
if (isset($result['code']) && $result['code'] == 0) {
|
||||
if($result['data']['state'] == 2){
|
||||
$status = 1;
|
||||
}elseif($result['data']['state'] == 1){
|
||||
$status = 0;
|
||||
}else{
|
||||
$status = 2;
|
||||
}
|
||||
$paydate = date('Y-m-d H:i:s', intval($result['data']['successTime']/1000));
|
||||
if($result['data']['errCode'] && $result['data']['errMsg']){
|
||||
$errmsg = '['.$result['data']['errCode'].']'.$result['data']['errMsg'];
|
||||
}
|
||||
return ['code'=>0, 'status'=>$status, 'amount'=>$result['data']['amount'], 'paydate'=>$paydate, 'errmsg'=>$errmsg];
|
||||
} else {
|
||||
return ['code'=>-1, 'msg'=>$result['msg']?$result['msg']:'返回数据解析失败'];
|
||||
}
|
||||
}
|
||||
|
||||
static public function transfernotify(){
|
||||
global $channel;
|
||||
|
||||
if(isset($_POST['sign'])){
|
||||
$arr = $_POST;
|
||||
}elseif(isset($_GET['sign'])){
|
||||
$arr = $_GET;
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'no data'];
|
||||
}
|
||||
|
||||
$sign = self::make_sign($arr,$channel['appkey']);
|
||||
|
||||
if($sign===$arr["sign"]){
|
||||
if($arr['state'] == 2){
|
||||
$status = 1;
|
||||
}elseif($arr['state'] == 1){
|
||||
$status = 0;
|
||||
}else{
|
||||
$status = 2;
|
||||
}
|
||||
if($arr['errCode'] && $arr['errMsg']){
|
||||
$errmsg = '['.$arr['errCode'].']'.$arr['errMsg'];
|
||||
}
|
||||
processTransfer($arr['mchOrderNo'], $status, $errmsg);
|
||||
return ['type'=>'html','data'=>'success'];
|
||||
}else{
|
||||
return ['type'=>'html','data'=>'fail'];
|
||||
}
|
||||
}
|
||||
|
||||
//支付成功页面
|
||||
static public function ok(){
|
||||
return ['type'=>'page','page'=>'ok'];
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 176 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user