PHP code example of davidcao626 / suning-sdk

1. Go to this page and download the library: Download davidcao626/suning-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

davidcao626 / suning-sdk example snippets


use DavidCao626\SuningSdk\Request\Govbus\CategoryGetRequest;
use DavidCao626\SuningSdk\DefaultSuningClient;

$req = new CategoryGetRequest();
$req->setCheckParam('true');
$assertArray = [
    'serverUrl' => 'http://openpre.cnsuning.com/api/http/sopRequest',
    'appKey' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
    'appSecret' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
    'format' => 'json'
];
$client = new DefaultSuningClient($assertArray['serverUrl'], $assertArray['appKey'],
    $assertArray['appSecret'], $assertArray['format']);

$resp = $client->execute($req);
$reqJson = $req->getReqJson();
print_r("请求报文:\n" . $reqJson);
print_r("\n返回响应报文:\n" . $resp);


 'providers' => [
        ...
        DavidCao626\SuningSdk\ServiceProvider::class
    ],

'suningSdk' => [
    'appKey' => env('SUNING_SDK_APPKEY'),
    'appSecret' => env('SUNING_SDK_APPSECRET'),
    'serverUrl' => env('SUNING_SDK_SERVERURL'),
    'format' => env('SUNING_SDK_FORMAT'),
],

SUNING_SDK_APPKEY= 你的appkey
SUNING_SDK_APPSECRET= 你的appSecret
SUNING_SDK_SERVERURL=http://openpre.cnsuning.com/api/http/sopRequest
SUNING_SDK_FORMAT=json



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DavidCao626\SuningSdk\Request\Govbus\CategoryGetRequest;
use DavidCao626\SuningSdk\DefaultSuningClient;

class CategoryGet extends Controller
{
    public function show(Request $request)
    {

        $req = new CategoryGetRequest();

        $req->setCheckParam('true');
        $resp =app('suningSdk')->execute($req);
        $reqJson = $req->getReqJson();
        print_r("请求报文:\n" . $reqJson);
        print_r("\n返回响应报文:\n" . $resp);
        $request->json($resp);
    }
}

    public function show(DefaultSuningClient $defaultSuningClient) 
    {
        ...
        $response = $defaultSuningClient->execute('$req');
    }

    public function show() 
    {
        ...
        $response =app('suningSdk')->execute($req);
    }