<?php


namespace App\Services\wallet;

use App\Exception\custom\CodeSpecialException;
use Helpers\Sdk;


class WalletService
{

    /**
     * @param $params
     * @return bool|mixed
     * @throws CodeSpecialException
     * 钱包记录同步
     */
    public static function send($params) {

        $url = config('interface', 'wallet.account.transfer');
        if (!$url) {
            throw new CodeSpecialException("failed");
        }

        // 服务增加签名
        $appid = \Yaf\Application::app()->getConfig()->get('wallet.appid');
        $secret = \Yaf\Application::app()->getConfig()->get('wallet.secret');

        $params['time'] = date('Y-m-d H:i:s');
        $params['transfer_service_id'] = $appid;
        $params['sign'] = self::sign($params, $secret);

        return Sdk::call($url, $params);
    }

    private function sign($params, $secret) {
        $sign = md5($params['time'] . $secret);
        return $sign;
    }
}