GroupredpackGateway.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * 发放裂变红包
  4. * Class GroupredpackGateway
  5. * Date: 2017/12/21
  6. * Time: 19:23
  7. * Com:萌点云科技(深圳)有限公司.
  8. *
  9. * Author:陈老司机
  10. *
  11. * Email:690712575@qq.com
  12. */
  13. namespace Yansongda\Pay\Gateways\Wechat;
  14. use Yansongda\Pay\Exceptions\GatewayException;
  15. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  16. class GroupredpackGateway extends Wechat
  17. {
  18. /**
  19. * @var string
  20. */
  21. protected $gateway_transfer = 'mmpaymkttransfers/sendgroupredpack';
  22. /**
  23. * pay a order.
  24. *
  25. * @author yansongda <me@yansongda.cn>
  26. *
  27. * @param array $config_biz
  28. *
  29. * @return mixed
  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. unset($this->config['sign_type']);
  37. unset($this->config['trade_type']);
  38. unset($this->config['notify_url']);
  39. unset($this->config['app_id']);
  40. unset($this->config['appid']);
  41. $this->config = array_merge($this->config, $config_biz);
  42. $this->config['sign'] = $this->getSign($this->config);
  43. $data = $this->fromXml($this->post(
  44. $this->endpoint.$this->gateway_transfer,
  45. $this->toXml($this->config),
  46. [
  47. 'cert' => $this->user_config->get('cert_client', ''),
  48. 'ssl_key' => $this->user_config->get('cert_key', ''),
  49. ]
  50. ));
  51. if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
  52. $error = 'getResult error:'.$data['return_msg'];
  53. $error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
  54. }
  55. if (isset($error)) {
  56. throw new GatewayException(
  57. $error,
  58. 20000,
  59. $data);
  60. }
  61. return $data;
  62. }
  63. /**
  64. * get trade type config.
  65. *
  66. * @author yansongda <me@yansongda.cn>
  67. *
  68. * @return string
  69. */
  70. protected function getTradeType()
  71. {
  72. return '';
  73. }
  74. }