对微信服务商的支付

This commit is contained in:
kriss 2018-02-26 15:55:08 +08:00
parent 7b3773532d
commit 4d1db92198
7 changed files with 33 additions and 3 deletions

View File

@ -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(),

View File

@ -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);
}
/**

View File

@ -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']);

View File

@ -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);
}

View File

@ -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']);

View File

@ -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;

View File

@ -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, '');