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"
// ]
}
}
}
@luciferangela

Copy link
Copy Markdown

Please try to replace $now with $milliseconds in $sign

@bogordesaincom

bogordesaincom commented Sep 7, 2022

Copy link
Copy Markdown
Author

when i change with microtime the error change to 107

Jepretan Layar 2022-09-08 pukul 06 03 42

@luciferangela

Copy link
Copy Markdown

this error is not about timestamp. Would you show me the parameters when you use the interface “getnewsbyproduct”?And you'd better use the interface "getordercid" first to get the ordered product id. Use this id to get articles by the interface “getnewsbyproduct”.

@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