我在app/services文件夹中创建了服务,我正在使用它控制器。在服务文件夹中,我有以下内容。namespace App\Services;use GuzzleHttp\Client;class SubscriptionService{ private $subUsername = 'M****************b'; private $subPassword = 'V********g'; private $subSource = 'o*********k'; private $subMinisite = 'a*******m'; public function pinVerify($request) { $DataArray = []; $client = new Client(); $route = 'http://b*******e.com/****/P***y.php'; $params = [ 'form_params' => [ 'Username' => $this->subUsername, 'Password' => $this->subPassword, 'userID' => $request->user_id, 'pincode' => $request->pin_code, ] ]; $result = $client->request('POST', $route, $params); $body = $result->getBody(); $bodyContent = $body->getContents(); if ($bodyContent === 1) { $DataArray['message'] = 'Failed because of system error'; $DataArray['status'] = 'failed'; } else { $DataArray['message'] = 'Sorry provided pincode is wrong.'; $DataArray['status'] = 'failed'; } return $DataArray; }}在控制器中,我以如下一种方法使用它。namespace App\Http\Controllers\Api;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use App\Services\SubscriptionService as Subscription;class XyzController extends Controller{ public function verifyPinCode(Subscription $Subscription, Request $request){ $serviceResponse = $Subscription->pinVerify($request); return response()->json($serviceResponse, 200); }}结果我收到错误,Class does not exist.我不确定我在哪里犯了错误。有人可以指导我如何解决这个问题吗?错误ReflectionExceptionClass App\Services\SubscriptionService does not existPrevious exceptionssyntax error, unexpected ''pincode'' (T_CONSTANT_ENCAPSED_STRING)Composer.json"autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" } },
3 回答
拉丁的传说
TA贡献1789条经验 获得超8个赞
在给定的行之后有一个额外的空格或其他东西。我已经检查了你的代码,在这一行'userID' => $request->user_id,
和你的语法错误之后打了一个退格,意外的“密码”(T_CONSTANT_ENCAPSED_STRING)错误消失了
开心每一天1111
TA贡献1836条经验 获得超13个赞
这syntax error, unexpected ''pincode'' (T_CONSTANT_ENCAPSED_STRING)
意味着您在SubscriptionService
类文件中存在解析问题(额外字符或丢失字符或类似问题)。因此,不会解析该文件并且该类不可用。异常错误跟踪对此很清楚。找到问题并解决它。你的问题就解决了。
- 3 回答
- 0 关注
- 116 浏览
添加回答
举报
0/150
提交
取消