Browse Source
			
			
			Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop
			
			
				develop
			
			
		
		Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop
	
		
	
			
			
				develop
			
			
		
				 9 changed files with 332 additions and 9 deletions
			
			
		- 
					31app/Admin/Controllers/MiniProgramDraftController.php
 - 
					25app/Admin/Controllers/MiniProgramListController.php
 - 
					32app/Admin/Controllers/MiniProgramTemplateController.php
 - 
					56app/Admin/Repositories/MiniProgramDraft.php
 - 
					56app/Admin/Repositories/MiniProgramList.php
 - 
					56app/Admin/Repositories/MiniProgramTemplate.php
 - 
					5app/Admin/routes.php
 - 
					59app/Http/Controllers/Api/MiniProgramController.php
 - 
					21routes/api.php
 
@ -0,0 +1,31 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Controllers; | 
			
		||||
 | 
				use App\Admin\Repositories\MiniProgramDraft; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Http\Controllers\AdminController; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序草稿箱 | 
			
		||||
 | 
				 * Class MiniProgramController | 
			
		||||
 | 
				 * @package App\Admin\Controllers | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramDraftController extends AdminController | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					protected $title = '小程序草稿箱'; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					protected function grid(): Grid | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return Grid::make(new MiniProgramDraft, function (Grid $grid) { | 
			
		||||
 | 
							$grid->disableCreateButton(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
							$grid->column('draft_id', 'ID'); | 
			
		||||
 | 
							$grid->column('user_version', '版本号'); | 
			
		||||
 | 
							$grid->column('user_desc', '描述'); | 
			
		||||
 | 
							$grid->column('source_miniprogram', '来源小程序'); | 
			
		||||
 | 
							$grid->column('source_miniprogram_appid', '上传者微信号'); | 
			
		||||
 | 
							$grid->column('developer', '上传者微信昵称'); | 
			
		||||
 | 
							$grid->column('create_time', '创建时间')->display(fn($v) => date('Y-m-d H:i:s', $v)); | 
			
		||||
 | 
						}); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,25 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Controllers; | 
			
		||||
 | 
				use App\Admin\Repositories\MiniProgramList; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Http\Controllers\AdminController; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序列表 | 
			
		||||
 | 
				 * Class MiniProgramController | 
			
		||||
 | 
				 * @package App\Admin\Controllers | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramListController extends AdminController | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					protected $title = '小程序列表'; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					protected function grid(): Grid | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return Grid::make(new MiniProgramList, function (Grid $grid) { | 
			
		||||
 | 
							$grid->disableCreateButton(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
							$grid->column('authorizer_appid', 'APPID'); | 
			
		||||
 | 
						}); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,32 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Controllers; | 
			
		||||
 | 
				use App\Admin\Repositories\MiniProgramTemplate; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Http\Controllers\AdminController; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序模板 | 
			
		||||
 | 
				 * Class MiniProgramController | 
			
		||||
 | 
				 * @package App\Admin\Controllers | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramTemplateController extends AdminController | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					protected $title = '小程序模板'; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					protected function grid(): Grid | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return Grid::make(new MiniProgramTemplate, function (Grid $grid) { | 
			
		||||
 | 
							$grid->disableCreateButton(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
							$grid->column('template_id', 'ID'); | 
			
		||||
 | 
							$grid->column('template_type', '模板类型')->using([0 => '普通模板', 1 => '标准模板']); | 
			
		||||
 | 
							$grid->column('user_version', '版本号'); | 
			
		||||
 | 
							$grid->column('user_desc', '描述'); | 
			
		||||
 | 
							$grid->column('source_miniprogram', '来源小程序'); | 
			
		||||
 | 
							$grid->column('source_miniprogram_appid', '上传者微信号'); | 
			
		||||
 | 
							$grid->column('developer', '上传者微信昵称'); | 
			
		||||
 | 
							$grid->column('create_time', '创建时间')->display(fn($v) => date('Y-m-d H:i:s', $v)); | 
			
		||||
 | 
						}); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,56 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Repositories; | 
			
		||||
 | 
				use App\Models\AdminSetting; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Repositories\Repository; | 
			
		||||
 | 
				use EasyWeChat\Factory; | 
			
		||||
 | 
				use GuzzleHttp\Exception\GuzzleException; | 
			
		||||
 | 
				use Illuminate\Pagination\LengthAwarePaginator; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序草稿箱 | 
			
		||||
 | 
				 * Class MiniProgramDraft | 
			
		||||
 | 
				 * @package App\Admin\Repositories | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramDraft extends Repository | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					public function getPrimaryKeyColumn() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return 'draft_id'; | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 查询表格数据 | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param Grid\Model $model | 
			
		||||
 | 
					 * @return LengthAwarePaginator | 
			
		||||
 | 
					 * @throws GuzzleException | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function get(Grid\Model $model): LengthAwarePaginator | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); | 
			
		||||
 | 
						$config = [ | 
			
		||||
 | 
							'app_id'   => $setting['service_appid'], | 
			
		||||
 | 
							'secret'   => $setting['service_appsecret'], | 
			
		||||
 | 
							'token'    => $setting['service_token'], | 
			
		||||
 | 
							'aes_key'  => $setting['service_aeskey'], | 
			
		||||
 | 
						]; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$openPlatform = Factory::openPlatform($config); | 
			
		||||
 | 
						$codeTemplate = $openPlatform['code_template']; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						if (empty($codeTemplate) || (!$list = $codeTemplate->getDrafts())) { | 
			
		||||
 | 
							$data['total'] = 0; | 
			
		||||
 | 
							$data['subjects'] = []; | 
			
		||||
 | 
						} else { | 
			
		||||
 | 
							$data['total'] = count($list['draft_list']); | 
			
		||||
 | 
							$data['subjects'] = $list['draft_list'] ?? []; | 
			
		||||
 | 
						} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						return $model->makePaginator( | 
			
		||||
 | 
							$data['total'] ?? 0, // 传入总记录数
 | 
			
		||||
 | 
							$data['subjects'] ?? [] // 传入数据二维数组
 | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,56 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Repositories; | 
			
		||||
 | 
				use App\Models\AdminSetting; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Repositories\Repository; | 
			
		||||
 | 
				use EasyWeChat\Factory; | 
			
		||||
 | 
				use GuzzleHttp\Exception\GuzzleException; | 
			
		||||
 | 
				use Illuminate\Pagination\LengthAwarePaginator; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序草稿箱 | 
			
		||||
 | 
				 * Class MiniProgramDraft | 
			
		||||
 | 
				 * @package App\Admin\Repositories | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramList extends Repository | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					public function getPrimaryKeyColumn() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return ''; | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 查询表格数据 | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param Grid\Model $model | 
			
		||||
 | 
					 * @return LengthAwarePaginator | 
			
		||||
 | 
					 * @throws GuzzleException | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function get(Grid\Model $model): LengthAwarePaginator | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); | 
			
		||||
 | 
						$config = [ | 
			
		||||
 | 
							'app_id'   => $setting['service_appid'], | 
			
		||||
 | 
							'secret'   => $setting['service_appsecret'], | 
			
		||||
 | 
							'token'    => $setting['service_token'], | 
			
		||||
 | 
							'aes_key'  => $setting['service_aeskey'], | 
			
		||||
 | 
						]; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$openPlatform = Factory::openPlatform($config); | 
			
		||||
 | 
						$codeTemplate = $openPlatform['code_template']; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						if (empty($codeTemplate) || (!$list = $openPlatform->getAuthorizers())) { | 
			
		||||
 | 
							$data['total'] = 0; | 
			
		||||
 | 
							$data['subjects'] = []; | 
			
		||||
 | 
						} else { | 
			
		||||
 | 
							$data['total'] = count($list['list']); | 
			
		||||
 | 
							$data['subjects'] = $list['list'] ?? []; | 
			
		||||
 | 
						} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						return $model->makePaginator( | 
			
		||||
 | 
							$data['total'] ?? 0, // 传入总记录数
 | 
			
		||||
 | 
							$data['subjects'] ?? [] // 传入数据二维数组
 | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,56 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Admin\Repositories; | 
			
		||||
 | 
				use App\Models\AdminSetting; | 
			
		||||
 | 
				use Dcat\Admin\Grid; | 
			
		||||
 | 
				use Dcat\Admin\Repositories\Repository; | 
			
		||||
 | 
				use EasyWeChat\Factory; | 
			
		||||
 | 
				use GuzzleHttp\Exception\GuzzleException; | 
			
		||||
 | 
				use Illuminate\Pagination\LengthAwarePaginator; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序模板 | 
			
		||||
 | 
				 * Class MiniProgramDraft | 
			
		||||
 | 
				 * @package App\Admin\Repositories | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramTemplate extends Repository | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					public function getPrimaryKeyColumn() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return 'template_id'; | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					/** | 
			
		||||
 | 
					 * 查询表格数据 | 
			
		||||
 | 
					 * | 
			
		||||
 | 
					 * @param Grid\Model $model | 
			
		||||
 | 
					 * @return LengthAwarePaginator | 
			
		||||
 | 
					 * @throws GuzzleException | 
			
		||||
 | 
					 */ | 
			
		||||
 | 
					public function get(Grid\Model $model): LengthAwarePaginator | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); | 
			
		||||
 | 
						$config = [ | 
			
		||||
 | 
							'app_id'   => $setting['service_appid'], | 
			
		||||
 | 
							'secret'   => $setting['service_appsecret'], | 
			
		||||
 | 
							'token'    => $setting['service_token'], | 
			
		||||
 | 
							'aes_key'  => $setting['service_aeskey'], | 
			
		||||
 | 
						]; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$openPlatform = Factory::openPlatform($config); | 
			
		||||
 | 
						$codeTemplate = $openPlatform['code_template']; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						if (empty($codeTemplate) || (!$list = $codeTemplate->list())) { | 
			
		||||
 | 
							$data['total'] = 0; | 
			
		||||
 | 
							$data['subjects'] = []; | 
			
		||||
 | 
						} else { | 
			
		||||
 | 
							$data['total'] = count($list['template_list']); | 
			
		||||
 | 
							$data['subjects'] = $list['template_list'] ?? []; | 
			
		||||
 | 
						} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						return $model->makePaginator( | 
			
		||||
 | 
							$data['total'] ?? 0, // 传入总记录数
 | 
			
		||||
 | 
							$data['subjects'] ?? [] // 传入数据二维数组
 | 
			
		||||
 | 
						); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,59 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\Http\Controllers\Api; | 
			
		||||
 | 
				use App\Http\Controllers\Controller; | 
			
		||||
 | 
				use App\Models\AdminSetting; | 
			
		||||
 | 
				use EasyWeChat\Factory; | 
			
		||||
 | 
				use EasyWeChat\OpenPlatform\Server\Guard; | 
			
		||||
 | 
				use Illuminate\Http\Request; | 
			
		||||
 | 
				use Illuminate\Support\Facades\DB; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 小程序授权等相关 | 
			
		||||
 | 
				 * Class MiniProgramController | 
			
		||||
 | 
				 * @package App\Http\Controllers\Api | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class MiniProgramController extends Controller | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					// 第三方平台授权事件通知
 | 
			
		||||
 | 
					public function authEvent(Request $request) | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); | 
			
		||||
 | 
						$config = [ // 第三方平台信息
 | 
			
		||||
 | 
							'app_id'   => $setting['service_appid'], | 
			
		||||
 | 
							'secret'   => $setting['service_appsecret'], | 
			
		||||
 | 
							'token'    => $setting['service_token'], | 
			
		||||
 | 
							'aes_key'  => $setting['service_aeskey'], | 
			
		||||
 | 
						]; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						$openPlatform = Factory::openPlatform($config); | 
			
		||||
 | 
						$server = $openPlatform->server; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						// 处理授权成功事件
 | 
			
		||||
 | 
						$server->push(function ($message) { | 
			
		||||
 | 
							DB::table('auth_event')->insert([ | 
			
		||||
 | 
								['response' => json_encode($message)] | 
			
		||||
 | 
							]); | 
			
		||||
 | 
						}, Guard::EVENT_AUTHORIZED); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						// 处理授权更新事件
 | 
			
		||||
 | 
						$server->push(function ($message) { | 
			
		||||
 | 
							DB::table('auth_event')->insert([ | 
			
		||||
 | 
								['response' => json_encode($message)] | 
			
		||||
 | 
							]); | 
			
		||||
 | 
						}, Guard::EVENT_UPDATE_AUTHORIZED); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						// 处理授权取消事件
 | 
			
		||||
 | 
						$server->push(function ($message) { | 
			
		||||
 | 
							DB::table('auth_event')->insert([ | 
			
		||||
 | 
								['response' => json_encode($message)] | 
			
		||||
 | 
							]); | 
			
		||||
 | 
						}, Guard::EVENT_UNAUTHORIZED); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						DB::table('auth_event')->insert([ | 
			
		||||
 | 
							['response' => json_encode($request->all())] | 
			
		||||
 | 
						]); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						return $server->serve(); | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue