WebGateway.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
class WebGateway extends Wechat
{
/**
* get trade type config.
*
* @author yansongda <me@yansongda.cn>
*
* @return string
*/
protected function getTradeType()
{
return 'NATIVE';
}
/**
* pay a order.
*
* @author yansongda <me@yansongda.cn>
*
* @param array $config_biz
*
* @return string
*/
public function pay(array $config_biz = [])
{
if (is_null($this->user_config->get('app_id'))) {
throw new InvalidArgumentException('Missing Config -- [app_id]');
}
$code_url = $this->preOrder($config_biz)['code_url'];
$params = [
'body' => $config_biz['body'],
'code_url' => $code_url,
'out_trade_no' => $config_biz['out_trade_no'],
'return_url' => $this->user_config->get('return_url'),
'total_fee' => $config_biz['total_fee'],
];
$params['sign'] = md5(implode('', $params) . $this->user_config->get('app_id'));
$endpoint = addon_url("epay/api/wechat");
return $this->buildPayHtml($endpoint, $params);
}
/**
* build pay html.
*
* @author yansongda <me@yansongda.cn>
*
* @return string
*/
protected function buildPayHtml($endpoint, $params)
{
$sHtml = "<form id='alipaysubmit' name='wechatsubmit' action='" . $endpoint . "' method='POST'>";
foreach ($params as $key => $val) {
$val = str_replace("'", ''', $val);
$sHtml .= "<input type='hidden' name='" . $key . "' value='" . $val . "'/>";
}
$sHtml .= "<input type='submit' value='ok' style='display:none;'></form>";
$sHtml .= "<script>document.forms['wechatsubmit'].submit();</script>";
return $sHtml;
}
}