use Yansongda\Pay\Pay;
use Yansongda\Pay\Log;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
use Cake\Network\Exception\NotFoundException;
use Cake\Core\Configure;
微信二维码支付:
config:
'Wechat'=> [
'app_id' => '', // APP APPID
'miniapp_id' => '', // Mp APPID
'mch_id' => '',
'key' => '',
'notify_url' => '',
'return_url' => '',
'log' => [ // optional
'file' => './logs/wechat.log',
'level' => 'debug'
]
],
部分代码:
$total_fee = $price;
$order = [
'out_trade_no' => $order_no,
'body' => ‘’,
'total_fee' => 0.01,
];
$config_wechat = Configure::read('Wechat');
$result = Pay::wechat($config_wechat)->scan($order);
$qr = $result->code_url;
$qrCode = new QrCode($qr);
$qrCode->setSize(300);
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setValidateResult(false);
//header('Content-Type: '.$qrCode->getContentType());
//pr($qrCode->writeString()) ;
$str = base64_encode($qrCode->writeString());
支付宝网站支付:
config:
'Alipay'=> [
'app_id' => '',
'notify_url' => '',
'return_url' => '',
'ali_public_key' =>‘',
// 加密方式: **RSA2**
'sign_type'=>"RSA2",
'private_key' =>'',
'log' => [
'file' => './logs/alipay.log',
'level' => 'debug'
]
// 'mode' => 'dev', // optional,设置此参数,将进入沙箱模式
],
部分代码:
$product_code = "FAST_INSTANT_TRADE_PAY";// 销售产品码,与支付宝签约的产品码名称。 注:目前仅支持FAST_INSTANT_TRADE_PAY
$total_amount = 1;
$ordermsg = [
'out_trade_no' => $order_no,
'product_code' => $product_code,
'total_amount' => $total_amount,
'subject' => '',
'body' => '',
];
$config_alipay = Configure::read('Alipay');
$alipay = Pay::alipay($config_alipay)->web($ordermsg);
return $alipay->send();
这是我写的对于网站发起支付的两种方式(支付宝、微信)的部分代码
composer引入组件composer require yansongda/pay
composer 查看组件文档地址:
https://packagist.org/packages/yansongda/pay