| 
					
					
						
							
						
					
					
				 | 
				@ -3,6 +3,8 @@ | 
			
		
		
	
		
			
				 | 
				 | 
				namespace App\Http\Controllers\Api; | 
				 | 
				 | 
				namespace App\Http\Controllers\Api; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				use App\Models\AdminSetting; | 
				 | 
				 | 
				use App\Models\AdminSetting; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				use App\Models\AgentProduct; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				use App\Models\MiniProgramUploadLog; | 
			
		
		
	
		
			
				 | 
				 | 
				use EasyWeChat\Factory; | 
				 | 
				 | 
				use EasyWeChat\Factory; | 
			
		
		
	
		
			
				 | 
				 | 
				use Illuminate\Support\Facades\Cache; | 
				 | 
				 | 
				use Illuminate\Support\Facades\Cache; | 
			
		
		
	
		
			
				 | 
				 | 
				use Illuminate\Support\Facades\DB; | 
				 | 
				 | 
				use Illuminate\Support\Facades\DB; | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -17,31 +19,29 @@ class TestController | 
			
		
		
	
		
			
				 | 
				 | 
					public function index() | 
				 | 
				 | 
					public function index() | 
			
		
		
	
		
			
				 | 
				 | 
					{ | 
				 | 
				 | 
					{ | 
			
		
		
	
		
			
				 | 
				 | 
						$appid = 'wx5bd5789ad8f89524'; | 
				 | 
				 | 
						$appid = 'wx5bd5789ad8f89524'; | 
			
		
		
	
		
			
				 | 
				 | 
						$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'], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						]; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						$message = json_decode('{"ToUserName":"gh_f4ab40774bed","FromUserName":"o4seR5d-TVCImgh2aE6UtrQn6LIM","CreateTime":"1631670431","MsgType":"event","Event":"weapp_audit_success","SuccTime":"1631670431"}', true); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						DB::table('mini_program_events') | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							->insert([ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'type' => 1, | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'response' => json_encode($message), | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'event' => $message['MsgType'] ?? '', | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'created_at' => now() | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							]); | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
						$app = Factory::openPlatform($config); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						$refreshToken = $app->getAuthorizer($appid)['authorization_info']['authorizer_refresh_token'] ?? null; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						if (!$refreshToken) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							return $this->error('获取refresh_token失败'); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						//审核结果通知
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$auditArr = [ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'weapp_audit_success' => 0, //成功
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'weapp_audit_fail' => 1, //拒绝
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'weapp_audit_delay' => 4, //审核延后
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							]; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$log = MiniProgramUploadLog::query() | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->where('appid', $appid) | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->orderBy('id', 'desc') | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->first(); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$log->is_success = $auditArr[$message['Event']] ?? -1; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$log->save(); | 
			
		
		
	
		
			
				 | 
				 | 
						} | 
				 | 
				 | 
						} | 
			
		
		
	
		
			
				 | 
				 | 
						$miniProgram = $app->miniProgram($appid, $refreshToken); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						$domain = $miniProgram['domain']; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						$host = env('APP_URL'); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						$param = [ | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							"action" => "add", | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							"requestdomain" => [$host], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							"wsrequestdomain" => [str_replace('http', 'ws', $host)], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							"uploaddomain" => [$host], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							"downloaddomain" => [$host], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						]; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
						return [$domain->modify($param), $domain->setWebviewDomain([env('APP_URL')])]; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
					} | 
				 | 
				 | 
					} | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
					/** | 
				 | 
				 | 
					/** | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
					
				 | 
				
  |