v2board/library/TomatoPay.php

64 lines
1.7 KiB
PHP
Raw Normal View History

2020-01-05 15:35:12 +08:00
<?php
2020-01-11 13:36:52 +08:00
2020-01-05 15:35:12 +08:00
namespace Library;
2020-01-11 13:36:52 +08:00
class TomatoPay
{
2020-01-05 15:35:12 +08:00
private $mchid;
private $account;
private $key;
2020-01-11 13:36:52 +08:00
public function __construct($mchid, $account, $key)
{
2020-01-05 15:35:12 +08:00
$this->mchid = $mchid;
$this->account = $account;
$this->key = $key;
}
2020-01-11 13:36:52 +08:00
public function alipay($cny, $trade)
{
2020-01-05 15:35:12 +08:00
$params = [
'mchid' => $this->mchid,
'account' => $this->account,
'cny' => $cny,
2020-01-05 16:48:18 +08:00
'type' => '1',
2020-01-05 15:35:12 +08:00
'trade' => $trade
];
2020-01-05 16:48:18 +08:00
$params['signs'] = $this->sign($params);
2020-01-05 15:48:51 +08:00
return $this->buildHtml('https://b.fanqieui.com/gateways/alipay.php', $params);
2020-01-05 15:35:12 +08:00
}
2020-01-11 13:36:52 +08:00
public function wxpay($cny, $trade)
{
2020-01-05 16:48:18 +08:00
$params = [
'mchid' => $this->mchid,
'account' => $this->account,
'cny' => $cny,
'type' => '1',
'trade' => $trade
];
$params['signs'] = $this->sign($params);
return $this->buildHtml('https://b.fanqieui.com/gateways/wxpay.php', $params);
2020-01-05 15:35:12 +08:00
}
2020-01-11 13:36:52 +08:00
public function sign($params)
{
$o = '';
foreach ($params as $k => $v) {
$o .= "$k=" . ($v) . "&";
2020-01-05 16:48:18 +08:00
}
2020-01-11 13:36:52 +08:00
return md5(substr($o, 0, -1) . $this->key);
2020-01-05 16:48:18 +08:00
}
2020-01-05 15:48:51 +08:00
2020-01-11 13:36:52 +08:00
public function buildHtml($url, $params, $method = 'post', $target = '_self')
{
// return var_dump($params);
$html = "<form id='submit' name='submit' action='" . $url . "' method='$method' target='$target'>";
foreach ($params as $key => $value) {
$html .= "<input type='hidden' name='$key' value='$value'/>";
}
$html .= "</form><script>document.forms['submit'].submit();</script>";
return $html;
2020-01-05 15:35:12 +08:00
}
2020-01-11 13:36:52 +08:00
}