PHP code example of wxbacy / yarsign

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

    

wxbacy / yarsign example snippets


// If you installed via composer, just use this code to requrie autoloader on the top of your projects.
' => [
        'service_address' => 'http://userservice.com/rpc/index',
        'secret' => '1532YADJas',
    ],
    'mall' => [
        'service_address' => 'http://mallservice.com/rpc/index',
        'secret' => '1532YADJas',
    ],
]);

// Server

// 以下写在控制器
$serviceStr = $_GET['service'];
$ts = $_GET['ts'];
$sign = $_GET['sign'];

// 解密
$service = Sign::serviceDecode($serviceStr);

// 身份认证
if (! Sign::checkSign($service['service'], $service['class'], $ts, $sign)) {
    return;
}

$server = new Yar_Server(new $service['class']());
$server->handle();

// Client
$userModel = Client::getInstance('user', 'UserModel');
$userModel->getUserByUserid(156562);

$userDetail = [];
Client::concurrentCall('user', 'UserModel', 'getUserByUserid', [156562], function($retval, $callinfo) use (&$userDetail){
    if ($callinfo == NULL) {
        return true;
    }
    $userDetail['username'] = $retval['username'];
    $userDetail['gender'] = $retval['gender'];
});
    
Client::concurrentCall('user', 'UserModel', 'getUserAccount', [156562], function($retval, $callinfo) use (&$userDetail){
    if ($callinfo == NULL) {
        return true;
    }
    $userDetail['balance_lyb'] = $retval['balance_lyb'];
    $userDetail['balance_mb'] = $retval['balance_mb'];
});
    
Yar_Concurrent_Client::loop();