This website uses cookies to ensure you get the best experience. ❤️
OK
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
Prizm API
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency

PRIZM API

Prizm支付系统集成
Prizm Space Cryptocurrency
Prizm Space Cryptocurrency
讲解
Prizm支付系统集成
PRIZM支付系统是接收和发送加密支付的最简单方法。
  • 描述
  • PHP實現示例
  • 基本工作原理
  • 功能實例
要开始使用PRIZM,您将需要启动网络节点(Node)和API_Servlet。
网络节点

PrizmCore wallet
Easy API Gateway

该软件可以在一台服务器上运行,也可以在多台服务器上运行。 但是,为方便起见,最好在一台服务器上启动它。

首先,您应该启动节点并等待其同步。 下一步是配置PrizmAPIServlet模块。


存档中有一个名为PrizmAPIServlet.properties的文件

  • 在里面 passphrase: NONE

而不是NONE,您应该编写将由您的项目使用的钱包的私钥。

  • 在里面 sendkey: NONE 线

而不是NONE,您应该输入密码(硬币发送功能将使用该密码,以防止未经授权的交易)。

填写完字段后,应该通过run-servlet.sh启动servlet

PHP实现示例

接收和发送硬币的工作描述,以及现成功能的示例和工作原理的描述。 Mysql数据库用于存储事务列表,下面是存储表的转储,以及与该表一起使用的代码示例(如果您使用QueryBuilder,就不会有问题)。

主要工作原理:

Cron任务 中有一个脚本,该脚本每2-5分钟向Servlet发出一次请求,以便它可以在商店的钱包中接收新交易。 收到交易清单后,您应该将它们保存到本地数据库中。如果数据库中没有任何操作,则应运行不带任何参数的命令。 但是,如果您希望接收新交易,则应发送上次拥有的交易编号作为参数。

函数示例:

<?php
function historyPZM($last_id = 0)
{
	if ($last_id) {
		$url = 'http://localhost:8888/history?fromid=' . $last_id;
	} else {
		$url = 'http://localhost:8888/history';
	}
	$page = '';
	$result = get_web_page($url);
	if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
		$error = $result['errmsg'];
	} else {
		$page = $result['content'];
	}
	$array_new = array();
	$xcmorewrite = explode("\n", str_replace("\r", '', $page));
	foreach ($xcmorewrite as $value) {
		if ($value) {
			$array_new[] = explode(";", $value);
		}
	}
	return $array_new;
}

?>

检索页面内容的功能:

<?php

function get_web_page($url)
{
	$uagent = "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.14";
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 恢复网页         
           curl_setopt($ch, CURLOPT_HEADER, 0); // 无法恢复标题   
           curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 跟随重定向 
           curl_setopt($ch, CURLOPT_ENCODING, ""); // 处理所有编码
          curl_setopt($ch, CURLOPT_USERAGENT, $uagent); // 用户代理
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); // 连接超时   
          curl_setopt($ch, CURLOPT_TIMEOUT, 20); // 答案超时 
          curl_setopt($ch, CURLOPT_MAXREDIRS, 2); // 在第十次重定向后停止

           $content = curl_exec($ch);
	$err = curl_errno($ch);
	$errmsg = curl_error($ch);
	$header = curl_getinfo($ch);
	curl_close($ch);

	$header['errno'] = $err;
	$header['errmsg'] = $errmsg;
	$header['content'] = $content;
	return $header;
}

?>

您可以通过控制台进行测试,例如:curl http://localhost8888/history

用于接收新事务和表结构的Cron任务处理程序脚本示例

CREATE TABLE `pzm_history` (
  `id` bigint(20) NOT NULL,
  `tarif_id` int(1) NOT NULL,
  `tr_id` varchar(255) NOT NULL,
  `tr_date` varchar(255) NOT NULL,
  `tr_timestamp` int(11) NOT NULL,
  `pzm` varchar(50) NOT NULL,
  `summa` decimal(16,2) NOT NULL,
  `mess` varchar(255) NOT NULL,
  `status` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


* *所有必要的ID键和ID的自动递增应添加到表格中

处理程序:

<?php

$nomer = getLastPrmHistory();
$historys = historyPZM($nomer);

foreach ($historys as $item) {
    if ($item['0'] != "No transactions!") {


// 此行使用INSERT IGNORE将数据添加到“ pzm_history”表中


PzmHistory::find()->insertIgnore([
            'tr_id' => $item['0'],
            'tr_date' => $item['1'],
            'tr_timestamp' => $item['2'],
            'pzm' => $item['3'],
            'summa' => $item['4'],
            'mess' => $item['5'],
            'status' => 0
        ]);
    }
}


function getLastPrmHistory()
{

// 此行搜索表中的最后一行以获取表中事务的最后一个ID

if (!empty($pzmHistory = PzmHistory::find()->orderBy('id', "DESC")->first())) {
		return $pzmHistory->tr_id;            
	};
	return 0;
}

?>


在此示例中,您将收到应保存到本地数据库的新事务的列表。


因此,您保留了钱包中所有交易的历史记录,将来您将使用关键数据在我们的本地数据库中搜索它们。


您的项目必须使用相同的Prizm钱包,这就是为什么将为所有客户提供相同的补充内部帐户和相同操作的哈希ID的原因。 确保告知客户,他必须严格按照付款注释中指示哈希标识符的条件进行交易。

因此,应该有另一个过程,如果付款注释具有客户的哈希标识符,则该过程将分析新的传入交易并将硬币存入内部帐户。 另外,您还需要为客户端创建一个单独的" I PAID"按钮,单击该按钮后可以为该用户搜索和记录新交易。

次要功能和硬币发送功能
获取钱包的公钥(仅适用于具有余额的激活钱包)。

<?php
	
	function destinationPZM($pzm)
    {
        $url = 'http://localhost:8888/publickey?destination=' . $pzm;
        $page = '';
        $result = get_web_page($url);
        if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
            $error = $result['errmsg'];
            return '';
        } else {
            $page = $result['content'];
            $haystack = "Public key absent";
            $haystack2 = "Send error!";
            $pos = strripos($page, $haystack);
            $pos2 = strripos($page, $haystack2);
            if ($pos === false AND $pos2 === false) {
                $xcmorewrite = explode(' ', $page);
                $page = trim($xcmorewrite[0]);
                return $page;
            } else {
                return '';
            }
        }
        return $page;
    }

?>

接收钱包的当前余额:

<?php

	function getBalancePZM($pzm)
    {
        $ip = '*******';  //  192.168.1.1:9976  带端口
		$url = 'http://'.$ip.'/prizm?requestType=getAccount&account=' . $pzm;
        $page = '';
        $result = get_web_page($url);
		//print_r($result); die;
        if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
            $error = $result['errmsg'];
            return '';
        } else {
            $page = $result['content'];
            $page = json_decode($page, true);
            if ( isset($page['balanceNQT']) ) {
              return $page['balanceNQT'] / 100;
            } else {
              return 0;
            }
        }
    }

?>

硬币发送的一些方法:

<?php

public function payPZM($summa, $pzm, $public_key, $text)
{
	$p2 = SENDKEY;   // 这是您在设置过程中指定的密码
	$return = false;
	$url = 'http://localhost:8888/send?sendkey=' . $p2 . '&amount=' . $summa . '&comment=' . urlencode($text) . '&destination=' . $pzm . '&publickey=' . $public_key;
	$page = '';
	$result = get_web_page($url);

	if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
		$error = $result['errmsg'];
	} else {
		$page = $result['content'];
	}

	if (preg_match('/^\+?\d+$/', $page)) {
		$return = true;
	} else {
		$return = false;
	}
	return $return;
}

?>