mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-05 21:58:26 +08:00
对微信服务商的支付
This commit is contained in:
parent
7b3773532d
commit
4d1db92198
@ -4,6 +4,7 @@ namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
@ -23,10 +24,13 @@ class AppGateway extends Gateway
|
||||
{
|
||||
$payload['appid'] = $this->config->get('appid');
|
||||
$payload['trade_type'] = $this->getTradeType();
|
||||
if ($this->mode === Wechat::MODE_SERVICE) {
|
||||
$payload['sub_appid'] = $this->config->get('sub_appid');
|
||||
}
|
||||
|
||||
$payRequest = [
|
||||
'appid' => $payload['appid'],
|
||||
'partnerid' => $payload['mch_id'],
|
||||
'partnerid' => $this->mode === Wechat::MODE_SERVICE ? $payload['sub_mch_id'] : $payload['mch_id'],
|
||||
'prepayid' => $this->preOrder('pay/unifiedorder', $payload)->prepay_id,
|
||||
'timestamp' => strval(time()),
|
||||
'noncestr' => Str::random(),
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Yansongda\Pay\Contracts\GatewayInterface;
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Config;
|
||||
@ -16,6 +17,13 @@ abstract class Gateway implements GatewayInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Mode.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mode;
|
||||
|
||||
/**
|
||||
* Bootstrap.
|
||||
*
|
||||
@ -26,6 +34,7 @@ abstract class Gateway implements GatewayInterface
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->mode = $this->config->get('mode', Wechat::MODE_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
@ -20,6 +21,9 @@ class GroupRedpackGateway extends Gateway
|
||||
public function pay($endpoint, array $payload): Collection
|
||||
{
|
||||
$payload['wxappid'] = $payload['appid'];
|
||||
if ($this->mode === Wechat::MODE_SERVICE) {
|
||||
$payload['msgappid'] = $payload['appid'];
|
||||
}
|
||||
$payload['amt_type'] = 'ALL_RAND';
|
||||
|
||||
unset($payload['appid'], $payload['trade_type'], $payload['notify_url'], $payload['spbill_create_ip']);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class MiniappGateway extends MpGateway
|
||||
@ -19,6 +20,9 @@ class MiniappGateway extends MpGateway
|
||||
public function pay($endpoint, array $payload): Collection
|
||||
{
|
||||
$payload['appid'] = $this->config->get('miniapp_id');
|
||||
if ($this->mode === Wechat::MODE_SERVICE) {
|
||||
$payload['sub_appid'] = $this->config->get('sub_miniapp_id');
|
||||
}
|
||||
|
||||
return parent::pay($endpoint, $payload);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
@ -21,6 +22,9 @@ class RedpackGateway extends Gateway
|
||||
public function pay($endpoint, array $payload): Collection
|
||||
{
|
||||
$payload['wxappid'] = $payload['appid'];
|
||||
if ($this->mode === Wechat::MODE_SERVICE) {
|
||||
$payload['msgappid'] = $payload['appid'];
|
||||
}
|
||||
$payload['client_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
|
||||
|
||||
unset($payload['appid'], $payload['trade_type'], $payload['notify_url'], $payload['spbill_create_ip']);
|
||||
|
@ -5,6 +5,7 @@ namespace Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Exceptions\GatewayException;
|
||||
use Yansongda\Pay\Exceptions\InvalidArgumentException;
|
||||
use Yansongda\Pay\Exceptions\InvalidSignException;
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Traits\HasHttpRequest;
|
||||
@ -209,11 +210,11 @@ class Support
|
||||
public static function baseUri($mode = null): string
|
||||
{
|
||||
switch ($mode) {
|
||||
case 'dev':
|
||||
case Wechat::MODE_DEV:
|
||||
self::getInstance()->baseUri = 'https://api.mch.weixin.qq.com/sandboxnew/';
|
||||
break;
|
||||
|
||||
case 'hk':
|
||||
case Wechat::MODE_HK:
|
||||
self::getInstance()->baseUri = 'https://apihk.mch.weixin.qq.com/';
|
||||
break;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Yansongda\Pay\Gateways\Wechat;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Yansongda\Pay\Gateways\Wechat;
|
||||
use Yansongda\Pay\Log;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
@ -20,6 +21,9 @@ class TransferGateway extends Gateway
|
||||
*/
|
||||
public function pay($endpoint, array $payload): Collection
|
||||
{
|
||||
if ($this->mode === Wechat::MODE_SERVICE) {
|
||||
unset($payload['sub_mch_id'], $payload['sub_appid']);
|
||||
}
|
||||
$type = isset($payload['type']) ? ($payload['type'].($payload['type'] == 'app' ?: '_').'id') : 'app_id';
|
||||
|
||||
$payload['mch_appid'] = $this->config->get($type, '');
|
||||
|
Loading…
Reference in New Issue
Block a user