mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-02 12:17:38 +08:00
微信企业付款
This commit is contained in:
parent
55798ffd54
commit
c8d77d6396
93
src/Gateways/Wechat/TransferGateway.php
Normal file
93
src/Gateways/Wechat/TransferGateway.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Yansongda\Pay\Exceptions\InvalidArgumentException;
|
||||
|
||||
class TransferGateway extends Wechat
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $gateway = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
||||
|
||||
/**
|
||||
* get trade type config.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTradeType()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* pay a order.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
* @param array $config_biz
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pay(array $config_biz = [])
|
||||
{
|
||||
if (is_null($this->user_config->get('app_id'))) {
|
||||
throw new InvalidArgumentException('Missing Config -- [app_id]');
|
||||
}
|
||||
|
||||
$config_biz['mch_appid'] = $this->config['appid'];
|
||||
$config_biz['mchid'] = $this->config['mch_id'];
|
||||
|
||||
unset($this->config['appid']);
|
||||
unset($this->config['mch_id']);
|
||||
unset($this->config['sign_type']);
|
||||
unset($this->config['trade_type']);
|
||||
unset($this->config['notify_url']);
|
||||
|
||||
$this->config = array_merge($this->config, $config_biz);
|
||||
|
||||
return $this->getResult($this->gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* get api result.
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*
|
||||
* @param string $end_point
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getResult($end_point)
|
||||
{
|
||||
$this->config['sign'] = $this->getSign($this->config);
|
||||
|
||||
|
||||
$data = $this->fromXml($this->post(
|
||||
$end_point,
|
||||
$this->toXml($this->config),
|
||||
[
|
||||
'cert' => $this->user_config->get('cert_client', ''),
|
||||
'ssl_key' => $this->user_config->get('cert_key', ''),
|
||||
]
|
||||
));
|
||||
|
||||
|
||||
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
|
||||
$error = 'getResult error:'.$data['return_msg'];
|
||||
$error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
|
||||
}
|
||||
|
||||
if (isset($error)) {
|
||||
throw new GatewayException(
|
||||
$error,
|
||||
20000,
|
||||
$data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user