Created
September 5, 2022 14:25
-
-
Save bogordesaincom/ccb33624a18c2d5ac831f25a4948c921 to your computer and use it in GitHub Desktop.
Response Error Timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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.'×tamp='.$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" | |
| // ] | |
| } | |
| } | |
| } |
Author
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”.
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

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