-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from MengDianYun/master
新增微信普通红包,裂变红包
- Loading branch information
Showing
3 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* 发放裂变红包 | ||
* Class GroupredpackGateway | ||
* Date: 2017/12/21 | ||
* Time: 19:23 | ||
* Com:萌点云科技(深圳)有限公司. | ||
* | ||
* Author:陈老司机 | ||
* | ||
* Email:[email protected] | ||
*/ | ||
|
||
namespace Yansongda\Pay\Gateways\Wechat; | ||
|
||
use Yansongda\Pay\Exceptions\GatewayException; | ||
use Yansongda\Pay\Exceptions\InvalidArgumentException; | ||
|
||
class GroupredpackGateway extends Wechat | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $gateway_transfer = 'mmpaymkttransfers/sendgroupredpack'; | ||
|
||
/** | ||
* pay a order. | ||
* | ||
* @author yansongda <[email protected]> | ||
* | ||
* @param array $config_biz | ||
* | ||
* @return mixed | ||
*/ | ||
public function pay(array $config_biz = []) | ||
{ | ||
if (is_null($this->user_config->get('app_id'))) { | ||
throw new InvalidArgumentException('Missing Config -- [app_id]'); | ||
} | ||
unset($this->config['sign_type']); | ||
unset($this->config['trade_type']); | ||
unset($this->config['notify_url']); | ||
unset($this->config['app_id']); | ||
unset($this->config['appid']); | ||
$this->config = array_merge($this->config, $config_biz); | ||
$this->config['sign'] = $this->getSign($this->config); | ||
$data = $this->fromXml($this->post( | ||
$this->endpoint.$this->gateway_transfer, | ||
$this->toXml($this->config), | ||
[ | ||
'cert' => $this->user_config->get('cert_client', ''), | ||
'ssl_key' => $this->user_config->get('cert_key', ''), | ||
] | ||
)); | ||
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') { | ||
$error = 'getResult error:'.$data['return_msg']; | ||
$error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : ''; | ||
} | ||
|
||
if (isset($error)) { | ||
throw new GatewayException( | ||
$error, | ||
20000, | ||
$data); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* get trade type config. | ||
* | ||
* @author yansongda <[email protected]> | ||
* | ||
* @return string | ||
*/ | ||
protected function getTradeType() | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* 发放普通红包 | ||
* Class RedPackGateway | ||
* Date: 2017/12/21 | ||
* Time: 19:23 | ||
* Com:萌点云科技(深圳)有限公司. | ||
* | ||
* Author:陈老司机 | ||
* | ||
* Email:[email protected] | ||
*/ | ||
|
||
namespace Yansongda\Pay\Gateways\Wechat; | ||
|
||
use Yansongda\Pay\Exceptions\GatewayException; | ||
use Yansongda\Pay\Exceptions\InvalidArgumentException; | ||
|
||
class RedpackGateway extends Wechat | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $gateway_transfer = 'mmpaymkttransfers/sendredpack'; | ||
|
||
/** | ||
* pay a order. | ||
* | ||
* @author yansongda <[email protected]> | ||
* | ||
* @param array $config_biz | ||
* | ||
* @return mixed | ||
*/ | ||
public function pay(array $config_biz = []) | ||
{ | ||
if (is_null($this->user_config->get('app_id'))) { | ||
throw new InvalidArgumentException('Missing Config -- [app_id]'); | ||
} | ||
unset($this->config['sign_type']); | ||
unset($this->config['trade_type']); | ||
unset($this->config['notify_url']); | ||
unset($this->config['app_id']); | ||
unset($this->config['appid']); | ||
|
||
$this->config = array_merge($this->config, $config_biz); | ||
|
||
$this->config['sign'] = $this->getSign($this->config); | ||
|
||
$data = $this->fromXml($this->post( | ||
$this->endpoint.$this->gateway_transfer, | ||
$this->toXml($this->config), | ||
[ | ||
'cert' => $this->user_config->get('cert_client', ''), | ||
'ssl_key' => $this->user_config->get('cert_key', ''), | ||
] | ||
)); | ||
|
||
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') { | ||
$error = 'getResult error:'.$data['return_msg']; | ||
$error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : ''; | ||
} | ||
|
||
if (isset($error)) { | ||
throw new GatewayException( | ||
$error, | ||
20000, | ||
$data); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* get trade type config. | ||
* | ||
* @author yansongda <[email protected]> | ||
* | ||
* @return string | ||
*/ | ||
protected function getTradeType() | ||
{ | ||
return ''; | ||
} | ||
} |