<?php

/**
 * Description of SendData
 * 最初用php编写的快速版本,后通过C#编写了工具软件.
 * @version
 *          1.0.0 Created at 2016-5-13. by --gwang
 * @author gwang (mail@wanggangzero.cn)
 * @copyright © 2016-5-13, SJZ LoyalSoft Corporation & gwang. All rights reserved.
 */
include_once __DIR__ . '/../Amfphp/main.php';
require_once 'OpenSSLVerify.php'; #Ps. 这个文件和类名没有对应关系.
/**
 * SendData
 * 通过本地向服务器刷入Cmem的key-value数据. key和value通过gzcompress和base64处理.
 * @author gwang email:wanggangzero@qq.com
 * @copyright © 2015-12-1, SJZ LoyalSoft Corporation & gwang. All rights reserved.
 */

class SendData
{

    /**
     * 发送数据
     * @param type $url
     */
    static function Send($zoneid, $url, $key, $value, $type = 'normal')
    {
        DebugHelper::var_dump($url);
        if (!is_string($value)) {
            $value = JsonUtil::encode($value);
        }
        $k = CommUtil::zb64encode($key);
        $v = CommUtil::zb64encode($value);
        $params = array(
            'zoneid' => $zoneid,
            'key' => $k,
            'val' => $v,
            'type' => $type);

        $keypath = ROOTDIR . "/Util/key";
        // 验证并查找回归密码记录
        $myrsa = new MyRsa($keypath);
        $sign = $myrsa->sign_arr($params);
        unset($myrsa);
        $params['sign'] = $sign; // 添加签名
//        var_dump($params);
        $ret = HttpUtil::makeRequest($url, $params, array());
        DebugHelper::var_dump($ret);
        if ($ret['result']) {
            echo 'ok';
            return true;
        } else {
            echo $ret['msg'];
            return false;
        }
    }

}
