123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace crmeb\services\easywechat\miniPayment;
- use EasyWeChat\Core\AbstractAPI;
- use EasyWeChat\Core\AccessToken;
- use EasyWeChat\Kernel\Support;
- use EasyWeChat\Kernel\Support\Collection;
- use EasyWeChat\Kernel\Traits\HasHttpRequests;
- use EasyWeChat\Payment\Application;
- use EasyWeChat\Payment\Kernel\BaseClient;
- use EasyWeChat\Payment\Merchant;
- class WeChatClient extends AbstractAPI
- {
- private $expire_time = 7000;
-
- const API_SET_CREATE_ORDER = 'https://api.weixin.qq.com/shop/pay/createorder';
-
- const API_SET_REFUND_ORDER = 'https://api.weixin.qq.com/shop/pay/refundorder';
-
- protected $merchant;
-
- public function __construct(AccessToken $accessToken, Merchant $merchant)
- {
- parent::__construct($accessToken);
- $this->merchant = $merchant;
- }
-
- public function createorder($order)
- {
- $params = [
- 'openid' => $order['openid'],
- 'combine_trade_no' => $order['out_trade_no'],
- 'expire_time' => time() + $this->expire_time,
- 'sub_orders' => [
- [
- 'mchid' => $this->merchant->merchant_id,
- 'amount' => (int)$order['total_fee'],
- 'trade_no' => $order['out_trade_no'],
- 'description' => $order['body']
- ]
- ]
- ];
- return $this->parseJSON('post', [self::API_SET_CREATE_ORDER, json_encode($params)]);
- }
-
- public function refundorder(array $order)
- {
- $params = [
- 'openid' => $order['openid'],
- 'mchid' => $this->merchant->merchant_id,
- 'trade_no' => $order['trade_no'],
- 'transaction_id' => $order['transaction_id'],
- 'refund_no' => $order['refund_no'],
- 'total_amount' => $order['total_amount'],
- 'refund_amount' => $order['refund_amount'],
- ];
- return $this->parseJSON('post', [self::API_SET_REFUND_ORDER, json_encode($params)]);
- }
- }
|