Skip to content

Instantly share code, notes, and snippets.

@bogordesaincom
Created September 5, 2022 14:25
Show Gist options
  • Select an option

  • Save bogordesaincom/ccb33624a18c2d5ac831f25a4948c921 to your computer and use it in GitHub Desktop.

Select an option

Save bogordesaincom/ccb33624a18c2d5ac831f25a4948c921 to your computer and use it in GitHub Desktop.
Response Error Timestamps
<?php
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class NewsSampleController extends Controller
{
public function index()
{
$now = Carbon::now()->timestamp;
$milliseconds = now()->getPreciseTimestamp(3);
$appID = 'eoC32W37zaWOnAg3S3hmrTy3VX3pZG2g';
$appKey = '33h78jqcZR17JbnCoPZD9HoiVPxDNF6T1TZprAoPFeFRbWPTq2otqEaTfhfFj2st';
$sessionKey = 's878KLmofNBCdshFZcKwVptWBvjQQEaS5dFI5hlRyeJnIyfPQ2oEc0GiLAFs2H1V';
$sign = 'appId='.$appID.'&appKey='.$appKey.'&sessionKey='.$sessionKey.'&timestamp='.$now;
$cryp = sha1($sign);
$response = Http::acceptJson()->post('http://api.xinhua-news.com/newapi/getnewsbyproduct', [
'appId' => $appID,
'appKey' => $appKey,
'sessionKey' => $sessionKey,
'timestamp' => $now,
'sign' => $cryp,
'productCategoryId' => ['c0030002'],
'pageSize' => 10
// 'newsCategoryId' => ['c0270001','c0270864']
]);
if ($response->serverError()) {
dd('Error');
} else if ($response->failed()) {
dd('Failed');
} else if ($response->clientError()) {
dd('Client Error');
} else if($response->successful()) {
dd($response->json());
// Response Like This
//array:2 [▼
// "ErroCode" => "106"
// "status" => "erro"
// ]
}
}
}
@bogordesaincom

Copy link
Copy Markdown
Author

ok i will try again. i just folllow your instruction in documentation in word file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment