51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Api\Controller;
|
|
|
|
use Think\Controller;
|
|
use Yansongda\Pay\Pay;
|
|
|
|
class DownController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
// 配置微信支付参数
|
|
$config = [
|
|
'wechat' => [
|
|
'default' => [
|
|
'mch_id' => '1625070753', // 必填-商户号
|
|
'mch_secret_key' => 'qwertyuiopasdfghjklzxcvbnm123456', // 必填-v3商户秘钥
|
|
'mch_secret_cert' => 'C:/phpstudy_pro/WWW/cart/apiclient_key.pem', // 必填-商户私钥路径
|
|
'mch_public_cert_path' => 'C:/phpstudy_pro/WWW/cart/apiclient_cert.pem', // 必填-商户公钥证书路径
|
|
'notify_url' => 'https://szdot.top', // 回调地址
|
|
'mini_app_id' => 'wx8347571d6893a383', // 小程序 app_id
|
|
],
|
|
],
|
|
];
|
|
|
|
// 配置 Pay
|
|
Pay::config($config);
|
|
|
|
// 定义参数
|
|
$params = [
|
|
'_config' => 'default', // 使用默认配置
|
|
];
|
|
|
|
// 保存证书的目录
|
|
$certPath = 'C:/phpstudy_pro/WWW/cart/Cert';
|
|
|
|
// 创建保存证书的目录,如果不存在
|
|
if (!is_dir($certPath)) {
|
|
mkdir($certPath, 0777, true);
|
|
}
|
|
|
|
// 获取微信平台公钥证书并保存到指定目录
|
|
try {
|
|
\Yansongda\Pay\get_wechat_public_certs($params, $certPath);
|
|
echo "微信平台公钥证书已成功保存到 $certPath\n";
|
|
} catch (Exception $e) {
|
|
echo '获取微信平台公钥证书时发生错误: ' . $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
}
|