我在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.我不确定我在哪里犯了错误。有人可以指导我如何解决这个问题吗?
错误
ReflectionException
Class App\Services\SubscriptionService does not exist
Previous exceptions
syntax error, unexpected ''pincode'' (T_CONSTANT_ENCAPSED_STRING)
Composer.json
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
冉冉说
拉丁的传说
开心每一天1111