Skip to content

Commit

Permalink
Merge pull request #55 from MengDianYun/master
Browse files Browse the repository at this point in the history
新增微信普通红包,裂变红包
  • Loading branch information
yansongda authored Dec 23, 2017
2 parents 256a5f2 + 7d11f1d commit a37ebfa
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 0 deletions.
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,101 @@ $config_biz = [
类型:array
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2)

### 13、微信 - 发放裂变红包

#### 最小配置参数
```php
<?php
$config = [
'wechat' => [
'app_id'=>'wxaxxxxxxxx',
'mch_id' => '1442222202',
'key' => 'ddddddddddddddd',
'cert_client' => 'D:\php\xxx\application\wxpay\cert\apiclient_cert.pem',
'cert_key' => 'D:\php\xxx\application\wxpay\cert\apiclient_key.pem',
],
];

$config_biz = [
'wxappid'=>'wxaxxxxxxxx',
'mch_billno' => 'hb'.time(),
'send_name'=>'萌点云科技',//商户名称
're_openid'=>'ogg5JwsssssssssssCdXeD_S54',//用户openid
'total_amount' =>333, // 付款金额,单位分
'wishing'=>'提前祝你狗年大吉',//红包祝福语
'client_ip'=>'192.168.0.1',//调用接口的机器Ip地址
'total_num'=>'3',//红包发放总人数
'act_name'=>'提前拜年',//活动名称
'remark'=>'提前祝你狗年大吉,苟富贵勿相忘!', //备注
'amt_type'=>'ALL_RAND',//ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额
];

$pay = new Pay($config);
try
{
$res= $pay->driver('wechat')->gateway('groupredpack')->pay($config_biz);

}catch (Exception $e){

}

```

#### 所有配置参数
具体请看 [官方文档](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4)

#### 返回值
- pay()
类型:array
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4)


### 14、微信 - 发放普通红包

#### 最小配置参数
```php
<?php
$config = [
'wechat' => [
'app_id'=>'wxaxxxxxxxx',
'mch_id' => '1442222202',
'key' => 'ddddddddddddddd',
'cert_client' => 'D:\php\xxx\application\wxpay\cert\apiclient_cert.pem',
'cert_key' => 'D:\php\xxx\application\wxpay\cert\apiclient_key.pem',
],
];

$config_biz = [
'wxappid'=>'wxaxxxxxxxx',
'mch_billno' => 'hb'.time(),
'send_name'=>'萌点云科技',//商户名称
're_openid'=>'ogg5JwsssssssssssCdXeD_S54',//用户openid
'total_amount' =>100, // 付款金额,单位分
'wishing'=>'提前祝你狗年大吉',//红包祝福语
'client_ip'=>'192.168.0.1',//调用接口的机器Ip地址
'total_num'=>'1',//红包发放总人数
'act_name'=>'提前拜年',//活动名称
'remark'=>'提前祝你狗年大吉,苟富贵勿相忘!', //备注
];

$pay = new Pay($config);
try
{
$res= $pay->driver('wechat')->gateway('redpack')->pay($config_biz);

}catch (Exception $e){

}

```

#### 所有配置参数
具体请看 [官方文档](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3)

#### 返回值
- pay()
类型:array
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3)
## 代码贡献
由于测试及使用环境的限制,本项目中只开发了「支付宝」和「微信支付」的相关支付网关。

Expand Down
82 changes: 82 additions & 0 deletions src/Gateways/Wechat/GroupredpackGateway.php
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 '';
}
}
86 changes: 86 additions & 0 deletions src/Gateways/Wechat/RedpackGateway.php
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 '';
}
}

0 comments on commit a37ebfa

Please sign in to comment.