PHP code example of siam / spm-sdk

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

    

siam / spm-sdk example snippets


use spm\Config;
use spm\Reporter;

$config = new Config();
$config->setUrl("http://www.spm.com/public/index.php");
$config->setProjectId(1); // 项目id

Reporter::instance($config);

use spm\utility\Timer;

Timer::start();

public function response($code, $data, $msg, $apiReport = [])

use spm\exception\Exception;
use spm\exception\TimerException;
use spm\utility\Timer;
use spm\bean\ApiDataBean;
use spm\Reporter;

$param = [
    'key1' => 'value1',
    'key2' => 'value2',
];

try{
    $apiLog = new ApiDataBean();
    $apiLog->setCategory("Wechat"); // 接口名 - 分类
    $apiLog->setMethod("jspay");  // 接口名 - 方法
    $apiLog->setUserFrom("Siam"); // 调用api的客户来源标识
    $apiLog->setUserIdentify(time().rand(1000,9999)); // 标识,比如订单号 用于后台追溯查看
    $apiLog->setApiResponse(json_encode($param)); // 响应给客户端的内容 比如json字符串 xml字符串等
    $apiLog->setConsumeTime(Timer::end());
    $apiLog->setApiParam($param);
    $apiLog->setIsSuccess(ApiDataBean::SUCCESS); // 可选ApiDataBean::FAIL
} catch (Exception $e) {
    return $e->getMessage();
} catch (TimerException $e) {
    return $e->getMessage();
}

Reporter::instance()->report($apiLog);


use spm\bean\ExceptionDataBean;
use spm\Reporter;

$bean = new ExceptionDataBean();
$bean->setAbClass('\Siam\test\Class');
$bean->setAbData([
    'get' => [
        'field1' => 'value1'
    ]
]);
$bean->setAbDate(date('Y-m-d'));
$bean->setAbFile("错误的文件地址");
$bean->setAbFileresources([
    [//[{"is_hight":0, "text": "代码", "line" :100}, {"is_hight":1, "text": "代码2", "line" :101}]
        'is_hight' => 0, // 是否高亮
        'text'     => "内容",
        'line' => "行号"
    ]
]);
$bean->setAbLine(320);
$bean->setAbStack([
    ['第一行stack'],
    ['第二行stack'],
]);
$bean->setAbMessage("错误消息");
Reporter::instance()->exception_report($bean);

use spm\bean\LogDataBean;
use spm\Reporter;

$bean = new LogDataBean();
$bean->setLogCategory("Wechat/Test/SDK");
$bean->setLogData('{"key": "value"}');
$bean->setLogFrom("SDK");
$bean->setLogPoint("test guzzle");
$bean->setLogSn("123456");
Reporter::instance()->log($bean);

$config = new \spm\Config();
$config->setUrl("http://www.siam.com/public/index.php");
$config->setProjectId(1);
Reporter::instance($config);

$config->setLazyLog(true);

$bean = new LogDataBean();
$bean->setLogCategory("Wechat/Test_lazy/SDK");
$bean->setLogData('{"key": "value"}');
$bean->setLogFrom("SDK");
$bean->setLogPoint("test guzzle");
$bean->setLogSn("20191128");
Reporter::instance()->log($bean); // 此时不会真正发送 

$bean = new LogDataBean();
$bean->setLogCategory("Wechat/Test_lazy/SDK");
$bean->setLogData('22222');
$bean->setLogFrom("SDK");
$bean->setLogPoint("test guzzle");
$bean->setLogSn("20191128");
Reporter::instance()->log($bean);

Reporter::instance()->lazy_log_send(); // 懒上报