WeChatClient.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace crmeb\services\wechat\MiniPayment\Payment;
  3. use EasyWeChat\Kernel\BaseClient;
  4. class WeChatClient extends BaseClient
  5. {
  6. private $expire_time = 7000;
  7. /**
  8. * 创建订单 支付
  9. */
  10. const API_SET_CREATE_ORDER = 'shop/pay/createorder';
  11. /**
  12. * 退款
  13. */
  14. const API_SET_REFUND_ORDER = 'shop/pay/refundorder';
  15. /**
  16. * 支付
  17. * @param array $params[
  18. * 'openid'=>'支付者的openid',
  19. * 'out_trade_no'=>'商家合单支付总交易单号',
  20. * 'total_fee'=>'支付金额',
  21. * 'wx_out_trade_no'=>'商家交易单号',
  22. * 'body'=>'商品描述',
  23. * 'attach'=>'支付类型', //product 产品 member 会员
  24. * ]
  25. * @param $isContract
  26. * @return mixed
  27. * @throws \GuzzleHttp\Exception\GuzzleException
  28. */
  29. public function createorder(array $params)
  30. {
  31. $data = [
  32. 'openid'=>$params['openid'], // 支付者的openid
  33. 'combine_trade_no'=>$params['out_trade_no'], // 商家合单支付总交易单号
  34. 'expire_time'=>time()+$this->expire_time,
  35. 'sub_orders'=>[
  36. [
  37. 'mchid'=>$this->app['config']['mch_id'],
  38. 'amount'=>(int)$params['total_fee'],
  39. 'trade_no'=>$params['out_trade_no'],
  40. 'description'=>$params['body'],
  41. ]
  42. ],
  43. ];
  44. return $this->httpPostJson(self::API_SET_CREATE_ORDER, $data);
  45. }
  46. /**
  47. * 退款
  48. * @param array $params[
  49. * 'openid'=>'退款者的openid',
  50. * 'trade_no'=>'商家交易单号',
  51. * 'transaction_id'=>'支付单号',
  52. * 'refund_no'=>'商家退款单号',
  53. * 'total_amount'=>'订单总金额',
  54. * 'refund_amount'=>'退款金额', //product 产品 member 会员
  55. * ]
  56. * @return mixed
  57. * @throws \GuzzleHttp\Exception\GuzzleException
  58. */
  59. public function refundorder(array $params)
  60. {
  61. $data = [
  62. 'openid'=>$params['openid'],
  63. 'mchid'=>$this->app['config']['mch_id'],
  64. 'trade_no'=>$params['trade_no'],
  65. 'transaction_id'=>$params['transaction_id'],
  66. 'refund_no'=>$params['refund_no'],
  67. 'total_amount'=>(int)$params['total_amount'],
  68. 'refund_amount'=>(int)$params['refund_amount'],
  69. ];
  70. return $this->httpPostJson(self::API_SET_REFUND_ORDER, $data);
  71. }
  72. }