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());
支付寶網(wǎng)站支付:
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,設(shè)置此參數(shù)萤彩,將進(jìn)入沙箱模式
??],
部分代碼:
$product_code = "FAST_INSTANT_TRADE_PAY";// 銷售產(chǎn)品碼,與支付寶簽約的產(chǎn)品碼名稱斧拍。 注:目前僅支持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();
這是我寫的對(duì)于網(wǎng)站發(fā)起支付的兩種方式(支付寶雀扶、微信)的部分代碼
composer引入組件composer require yansongda/pay
composer 查看組件文檔地址:
https://packagist.org/packages/yansongda/pay