PHP code example of internal-services / service-sdk

1. Go to this page and download the library: Download internal-services/service-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/ */

    

internal-services / service-sdk example snippets


use Internal\ServiceSdk\DataMid\DataMidClient;
use Internal\ServiceSdk\DataMid\EventFactory;

$client = new DataMidClient([
    'base_url' => getenv('MID_GATEWAY'),
    'country_code' => getenv('COUNTRY_CODE'),
    'client_id' => getenv('MID_CLIENT_ID'),
    'secret' => getenv('MID_SECRET'),
    'timeout' => 10,
]);

$events = new EventFactory('NG');
$event = $events->applicationSubmitted(
    '42',
    '5001',
    '业务手机号',
    'ORDER-001',
    'PRODUCT-01',
    'Quick Loan'
);

$response = $client->reportEvent($event->payload());

use Internal\ServiceSdk\Auth\InternalRequestContext;
use Internal\ServiceSdk\Http\GuzzleHttpTransport;
use Internal\ServiceSdk\Http\QueryString;
use Internal\ServiceSdk\Http\SignedHttpClient;

$client = new SignedHttpClient([
    'base_url' => getenv('DATA_MID_BASE_URL'),
    'client_id' => getenv('DATA_MID_CLIENT_ID'),
    'secret' => getenv('DATA_MID_CLIENT_SECRET'),
    'timeout' => 10,
], new GuzzleHttpTransport());

$context = new InternalRequestContext(
    'operator-id',
    '[email protected]',
    'mid.rules.read,mid.rules.edit',
    'request-id'
);
$path = QueryString::append('/admin/v1/rules', ['country_code' => 'NG']);
$response = $client->request('GET', $path, '', $context);

use Internal\ServiceSdk\Notification\DeviceRegistration;
use Internal\ServiceSdk\Notification\NotificationDeviceClient;

$client = new NotificationDeviceClient([
    'base_url' => getenv('NOTIFICATION_SERVICE_URL'),
    'client_id' => getenv('NOTIFICATION_SERVICE_CLIENT_ID'),
    'secret' => getenv('NOTIFICATION_SERVICE_SECRET'),
    'timeout' => 5,
]);

$client->registerDevice(new DeviceRegistration(
    'install-uuid',
    'NG',
    '5001',
    DeviceRegistration::PLATFORM_ANDROID,
    '当前 Token(至少 20 字节)',
    '2026-07-24T12:00:00.000000+01:00',
    '可选 GAID'
));

use Internal\ServiceSdk\Toolbox\AlertCatalog;
use Internal\ServiceSdk\Toolbox\FeishuAlertClient;
use Internal\ServiceSdk\Toolbox\FeishuNotifier;

$client = new FeishuAlertClient([
    'base_url' => getenv('FEISHU_BASE_URL'),
    'app_name' => 'country-loan-api',
    'environment' => getenv('APP_ENV'),
    'timeout' => 10,
]);

$notifier = new FeishuNotifier($client, new AlertCatalog([
    'SYSTEM_ERROR' => [
        'id' => 'COUNTRY-SYSTEM-ERROR',
        'description' => '系统错误',
    ],
]));
$notifier->notify('SYSTEM_ERROR', [
    'message' => ['error' => 'example'],
], 1);