簡訊簽名狀態查詢
SmsSignRequestModel.php
增加describeSmsSigns
方法
/* app/Http/Requests/Api/SmsSignRequest.php */
<?php
namespace App\Http\Models\TencentCloud;
use TencentCloud\Sms\V20190711\Models\AddSmsSignRequest;
use TencentCloud\Sms\V20190711\Models\ModifySmsSignRequest;
use TencentCloud\Sms\V20190711\Models\DeleteSmsSignRequest;
use TencentCloud\Sms\V20190711\Models\DescribeSmsSignListRequest;
class SmsSignRequest
{
·
·
·
/**
* 簡訊簽名狀態查詢 DescribeSmsSignList
*
* @param Array $signIds 簽名 ID 陣列。
* @param integer $international 是否國際/港澳臺簡訊:
* 0:表示國內簡訊。
* 1:表示國際/港澳臺簡訊。
* @return void
*/
public function describeSmsSigns(Array $signIds, int $international = 0)
{
// 例項化一個 sms 修改簽名請求物件,每個介面都會對應一個request物件。
$req = new DescribeSmsSignListRequest();
$req->SignIdSet = $signIds;
$req->International = $international;
return $req;
}
}
簡訊簽名驗證類增加簡訊簽名狀態查詢的驗證規則
/* app/Http/Requests/Api/SmsSignRequest.php */
<?php
namespace App\Http\Requests\Api;
use Illuminate\Http\Request;
class SmsSignRequest extends FormRequest
{
·
·
·
protected $describeSignsRules = [
'signIds' => 'required|array',
'international' => 'required|integer'
];
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(Request $request)
{
switch ($request->method) {
case 'GET':
$rules = $this->describeSignsRules;
break;
case 'POST':
$rules = $this->addSignRules;
break;
case 'PUT':
$rules = $this->modifySignRules;
break;
case 'DELETE':
$rules = $this->deleteSignRules;
break;
default:
$rules = $this->addSignRules;
break;
}
return $rules;
}
}
SmsSignController.php
增加簽名狀態查詢方法
/* app/Http/Controllers/Api/SmsSignController.php */
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\Api\SmsSignRequest;
use App\Http\Models\TencentCloud\SmsSignRequest as SmsSignRequestModel;
use TencentCloud\Common\Exception\TencentCloudSDKException;
class SmsSignController extends Controller
{
·
·
·
public function describeSigns(SmsSignRequest $request,SmsSignRequestModel $describeSmsSignsRequestModel)
{
try {
$sms = app('tencentcloudSms');
$req = $describeSmsSignsRequestModel->describeSmsSigns($request->signIds, $request->international);
// 通過client物件呼叫DescribeInstances方法發起請求。注意請求方法名與請求物件是對應的
// 返回的resp是一個DescribeInstancesResponse類的例項,與請求物件對應
$resp = $sms->DescribeSmsSignList($req);
list($DescribeSignListStatusSet, $RequestId) = array_values(json_decode($resp->toJsonString(), true));
if (count($DescribeSignListStatusSet) >= 1) {
return response()->json([
'key' => $RequestId,
'code' => 0,
'message' => 'Ok',
'signs' => $DescribeSignListStatusSet
]);
}
} catch (TencentCloudSDKException $e) {
return response()->json([
'key' => $e->getRequestId(),
'code' => $e->getErrorCode(),
'message' => $e->getMessage()
])->setStatusCode(500);
}
}
}
新增路由
/* routes/api.php */
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::prefix('v1')->namespace('Api')->name('api.v1.')->group(function () {
// 傳送簡訊
Route::post('sendsms', 'SmsController@send')
->name('sms.send');
// 新增簡訊簽名
Route::post('smsSign', 'SmsSignController@addSign')
->name('sms.sign.add');
// 修改簡訊簽名
Route::put('smsSign', 'SmsSignController@modifySign')
->name('sms.sign.modify');
// 刪除簡訊簽名
Route::delete('smsSign', 'SmsSignController@deleteSign')
->name('sms.sign.delete');
// 簡訊簽名狀態查詢
Route::get('smsSign', 'SmsSignController@describeSigns')
->name('sms.sign.describe');
});
測試
通過 PostMan 測試一下:
本作品採用《CC 協議》,轉載必須註明作者和本文連結