v2board/library/TomatoPay.php

41 lines
1.1 KiB
PHP
Raw Normal View History

2020-01-05 15:35:12 +08:00
<?php
namespace Library;
class TomatoPay {
private $mchid;
private $account;
private $key;
public function __construct($mchid, $account, $key) {
$this->mchid = $mchid;
$this->account = $account;
$this->key = $key;
}
2020-01-05 15:48:51 +08:00
public function alipay ($cny, $type, $trade) {
2020-01-05 15:35:12 +08:00
$params = [
'mchid' => $this->mchid,
'account' => $this->account,
'cny' => $cny,
'type' => $type,
'trade' => $trade
];
$params['signs'] = $this->sign(http_build_query($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
}
public function sign ($str) {
return md5($str.$this->key);
}
2020-01-05 15:48:51 +08:00
public function buildHtml($url, $params, $method = 'post', $target = '_self'){
2020-01-05 15:35:12 +08:00
// var_dump($params);exit;
2020-01-05 15:48:51 +08:00
$html = "<form id='submit' name='submit' action='".$url."' method='$method' target='$target'>";
2020-01-05 15:35:12 +08:00
foreach ($params as $key => $value) {
$html .= "<input type='hidden' name='$key' value='$value'/>";
}
$html .= "</form><script>document.forms['submit'].submit();</script>";
return $html;
}
}