## 1.maatwebsite/excel导出导入excel包用法 ### 1.1导出功能 namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Excel; class ExcelController extends Controller { //Excel文件导出功能 By Laravel学院 public function export(){ $cellData = [ ['学号','姓名','成绩'], ['10001','AAAAA','99'], ['10002','BBBBB','92'], ['10003','CCCCC','95'], ['10004','DDDDD','89'], ['10005','EEEEE','96'], ]; Excel::create('学生成绩',function($excel) use ($cellData){ $excel->sheet('score', function($sheet) use ($cellData){ $sheet->rows($cellData); }); })->export('xls'); } } ### 1.2导入功能 //Excel文件导入功能 By Laravel学院 public function import(){ $filePath = 'storage/exports/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; Excel::load($filePath, function($reader) { $data = $reader->all(); dd($data); }); } ## 2 socialiteproviders/qq 第三方登录包 >[info]使用如下Composer命令安装依赖: ~~~ composer require socialiteproviders/weibo 注册服务提供者(同时注释掉原有的Socialite提供者): //Laravel\Socialite\SocialiteServiceProvider::class, SocialiteProviders\Manager\ServiceProvider::class, 添加Socialite门面(如果已有略过本操作): 'Socialite' => Laravel\Socialite\Facades\Socialite::class, 添加事件监听器(App/Providers/EventServiceProvider): protected $listen = [ 'SocialiteProviders\Manager\SocialiteWasCalled' => [ 'SocialiteProviders\Weibo\WeiboExtendSocialite@handle', ], ]; 去新浪微博开放平台(http://open.weibo.com/)创建一个新的网站应用以获取相应的App Key和App Secret。需要注意的是不比GitHub,新浪微博需要创建的网站应用对应网站在外网可以访问。 然后在配置文件app/services.php中添加weibo配置项: 'weibo' => [ 'client_id' => 'your weibo app App Key', 'client_secret' => 'your weibo app App Secret', 'redirect' => 'http://laravel.app:8000/auth/weibo/callback' ] 接下来我们要对AuthController略作修改: public function redirectToProvider(Request $request,$service) { return Socialite::driver($service)->redirect(); } public function handleProviderCallback(Request $request,$service) { $user = Socialite::driver($service)->user(); dd($user); } 以支持多种不同认证提供者的切换。 最后需要修改认证路由规则如下: Route::get('auth/{service}', 'Auth\AuthController@redirectToProvider'); Route::get('auth/{service}/callback', 'Auth\AuthController@handleProviderCallback'); ## 3.支付宝支付" ignited/laravel-omnipay": "2.*", 在composer.json中添加如下依赖: "ignited/laravel-omnipay": "2.*", "lokielse/omnipay-alipay": "dev-master" 运行composer update安装这些依赖。 安装完成后在config/app.php中注册服务提供者: Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider::class 同时添加OmniPay门面到门面数组: 'Omnipay' => Ignited\LaravelOmnipay\Facades\OmnipayFacade::class 最后,通过php artisan vendor:publish发布配置文件。 此外OmniPay for Laravel 5 & Lumen还支持Lumen。在bootstrap/app.php中注册服务提供者: $app->register(Ignited\LaravelOmnipay\LumenOmnipayServiceProvider::class); 将laravel-omnipay.php文件复制到config/laravel-omnipay.php,然后在bootstrap/app.php中添加如下代码: $app->configure('laravel-omnipay'); 然后在项目中编辑配置文件config/laravel-omnipay.php: return [ // 默认支付网关 'default' => 'alipay', // 各个支付网关配置 'gateways' => [ 'paypal' => [ 'driver' => 'PayPal_Express', 'options' => [ 'solutionType' => '', 'landingPage' => '', 'headerImageUrl' => '' ] ], 'alipay' => [ 'driver' => 'Alipay_Express', 'options' => [ 'partner' => 'your pid here', 'key' => 'your appid here', 'sellerEmail' =>'your alipay account here', 'returnUrl' => 'your returnUrl here', 'notifyUrl' => 'your notifyUrl here' ] ] ] ]; ~~~ >[info]1)定义相关路由 ~~~ //支付宝支付处理 Route::get('alipay/pay','AlipayController@pay'); //支付后跳转页面 Route::post('alipay/return','AlipayController@result'); 新建控制器AlipayController,定义其pay方法如下: public function pay(){ $gateway = Omnipay::gateway(); $options = [ 'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), 'subject' => 'Alipay Test', 'total_fee' => '0.01', ]; $response = $gateway->purchase($options)->send(); $response->redirect(); } ~~~ >[info]3)回调 >[info]接下来我们定义支付后跳转页面对应的result方法: ~~~ public function result(){ $gateway = Omnipay::gateway(); $options = [ 'request_params'=> $_REQUEST, ]; $response = $gateway->completePurchase($options)->send(); if ($response->isSuccessful() && $response->isTradeStatusOk()) { //支付成功后操作 exit('支付成功'); } else { //支付失败通知. exit('支付失败'); } } ~~~ ## 4.微信支付 ~~~ "lokielse/omnipay-wechatpay": "^1.0", "labs7in0/omnipay-wechat": "dev-master" 支付 public function pay(){ $gateway = Omnipay::gateway(); $options = [ 'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), 'subject' => 'Alipay Test', 'total_fee' => '0.01', ]; $response = $gateway->purchase($options)->send(); $response->redirect(); } ~~~ >[info]3)回调 接下来我们定义支付后跳转页面对应的result方法: 支付 ~~~ public function result(){ $config = ['appId' => '***','appKey' => ''***', 'mchId'=>''***']; $wechat = Omnipay::gateway('wechat'); $wechat->setAppId($config['appId']); $wechat->setMchId($config['mchId']); $wechat->setAppKey($config['appKey']); $params = array( 'out_trade_no' => time(), // billing id in your system 'notify_url' => env('WECHAT_NOTIFY_URL', url('pay/wechat/notify/async')), // URL for asynchronous notify 'body' => '微信充值', // A simple description 'total_fee' => 0.01, // Amount with less than 2 decimals places 'fee_type' => 'CNY', // Currency name from ISO4217, Optional, default as CNY ); $response = $wechat->purchase($params)->send(); $img = QrCode::size('280')->generate($response->getRedirectUrl()); return $img; 回调 public function async(){ //获取微信回调参数 //$arrNotify = \CommonClass::xmlToArray($GLOBALS['HTTP_RAW_POST_DATA']); $arrNotify = ['return_code' => 'SUCESS']; $content = '<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> </xml>'; if ($arrNotify['result_code'] == 'SUCCESS' && $arrNotify['return_code'] = 'SUCCESS') { /** * 此处处理订单业务逻辑 */ //回复微信端请求成功 return response($content)->header('Content-Type', 'text/xml'); } } ~~~