TransferGateway.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Yansongda\Pay\Exceptions\GatewayException;
  4. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  5. class TransferGateway extends Wechat
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $gateway_transfer = 'mmpaymkttransfers/promotion/transfers';
  11. /**
  12. * get trade type config.
  13. *
  14. * @author yansongda <me@yansongda.cn>
  15. *
  16. * @return string
  17. */
  18. protected function getTradeType()
  19. {
  20. return '';
  21. }
  22. /**
  23. * pay a order.
  24. *
  25. * @author yansongda <me@yansongda.cn>
  26. *
  27. * @param array $config_biz
  28. *
  29. * @return array
  30. */
  31. public function pay(array $config_biz = [])
  32. {
  33. if (is_null($this->user_config->get('app_id'))) {
  34. throw new InvalidArgumentException('Missing Config -- [app_id]');
  35. }
  36. $config_biz['mch_appid'] = $this->config['appid'];
  37. $config_biz['mchid'] = $this->config['mch_id'];
  38. unset($this->config['appid']);
  39. unset($this->config['mch_id']);
  40. unset($this->config['sign_type']);
  41. unset($this->config['trade_type']);
  42. unset($this->config['notify_url']);
  43. $this->config = array_merge($this->config, $config_biz);
  44. $this->config['sign'] = $this->getSign($this->config);
  45. $data = $this->fromXml($this->post(
  46. $this->endpoint.$this->gateway_transfer,
  47. $this->toXml($this->config),
  48. [
  49. 'cert' => $this->user_config->get('cert_client', ''),
  50. 'ssl_key' => $this->user_config->get('cert_key', ''),
  51. ]
  52. ));
  53. if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
  54. $error = 'getResult error:'.$data['return_msg'];
  55. $error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
  56. }
  57. if (isset($error)) {
  58. throw new GatewayException(
  59. $error,
  60. 20000,
  61. $data);
  62. }
  63. return $data;
  64. }
  65. }