(string)mnbt_plugin_option_get('alipay_official', 'app_id', ''),
'private_key' => (string)mnbt_plugin_option_get('alipay_official', 'private_key', ''),
'public_key' => (string)mnbt_plugin_option_get('alipay_official', 'public_key', ''),
'gateway' => (string)mnbt_plugin_option_get('alipay_official', 'gateway', ''),
];
$configured = $cfg['app_id'] !== '' && $cfg['private_key'] !== '' && $cfg['public_key'] !== '';
$gatewayDefault = $cfg['gateway'] === '' ? 'https://openapi.alipay.com/gateway.do' : $cfg['gateway'];
// 计算回调 URL
$scriptName = str_replace('\\', '/', $_SERVER['SCRIPT_NAME'] ?? '');
$siteRoot = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https://' : 'http://')
. ($_SERVER['HTTP_HOST'] ?? 'localhost')
. substr($scriptName, 0, strrpos($scriptName, '/'));
if (substr($siteRoot, -6) === '/admin') {
$siteRoot = substr($siteRoot, 0, -6);
}
// 回调地址统一用 index.php?_r= 兼容路由:不依赖服务器伪静态重写
$notifyUrl = $siteRoot . '/index.php?_r=/pay/alipay_official/notify';
$returnUrl = $siteRoot . '/index.php?_r=/pay/alipay_official/return';
?>
支付宝官方设置
配置支付宝开放平台应用的 RSA2 凭证
说明:本页仅配置支付宝官方 API 凭证。是否在客户端显示该插件的付款方式,请前往
支付设置 启用。
开放平台 → 应用列表 → 对应应用的 APPID
开放平台 → 密钥管理 → 应用私钥(PKCS1 或 PKCS8 格式均可,仅 base64 字符串部分)
开放平台 → 密钥管理 → 支付宝公钥(用于验签异步通知)
默认正式环境;沙箱测试可改为 https://openapi-sandbox.dl.alipaydev.com/gateway.do
未配置:请填写完整的三项凭证,否则支付宝官方相关付款方式将不可用。
已配置:凭证已就绪。可在
支付设置 启用电脑网站支付或扫码支付。
回调地址
在支付宝开放平台应用配置中需填入以下地址
| 类型 | URL |
| 异步通知(notify_url) |
=htmlspecialchars($notifyUrl, ENT_QUOTES)?> |
| 同步返回(return_url) |
=htmlspecialchars($returnUrl, ENT_QUOTES)?> |
回调路径由系统通过通用路由自动注册。请在支付宝开放平台对应应用的"接口加签方式"中选择 公钥模式,并确保服务器时间准确(RSA2 验签对时间戳敏感)。
- PHP 已启用
openssl 扩展(RSA2 签名必需)
- PHP 已启用
curl 扩展(调用 alipay.trade.precreate 必需)
- 已配置 nginx/apache rewrite,将未命中文件的请求转发到
index.php(异步通知需要)
- 开放平台应用已开通"电脑网站支付"和"当面付"能力